Search in sources :

Example 1 with CustomizedPathsRequest

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

the class CustomizedPathsApiTest method testCustomizedPathsSourceLabelProperty.

@Test
public void testCustomizedPathsSourceLabelProperty() {
    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);
    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, joshId, lopId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, rippleId);
    Assert.assertEquals(path1, paths.get(0).objects());
    Assert.assertEquals(path2, paths.get(1).objects());
    List<Double> weights1 = ImmutableList.of(1.0D, 0.4D);
    List<Double> weights2 = ImmutableList.of(1.0D, 1.0D);
    Assert.assertEquals(weights1, paths.get(0).weights());
    Assert.assertEquals(weights2, paths.get(1).weights());
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(4, vertices.size());
    Set<?> expectedVertices = ImmutableSet.of(markoId, lopId, rippleId, joshId);
    Assert.assertEquals(expectedVertices, vertices);
}
Also used : CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 2 with CustomizedPathsRequest

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

the class CustomizedPathsApiTest method testCustomizedPathsWithCapacity.

@Test
public void testCustomizedPathsWithCapacity() {
    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);
    builder.sortBy(CustomizedPathsRequest.SortBy.INCR).withVertex(true).capacity(1).limit(-1);
    CustomizedPathsRequest request = builder.build();
    Assert.assertThrows(ServerException.class, () -> {
        customizedPathsAPI.post(request);
    }, e -> {
        String expect = "Exceed capacity '1' while finding customized paths";
        Assert.assertContains(expect, e.getMessage());
    });
}
Also used : CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 3 with CustomizedPathsRequest

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

the class CustomizedPathsApiTest method testCustomizedPathsWithLimit.

@Test
public void testCustomizedPathsWithLimit() {
    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);
    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, lopId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, rippleId);
    List<List<Object>> expectedPaths = ImmutableList.of(path1, path2);
    Assert.assertTrue(expectedPaths.contains(paths.get(0).objects()));
    List<Double> weights1 = ImmutableList.of(1.0D, 0.4D);
    List<Double> weights2 = ImmutableList.of(1.0D, 1.0D);
    List<List<Double>> expectedWeights = ImmutableList.of(weights1, weights2);
    Assert.assertTrue(expectedWeights.contains(paths.get(0).weights()));
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(3, vertices.size());
    Set<?> vertices1 = ImmutableSet.of(markoId, lopId, joshId);
    Set<?> vertices2 = ImmutableSet.of(markoId, lopId, rippleId);
    Set<Set<?>> expectedVertices = ImmutableSet.of(vertices1, vertices2);
    Assert.assertTrue(expectedVertices.contains(vertices));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 4 with CustomizedPathsRequest

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

the class CustomizedPathsApiTest method testCustomizedPathsSourceLabelPropertyMultiValue.

@Test
public void testCustomizedPathsSourceLabelPropertyMultiValue() {
    Object markoId = getVertexId("person", "name", "marko");
    Object lopId = getVertexId("software", "name", "lop");
    Object peterId = getVertexId("person", "name", "peter");
    CustomizedPathsRequest.Builder builder = CustomizedPathsRequest.builder();
    List<String> names = ImmutableList.of("marko", "peter");
    builder.sources().label("person").property("name", names);
    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);
}
Also used : CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Example 5 with CustomizedPathsRequest

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

the class CustomizedPathsApiTest method testCustomizedPathsWithDecr.

@Test
public void testCustomizedPathsWithDecr() {
    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);
    builder.sortBy(CustomizedPathsRequest.SortBy.DECR).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, joshId, rippleId);
    List<Object> path2 = ImmutableList.of(markoId, joshId, lopId);
    Assert.assertEquals(path1, paths.get(0).objects());
    Assert.assertEquals(path2, paths.get(1).objects());
    List<Double> weights1 = ImmutableList.of(1.0D, 1.0D);
    List<Double> weights2 = ImmutableList.of(1.0D, 0.4D);
    Assert.assertEquals(weights1, paths.get(0).weights());
    Assert.assertEquals(weights2, paths.get(1).weights());
    Set<?> vertices = customizedPaths.vertices().stream().map(Vertex::id).collect(Collectors.toSet());
    Assert.assertEquals(4, vertices.size());
    Set<?> expectedVertices = ImmutableSet.of(markoId, lopId, rippleId, joshId);
    Assert.assertEquals(expectedVertices, vertices);
}
Also used : CustomizedPathsRequest(com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest) PathsWithVertices(com.baidu.hugegraph.structure.traverser.PathsWithVertices) Test(org.junit.Test) BaseApiTest(com.baidu.hugegraph.api.BaseApiTest)

Aggregations

BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)7 CustomizedPathsRequest (com.baidu.hugegraph.structure.traverser.CustomizedPathsRequest)7 Test (org.junit.Test)7 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)6 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ImmutableSet (com.google.common.collect.ImmutableSet)1 Set (java.util.Set)1