Search in sources :

Example 1 with Kneighbor

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

the class KneighborApiTest method testKneighborPostWithVertex.

@Test
public void testKneighborPostWithVertex() {
    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(false);
    builder.withVertex(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.vertices().size());
    Set<Object> expectedVids = ImmutableSet.of(vadasId, lopId, joshId);
    for (Vertex vertex : kneighborResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(false);
    builder.withVertex(true);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(5, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
    Assert.assertEquals(expected, kneighborResult.ids());
    Assert.assertEquals(5, kneighborResult.vertices().size());
    expectedVids = ImmutableSet.of(vadasId, lopId, joshId, peterId, rippleId);
    for (Vertex vertex : kneighborResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(1);
    builder.withPath(true);
    builder.withVertex(true);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(3, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId);
    Assert.assertEquals(expected, kneighborResult.ids());
    Assert.assertEquals(3, kneighborResult.paths().size());
    Set<List<Object>> expectedPaths = ImmutableSet.of(ImmutableList.of(markoId, vadasId), ImmutableList.of(markoId, lopId), ImmutableList.of(markoId, joshId));
    for (Path path : kneighborResult.paths()) {
        Assert.assertTrue(expectedPaths.contains(path.objects()));
    }
    Assert.assertEquals(4, kneighborResult.vertices().size());
    expectedVids = ImmutableSet.of(markoId, vadasId, lopId, joshId);
    for (Vertex vertex : kneighborResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH);
    builder.maxDepth(2);
    builder.withPath(true);
    builder.withVertex(true);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(5, kneighborResult.size());
    expected = ImmutableSet.of(peterId, lopId, joshId, rippleId, vadasId);
    Assert.assertEquals(expected, kneighborResult.ids());
    Assert.assertEquals(5, kneighborResult.paths().size());
    expectedPaths = ImmutableSet.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()));
    }
    Assert.assertEquals(6, kneighborResult.vertices().size());
    expectedVids = ImmutableSet.of(markoId, peterId, lopId, joshId, rippleId, vadasId);
    for (Vertex vertex : kneighborResult.vertices()) {
        Assert.assertTrue(expectedVids.contains(vertex.id()));
    }
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Kneighbor(com.baidu.hugegraph.structure.traverser.Kneighbor) Vertex(com.baidu.hugegraph.structure.graph.Vertex) KneighborRequest(com.baidu.hugegraph.structure.traverser.KneighborRequest) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 2 with Kneighbor

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

the class KneighborApiTest method testKneighborPostWithDirection.

@Test
public void testKneighborPostWithDirection() {
    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");
    KneighborRequest.Builder builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.OUT);
    builder.maxDepth(1);
    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());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.OUT);
    builder.maxDepth(2);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(4, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, lopId, joshId, rippleId);
    Assert.assertEquals(expected, kneighborResult.ids());
}
Also used : 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 3 with Kneighbor

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

the class KneighborApiTest method testKneighborPostWithLabel.

@Test
public void testKneighborPostWithLabel() {
    Object markoId = getVertexId("person", "name", "marko");
    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).labels("created");
    builder.maxDepth(1);
    KneighborRequest request = builder.build();
    Kneighbor kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(1, kneighborResult.size());
    Set<Object> expected = ImmutableSet.of(lopId);
    Assert.assertEquals(expected, kneighborResult.ids());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("created");
    builder.maxDepth(2);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(3, kneighborResult.size());
    expected = ImmutableSet.of(lopId, peterId, joshId);
    Assert.assertEquals(expected, kneighborResult.ids());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("knows");
    builder.maxDepth(1);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(2, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, joshId);
    Assert.assertEquals(expected, kneighborResult.ids());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).labels("knows");
    builder.maxDepth(2);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(2, kneighborResult.size());
    expected = ImmutableSet.of(vadasId, joshId);
    Assert.assertEquals(expected, kneighborResult.ids());
}
Also used : 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 4 with Kneighbor

use of com.baidu.hugegraph.structure.traverser.Kneighbor 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 5 with Kneighbor

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

the class KneighborApiTest method testKneighborPostWithProperties.

@Test
public void testKneighborPostWithProperties() {
    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 peterId = getVertexId("person", "name", "peter");
    KneighborRequest.Builder builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(1);
    KneighborRequest request = builder.build();
    Kneighbor kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(1, kneighborResult.size());
    Set<Object> expected = ImmutableSet.of(lopId);
    Assert.assertEquals(expected, kneighborResult.ids());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(2);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(3, kneighborResult.size());
    expected = ImmutableSet.of(lopId, peterId, joshId);
    Assert.assertEquals(expected, kneighborResult.ids());
    builder = KneighborRequest.builder();
    builder.source(markoId);
    builder.step().direction(Direction.BOTH).properties("date", "P.gt(\"2014-01-01 00:00:00\")");
    builder.maxDepth(3);
    request = builder.build();
    kneighborResult = kneighborAPI.post(request);
    Assert.assertEquals(4, kneighborResult.size());
    expected = ImmutableSet.of(lopId, peterId, joshId, rippleId);
    Assert.assertEquals(expected, kneighborResult.ids());
}
Also used : Kneighbor(com.baidu.hugegraph.structure.traverser.Kneighbor) KneighborRequest(com.baidu.hugegraph.structure.traverser.KneighborRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)8 Kneighbor (com.baidu.hugegraph.structure.traverser.Kneighbor)8 KneighborRequest (com.baidu.hugegraph.structure.traverser.KneighborRequest)8 Test (org.junit.Test)8 Path (com.baidu.hugegraph.structure.graph.Path)2 Vertex (com.baidu.hugegraph.structure.graph.Vertex)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1