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);
}
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);
}
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));
}
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));
}
}
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()));
}
}
Aggregations