Search in sources :

Example 1 with PathsWithVertices

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

the class PathsApiTest method testPathsPostWithLabel.

@Test
public void testPathsPostWithLabel() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    PathsRequest.Builder builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(3);
    PathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = pathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId), ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH).labels("created");
    builder.maxDepth(3);
    request = builder.build();
    pathsWithVertices = pathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PathsRequest(com.baidu.hugegraph.structure.traverser.PathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 2 with PathsWithVertices

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

the class PathsApiTest method testPathsPostWithNearest.

@Test
public void testPathsPostWithNearest() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    Vertex tom = graph().addVertex(T.label, "person", "name", "Tom", "age", 29, "city", "Shanghai");
    Vertex jim = graph().addVertex(T.label, "person", "name", "Jim", "age", 29, "city", "Shanghai");
    Vertex java = graph().addVertex(T.label, "software", "name", "java", "lang", "java", "price", 199);
    Object tomId = tom.id();
    Object jimId = jim.id();
    Object javaId = java.id();
    graph().addEdge(tomId, "created", rippleId, "date", "2016-01-10", "city", "Beijing");
    graph().addEdge(tomId, "created", javaId, "date", "2017-01-10", "city", "Hongkong");
    graph().addEdge(jimId, "created", javaId, "date", "2017-01-10", "city", "Hongkong");
    PathsRequest.Builder builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(jimId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(6);
    PathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = pathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId, tomId, javaId, jimId), ImmutableList.of(markoId, joshId, rippleId, tomId, javaId, jimId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(jimId);
    builder.step().direction(Direction.BOTH);
    builder.nearest(true);
    builder.maxDepth(6);
    request = builder.build();
    pathsWithVertices = pathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    expected = ImmutableList.of(ImmutableList.of(markoId, joshId, rippleId, tomId, javaId, jimId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
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) PathsRequest(com.baidu.hugegraph.structure.traverser.PathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 3 with PathsWithVertices

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

the class PathsApiTest method testPathsPostWithProperties.

@Test
public void testPathsPostWithProperties() {
    Object markoId = getVertexId("person", "name", "marko");
    Object rippleId = getVertexId("software", "name", "ripple");
    Object joshId = getVertexId("person", "name", "josh");
    Object lopId = getVertexId("software", "name", "lop");
    PathsRequest.Builder builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(3);
    PathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = pathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(2, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId), ImmutableList.of(markoId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = PathsRequest.builder();
    builder.sources().ids(markoId);
    builder.targets().ids(rippleId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(3);
    request = builder.build();
    pathsWithVertices = pathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) PathsRequest(com.baidu.hugegraph.structure.traverser.PathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 4 with PathsWithVertices

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

the class TemplatePathsApiTest method testTemplatePathsWithProperties.

@Test
public void testTemplatePathsWithProperties() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
    builder.withRing(true);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(4, paths.size());
    List<List<Object>> expected = ImmutableList.of(ImmutableList.of(1, 16, 17, 10), ImmutableList.of(1, 16, 17, 16, 17, 10), ImmutableList.of(1, 16, 17, 16, 17, 16, 17, 10), ImmutableList.of(1, 16, 17, 16, 17, 16, 17, 16, 17, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
    builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("relateTo").properties("weight", "P.gt(0.4)").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").properties("weight", "P.gt(0.4)").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").properties("weight", "P.gt(0.4)").maxTimes(3);
    builder.withRing(true);
    request = builder.build();
    pathsWithVertices = templatePathsAPI.post(request);
    paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    expected = ImmutableList.of(ImmutableList.of(1, 16, 17, 10));
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expected.contains(path.objects()));
    }
}
Also used : TemplatePathsRequest(com.baidu.hugegraph.structure.traverser.TemplatePathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

Example 5 with PathsWithVertices

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

the class TemplatePathsApiTest method testTemplatePathsWithVertex.

@Test
public void testTemplatePathsWithVertex() {
    TemplatePathsRequest.Builder builder = TemplatePathsRequest.builder();
    builder.sources().ids(1);
    builder.targets().ids(10);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.OUT).labels("relateTo").maxTimes(3);
    builder.steps().direction(Direction.IN).labels("relateTo").maxTimes(3);
    builder.withVertex(true);
    TemplatePathsRequest request = builder.build();
    PathsWithVertices pathsWithVertices = templatePathsAPI.post(request);
    List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
    Assert.assertEquals(1, paths.size());
    List<Object> expectedIds = ImmutableList.of(1, 16, 17, 10);
    List<List<Object>> expectedPath = ImmutableList.of(expectedIds);
    for (PathsWithVertices.Paths path : paths) {
        Assert.assertTrue(expectedPath.contains(path.objects()));
    }
    Set<Vertex> vertices = pathsWithVertices.vertices();
    Assert.assertEquals(4, vertices.size());
    for (Vertex v : vertices) {
        Assert.assertTrue(expectedIds.contains(v.id()));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) TemplatePathsRequest(com.baidu.hugegraph.structure.traverser.TemplatePathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test)

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