Search in sources :

Example 11 with PathsWithVertices

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

the class CustomizedPathsApiTest method testCustomizedPathsWithDecr.

@Test
public void testCustomizedPathsWithDecr() {
    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.DECR).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, rippleId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, lopId);
    Assert.assertEquals(path1, paths.get(0).objects());
    Assert.assertEquals(path2, paths.get(1).objects());
    List<Double> weights1 = ImmutableList.of(1.0D, 1.0D);
    List<Double> weights2 = ImmutableList.of(1.0D, 0.4D);
    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 12 with PathsWithVertices

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

the class CustomizedPathsApiTest method testCustomizedPathsSourceIds.

@Test
public void testCustomizedPathsSourceIds() {
    Object markoId = getVertexId("person", "name", "marko");
    Object lopId = getVertexId("software", "name", "lop");
    Object peterId = getVertexId("person", "name", "peter");
    CustomizedPathsRequest.Builder builder = CustomizedPathsRequest.builder();
    builder.sources().ids(markoId, peterId);
    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)

Example 13 with PathsWithVertices

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

the class CustomizedPathsApiTest method testCustomizedPathsWithSample.

@Test
public void testCustomizedPathsWithSample() {
    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).sample(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, rippleId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, lopId);
    List<List<Object>> expectedPaths = ImmutableList.of(path1, path2);
    Assert.assertTrue(expectedPaths.contains(paths.get(0).objects()));
    List<Double> weights1 = ImmutableList.of(1D, 0.4D);
    List<Double> weights2 = ImmutableList.of(1D, 1D);
    Assert.assertTrue(weights1.equals(paths.get(0).weights()) || weights2.equals(paths.get(0).weights()));
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(path1.containsAll(vertices) || path2.containsAll(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)

Example 14 with PathsWithVertices

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

the class MultiNodeShortestPathApiTest method testMultiNodeShortestPath.

@Test
public void testMultiNodeShortestPath() {
    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);
    MultiNodeShortestPathRequest request = builder.build();
    PathsWithVertices pathsWithVertices = multiNodeShortestPathAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(15, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, joshId), ImmutableList.of(peterId, lopId), ImmutableList.of(peterId, lopId, markoId, vadasId), ImmutableList.of(peterId, lopId, joshId), ImmutableList.of(markoId, vadasId), ImmutableList.of(vadasId, markoId, lopId), ImmutableList.of(vadasId, markoId, joshId), ImmutableList.of(peterId, lopId, joshId, rippleId), 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), ImmutableList.of(vadasId, markoId, joshId, rippleId));
    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 15 with PathsWithVertices

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

the class MultiNodeShortestPathApiTest method testMultiNodeShortestPathWithVertex.

@Test
public void testMultiNodeShortestPathWithVertex() {
    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.withVertex(true);
    MultiNodeShortestPathRequest request = builder.build();
    PathsWithVertices pathsWithVertices = multiNodeShortestPathAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(15, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, joshId), ImmutableList.of(peterId, lopId), ImmutableList.of(peterId, lopId, markoId, vadasId), ImmutableList.of(peterId, lopId, joshId), ImmutableList.of(markoId, vadasId), ImmutableList.of(vadasId, markoId, lopId), ImmutableList.of(vadasId, markoId, joshId), ImmutableList.of(peterId, lopId, joshId, rippleId), 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), ImmutableList.of(vadasId, markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(contains(expected, path));
    }
    Set<Vertex> vertices = pathsWithVertices.vertices();
    Assert.assertEquals(6, vertices.size());
    Set<Object> vertexIds = ImmutableSet.of(markoId, rippleId, joshId, lopId, vadasId, peterId);
    for (Vertex vertex : vertices) {
        Assert.assertTrue(vertexIds.contains(vertex.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) MultiNodeShortestPathRequest(com.baidu.hugegraph.structure.traverser.MultiNodeShortestPathRequest) 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