use of com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest 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.CustomizedPathsRequest 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));
}
Aggregations