use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class CommonTraverserApiTest method testCrosspoints.
@Test
public void testCrosspoints() {
Object markoId = getVertexId("person", "name", "marko");
Object joshId = getVertexId("person", "name", "josh");
Object lopId = getVertexId("software", "name", "lop");
Object peterId = getVertexId("person", "name", "peter");
List<Path> paths = crosspointsAPI.get(markoId, peterId, Direction.OUT, null, 3, -1L, -1L, 10);
Assert.assertEquals(2, paths.size());
Path crosspoint1 = new Path(lopId, ImmutableList.of(markoId, lopId, peterId));
Path crosspoint2 = new Path(lopId, ImmutableList.of(markoId, joshId, lopId, peterId));
List<Path> crosspoints = ImmutableList.of(crosspoint1, crosspoint2);
Assert.assertTrue(crosspoints.contains(paths.get(0)));
Assert.assertTrue(crosspoints.contains(paths.get(1)));
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class KneighborApiTest method testKneighborPostWithPath.
@Test
public void testKneighborPostWithPath() {
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");
KneighborRequest.Builder builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(true);
KneighborRequest request = builder.build();
Kneighbor kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(3, kneighborResult.size());
Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(3, kneighborResult.paths().size());
List<Object> expectedPaths = ImmutableList.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
builder = KneighborRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(true);
request = builder.build();
kneighborResult = kneighborAPI.post(request);
Assert.assertEquals(5, kneighborResult.size());
expected = ImmutableSet.of(vadasId, peterId, joshId, lopId, rippleId);
Assert.assertEquals(expected, kneighborResult.ids());
Assert.assertEquals(5, kneighborResult.paths().size());
expectedPaths = ImmutableList.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId), ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (Path path : kneighborResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class KoutApiTest method testKoutPostWithVertex.
@Test
public void testKoutPostWithVertex() {
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");
KoutRequest.Builder builder = KoutRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(false);
builder.withVertex(true);
KoutRequest request = builder.build();
Kout koutResult = koutAPI.post(request);
Assert.assertEquals(3, koutResult.size());
Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, koutResult.ids());
Assert.assertEquals(3, koutResult.vertices().size());
Set<Object> expectedVids = ImmutableSet.of(vadasId, lopId, joshId);
for (Vertex vertex : koutResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KoutRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(false);
builder.withVertex(true);
request = builder.build();
koutResult = koutAPI.post(request);
Assert.assertEquals(2, koutResult.size());
expected = ImmutableSet.of(peterId, rippleId);
Assert.assertEquals(expected, koutResult.ids());
Assert.assertEquals(2, koutResult.vertices().size());
expectedVids = ImmutableSet.of(peterId, rippleId);
for (Vertex vertex : koutResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KoutRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(true);
builder.withVertex(true);
request = builder.build();
koutResult = koutAPI.post(request);
Assert.assertEquals(3, koutResult.size());
expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, koutResult.ids());
Assert.assertEquals(3, koutResult.paths().size());
Set<List<Object>> expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
for (Path path : koutResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
Assert.assertEquals(4, koutResult.vertices().size());
expectedVids = ImmutableSet.of(markoId, vadasId, lopId, joshId);
for (Vertex vertex : koutResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
builder = KoutRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(true);
builder.withVertex(true);
request = builder.build();
koutResult = koutAPI.post(request);
Assert.assertEquals(2, koutResult.size());
expected = ImmutableSet.of(peterId, rippleId);
Assert.assertEquals(expected, koutResult.ids());
Assert.assertEquals(2, koutResult.paths().size());
expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (Path path : koutResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
Assert.assertEquals(5, koutResult.vertices().size());
expectedVids = ImmutableSet.of(markoId, peterId, lopId, joshId, rippleId);
for (Vertex vertex : koutResult.vertices()) {
Assert.assertTrue(expectedVids.contains(vertex.id()));
}
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class KoutApiTest method testKoutPostWithPath.
@Test
public void testKoutPostWithPath() {
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");
KoutRequest.Builder builder = KoutRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(1);
builder.withPath(true);
KoutRequest request = builder.build();
Kout koutResult = koutAPI.post(request);
Assert.assertEquals(3, koutResult.size());
Set<Object> expected = ImmutableSet.of(vadasId, lopId, joshId);
Assert.assertEquals(expected, koutResult.ids());
Assert.assertEquals(3, koutResult.paths().size());
List<Object> expectedPaths = ImmutableList.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
for (Path path : koutResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
builder = KoutRequest.builder();
builder.source(markoId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(2);
builder.withPath(true);
request = builder.build();
koutResult = koutAPI.post(request);
Assert.assertEquals(2, koutResult.size());
expected = ImmutableSet.of(peterId, rippleId);
Assert.assertEquals(expected, koutResult.ids());
Assert.assertEquals(2, koutResult.paths().size());
expectedPaths = ImmutableList.of(ImmutableList.of(markoId, lopId, peterId), ImmutableList.of(markoId, joshId, rippleId));
for (Path path : koutResult.paths()) {
Assert.assertTrue(expectedPaths.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.graph.Path in project incubator-hugegraph-toolchain by apache.
the class ShortestPathAPI method get.
public Path get(Object sourceId, Object targetId, Direction direction, String label, int maxDepth, long degree, long skipDegree, long capacity) {
String source = GraphAPI.formatVertexId(sourceId, false);
String target = GraphAPI.formatVertexId(targetId, false);
checkPositive(maxDepth, "Max depth of shortest path");
checkDegree(degree);
checkCapacity(capacity);
checkSkipDegree(skipDegree, degree, capacity);
Map<String, Object> params = new LinkedHashMap<>();
params.put("source", source);
params.put("target", target);
params.put("direction", direction);
params.put("label", label);
params.put("max_depth", maxDepth);
params.put("max_degree", degree);
params.put("skip_degree", skipDegree);
params.put("capacity", capacity);
RestResult result = this.client.get(this.path(), params);
List<Object> vertices = result.readList("path", Object.class);
return new Path(vertices);
}
Aggregations