Search in sources :

Example 6 with PathsWithVertices

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

the class TemplatePathsApiTest method testTemplatePathsWithRing.

@Test
public void testTemplatePathsWithRing() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    List<List<Object>> expected = ImmutableList.of(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("relateTo").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
    builder.withRing(true);
    request = builder.build();
    pathsWithVertices = templatePathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(4, paths.size());
    expected = ImmutableList.of(ImmutableList.of(1, 16, 17, 10), ImmutableList.of(1, 16, 17, 16, 17, 10), ImmutableList.of(1, 16, 17, 16, 17, 16, 17, 10), ImmutableList.of(1, 16, 17, 16, 17, 16, 17, 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 7 with PathsWithVertices

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

the class TemplatePathsApiTest method testTemplatePathsWithLabel.

@Test
public void testTemplatePathsWithLabel() {
    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("relateTo").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
    request = builder.build();
    pathsWithVertices = templatePathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    expected = ImmutableList.of(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 8 with PathsWithVertices

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

the class CustomizedPathsApiTest method testCustomizedPathsSourceLabelProperty.

@Test
public void testCustomizedPathsSourceLabelProperty() {
    Object markoId = getVertexId("person", "name", "marko");
    Object joshId = getVertexId("person", "name", "josh");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object lopId = getVertexId("software", "name", "lop");
    CustomizedPathsRequest.Builder builder = CustomizedPathsRequest.builder();
    builder.sources().label("person").property("name", "marko");
    builder.steps().direction(Direction.OUT).labels("knows1").weightBy("weight").degree(-1);
    builder.steps().direction(Direction.OUT).labels("created1").weightBy("weight").degree(-1);
    builder.sortBy(CustomizedPathsRequest.SortBy.INCR).withVertex(true).capacity(-1).limit(-1);
    CustomizedPathsRequest request = builder.build();
    PathsWithVertices customizedPaths = customizedPathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = customizedPaths.paths();
    Assert.assertEquals(2, paths.size());
    List<Object> path1 = ImmutableList.of(markoId, joshId, lopId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, rippleId);
    Assert.assertEquals(path1, paths.get(0).objects());
    Assert.assertEquals(path2, paths.get(1).objects());
    List<Double> weights1 = ImmutableList.of(1.0D, 0.4D);
    List<Double> weights2 = ImmutableList.of(1.0D, 1.0D);
    Assert.assertEquals(weights1, paths.get(0).weights());
    Assert.assertEquals(weights2, paths.get(1).weights());
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(4, vertices.size());
    Set<?> expectedVertices = ImmutableSet.of(markoId, lopId, rippleId, joshId);
    Assert.assertEquals(expectedVertices, vertices);
}
Also used : CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 9 with PathsWithVertices

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

the class CustomizedPathsApiTest method testCustomizedPathsWithLimit.

@Test
public void testCustomizedPathsWithLimit() {
    Object markoId = getVertexId("person", "name", "marko");
    Object joshId = getVertexId("person", "name", "josh");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object lopId = getVertexId("software", "name", "lop");
    CustomizedPathsRequest.Builder builder = CustomizedPathsRequest.builder();
    builder.sources().label("person").property("name", "marko");
    builder.steps().direction(Direction.OUT).labels("knows1").weightBy("weight").degree(-1);
    builder.steps().direction(Direction.OUT).labels("created1").weightBy("weight").degree(-1);
    builder.sortBy(CustomizedPathsRequest.SortBy.INCR).withVertex(true).capacity(-1).limit(1);
    CustomizedPathsRequest request = builder.build();
    PathsWithVertices customizedPaths = customizedPathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = customizedPaths.paths();
    Assert.assertEquals(1, paths.size());
    List<Object> path1 = ImmutableList.of(markoId, joshId, lopId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, rippleId);
    List<List<Object>> expectedPaths = ImmutableList.of(path1, path2);
    Assert.assertTrue(expectedPaths.contains(paths.get(0).objects()));
    List<Double> weights1 = ImmutableList.of(1.0D, 0.4D);
    List<Double> weights2 = ImmutableList.of(1.0D, 1.0D);
    List<List<Double>> expectedWeights = ImmutableList.of(weights1, weights2);
    Assert.assertTrue(expectedWeights.contains(paths.get(0).weights()));
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(3, vertices.size());
    Set<?> vertices1 = ImmutableSet.of(markoId, lopId, joshId);
    Set<?> vertices2 = ImmutableSet.of(markoId, lopId, rippleId);
    Set<Set<?>> expectedVertices = ImmutableSet.of(vertices1, vertices2);
    Assert.assertTrue(expectedVertices.contains(vertices));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 10 with PathsWithVertices

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

the class CustomizedPathsApiTest method testCustomizedPathsSourceLabelPropertyMultiValue.

@Test
public void testCustomizedPathsSourceLabelPropertyMultiValue() {
    Object markoId = getVertexId("person", "name", "marko");
    Object lopId = getVertexId("software", "name", "lop");
    Object peterId = getVertexId("person", "name", "peter");
    CustomizedPathsRequest.Builder builder = CustomizedPathsRequest.builder();
    List<String> names = ImmutableList.of("marko", "peter");
    builder.sources().label("person").property("name", names);
    builder.steps().direction(Direction.OUT).labels("created1").weightBy("weight").degree(-1);
    builder.sortBy(CustomizedPathsRequest.SortBy.INCR).withVertex(true).capacity(-1).limit(-1);
    CustomizedPathsRequest request = builder.build();
    PathsWithVertices customizedPaths = customizedPathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = customizedPaths.paths();
    Assert.assertEquals(2, paths.size());
    List<Object> path1 = ImmutableList.of(markoId, lopId);
    List<Object> path2 = ImmutableList.of(peterId, lopId);
    List<List<Object>> expectedPaths = ImmutableList.of(path1, path2);
    Assert.assertTrue(expectedPaths.contains(paths.get(0).objects()));
    Assert.assertTrue(expectedPaths.contains(paths.get(1).objects()));
    List<Double> weights1 = ImmutableList.of(0.2D);
    List<Double> weights2 = ImmutableList.of(0.4D);
    List<List<Double>> expectedWeights = ImmutableList.of(weights1, weights2);
    Assert.assertTrue(expectedWeights.contains(paths.get(0).weights()));
    Assert.assertTrue(expectedWeights.contains(paths.get(1).weights()));
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(3, vertices.size());
    Set<?> expectedVertices = ImmutableSet.of(markoId, lopId, peterId);
    Assert.assertEquals(expectedVertices, vertices);
}
Also used : CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) 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