Search in sources :

Example 6 with Path

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)));
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 7 with Path

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()));
    }
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Kneighbor(com.baidu.hugegraph.structure.traverser.Kneighbor) KneighborRequest(com.baidu.hugegraph.structure.traverser.KneighborRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 8 with Path

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()));
    }
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 9 with Path

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()));
    }
}
Also used : Kout(com.baidu.hugegraph.structure.traverser.Kout) Path(com.baidu.hugegraph.structure.graph.Path) KoutRequest(com.baidu.hugegraph.structure.traverser.KoutRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 10 with Path

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);
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) RestResult(com.baidu.hugegraph.rest.RestResult) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Path (com.baidu.hugegraph.structure.graph.Path)30 Test (org.junit.Test)21 Vertex (com.baidu.hugegraph.structure.graph.Vertex)11 Edge (com.baidu.hugegraph.structure.graph.Edge)9 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)7 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)6 Result (com.baidu.hugegraph.structure.gremlin.Result)6 HugeClient (com.baidu.hugegraph.driver.HugeClient)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)4 ArrayList (java.util.ArrayList)4 GremlinResult (com.baidu.hugegraph.entity.query.GremlinResult)3 TableView (com.baidu.hugegraph.entity.query.TableView)3 TypedResult (com.baidu.hugegraph.entity.query.TypedResult)3 HashMap (java.util.HashMap)3 GremlinRequest (com.baidu.hugegraph.api.gremlin.GremlinRequest)2 Type (com.baidu.hugegraph.entity.query.GremlinResult.Type)2 JsonView (com.baidu.hugegraph.entity.query.JsonView)2 RestResult (com.baidu.hugegraph.rest.RestResult)2