Search in sources :

Example 16 with PathsWithVertices

use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.

the class MultiNodeShortestPathApiTest method testMultiNodeShortestPathWithMaxDepth.

@Test
public void testMultiNodeShortestPathWithMaxDepth() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Object vadasId = getVertexId("person", "name", "vadas");
    Object peterId = getVertexId("person", "name", "peter");
    MultiNodeShortestPathRequest.Builder builder = MultiNodeShortestPathRequest.builder();
    builder.vertices().ids(markoId, rippleId, joshId, lopId, vadasId, peterId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    MultiNodeShortestPathRequest request = builder.build();
    PathsWithVertices pathsWithVertices = multiNodeShortestPathAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(12, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, joshId), ImmutableList.of(peterId, lopId), ImmutableList.of(peterId, lopId, joshId), ImmutableList.of(markoId, vadasId), ImmutableList.of(vadasId, markoId, lopId), ImmutableList.of(vadasId, markoId, joshId), ImmutableList.of(lopId, joshId, rippleId), ImmutableList.of(lopId, joshId), ImmutableList.of(rippleId, joshId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(contains(expected, path));
    }
    builder = MultiNodeShortestPathRequest.builder();
    builder.vertices().ids(markoId, rippleId, joshId, lopId, vadasId, peterId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    request = builder.build();
    pathsWithVertices = multiNodeShortestPathAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(6, paths.size());
    expected = ImmutableList.of(ImmutableList.of(markoId, joshId), ImmutableList.of(peterId, lopId), ImmutableList.of(markoId, vadasId), ImmutableList.of(lopId, joshId), ImmutableList.of(rippleId, joshId), ImmutableList.of(markoId, lopId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(contains(expected, path));
    }
}
Also used : PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) MultiNodeShortestPathRequest(com.baidu.hugegraph.structure.traverser.MultiNodeShortestPathRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 17 with PathsWithVertices

use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.

the class TemplatePathsApiTest method testTemplatePaths.

@Test
public void testTemplatePaths() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).maxTimes(3);
    builder.steps().direction(Direction.OUT).maxTimes(3);
    builder.steps().direction(Direction.IN).maxTimes(3);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(3, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ImmutableList.of(1, 11, 12, 13, 14, 15, 10), ImmutableList.of(1, 16, 17, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : TemplatePathsRequest(com.baidu.hugegraph.structure.traverser.TemplatePathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 18 with PathsWithVertices

use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.

the class TemplatePathsApiTest method testTemplatePathsWithLimit.

@Test
public void testTemplatePathsWithLimit() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("link").maxTimes(3);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(3, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ImmutableList.of(1, 11, 12, 13, 14, 15, 10), ImmutableList.of(1, 16, 17, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("link").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("link").maxTimes(3);
    builder.limit(2);
    request = builder.build();
    pathsWithVertices = templatePathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    expected = ImmutableList.of(ImmutableList.of(1, 16, 17, 10), ImmutableList.of(1, 11, 12, 13, 14, 15, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : TemplatePathsRequest(com.baidu.hugegraph.structure.traverser.TemplatePathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 19 with PathsWithVertices

use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.

the class PathsApiTest method testPathsPost.

@Test
public void testPathsPost() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    PathsRequest.Builder builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(3);
    PathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = pathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId), ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PathsRequest(com.baidu.hugegraph.structure.traverser.PathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 20 with PathsWithVertices

use of com.baidu.hugegraph.structure.traverser.PathsWithVertices in project incubator-hugegraph-toolchain by apache.

the class PathsApiTest method testPathsPostWithVertex.

@Test
public void testPathsPostWithVertex() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    PathsRequest.Builder builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(3);
    builder.withVertex(true);
    PathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = pathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    List<Object> expectedIds = ImmutableList.of(markoId, lopId, joshId, rippleId);
    List<List<Object>> expected = ImmutableList.of(expectedIds, ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    Set<Vertex> vertices = pathsWithVertices.vertices();
    Assert.assertEquals(4, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertTrue(expectedIds.contains(v.id()));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PathsRequest(com.baidu.hugegraph.structure.traverser.PathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)21 Test (org.junit.Test)21 ImmutableList (com.google.common.collect.ImmutableList)19 List (java.util.List)19 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)15 CustomizedPathsRequest (com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest)6 PathsRequest (com.baidu.hugegraph.structure.traverser.PathsRequest)6 TemplatePathsRequest (com.baidu.hugegraph.structure.traverser.TemplatePathsRequest)6 Vertex (com.baidu.hugegraph.structure.graph.Vertex)4 ArrayList (java.util.ArrayList)4 MultiNodeShortestPathRequest (com.baidu.hugegraph.structure.traverser.MultiNodeShortestPathRequest)3 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1