Search in sources :

Example 11 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityMinSimilars.

@Test
public void testFusiformSimilarityMinSimilars() {
    Object p1 = getVertexId("person", "name", "p1");
    Object p2 = getVertexId("person", "name", "p2");
    Object p3 = getVertexId("person", "name", "p3");
    FusiformSimilarityRequest.Builder builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p1");
    builder.label("read").direction(Direction.OUT).minNeighbors(8).alpha(0.75D).minSimilars(3).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(0, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p1");
    builder.label("read").direction(Direction.OUT).minNeighbors(8).alpha(0.75D).minSimilars(2).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
    Map.Entry<Object, Set<Similar>> entry = results.first();
    Assert.assertEquals(p1, entry.getKey());
    Assert.assertEquals(2, entry.getValue().size());
    Set<Object> expected = ImmutableSet.of(p2, p3);
    Set<Object> actual = entry.getValue().stream().map(Similar::id).collect(Collectors.toSet());
    Assert.assertEquals(expected, actual);
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p1");
    builder.label("read").direction(Direction.OUT).minNeighbors(8).alpha(0.75D).minSimilars(1).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
    entry = results.first();
    Assert.assertEquals(p1, entry.getKey());
    Assert.assertEquals(2, entry.getValue().size());
    Assert.assertEquals(expected, actual);
    Assert.assertThrows(IllegalArgumentException.class, () -> {
        FusiformSimilarityRequest.builder().minSimilars(0);
    });
}
Also used : FusiformSimilarity(com.baidu.hugegraph.structure.traverser.FusiformSimilarity) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) FusiformSimilarityRequest(com.baidu.hugegraph.structure.traverser.FusiformSimilarityRequest) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 12 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityLimit.

@Test
public void testFusiformSimilarityLimit() {
    Object p1 = getVertexId("person", "name", "p1");
    Object p2 = getVertexId("person", "name", "p2");
    Object p3 = getVertexId("person", "name", "p3");
    FusiformSimilarityRequest.Builder builder = FusiformSimilarityRequest.builder();
    builder.sources().ids(p1, p2, p3);
    builder.label("read").direction(Direction.OUT).minNeighbors(5).alpha(0.8D).top(2);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(3, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().ids(p1, p2, p3);
    builder.label("read").direction(Direction.OUT).minNeighbors(5).alpha(0.8D).top(2);
    builder.capacity(-1).limit(2);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(2, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().ids(p1, p2, p3);
    builder.label("read").direction(Direction.OUT).minNeighbors(5).alpha(0.8D).top(2);
    builder.capacity(-1).limit(1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
}
Also used : FusiformSimilarity(com.baidu.hugegraph.structure.traverser.FusiformSimilarity) FusiformSimilarityRequest(com.baidu.hugegraph.structure.traverser.FusiformSimilarityRequest) Test(org.junit.Test)

Example 13 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityLessThanMinEdgeCount.

@Test
public void testFusiformSimilarityLessThanMinEdgeCount() {
    FusiformSimilarityRequest.Builder builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p1");
    builder.label("read").direction(Direction.OUT).minNeighbors(10).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(0, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p1");
    builder.label("read").direction(Direction.OUT).minNeighbors(9).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p2");
    builder.label("read").direction(Direction.OUT).minNeighbors(10).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(0, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p2");
    builder.label("read").direction(Direction.OUT).minNeighbors(9).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p3");
    builder.label("read").direction(Direction.OUT).minNeighbors(8).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(0, results.size());
    builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p2");
    builder.label("read").direction(Direction.OUT).minNeighbors(7).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
}
Also used : FusiformSimilarity(com.baidu.hugegraph.structure.traverser.FusiformSimilarity) FusiformSimilarityRequest(com.baidu.hugegraph.structure.traverser.FusiformSimilarityRequest) Test(org.junit.Test)

Aggregations

FusiformSimilarityRequest (com.baidu.hugegraph.structure.traverser.FusiformSimilarityRequest)13 Test (org.junit.Test)13 FusiformSimilarity (com.baidu.hugegraph.structure.traverser.FusiformSimilarity)12 ImmutableMap (com.google.common.collect.ImmutableMap)10 ImmutableSet (com.google.common.collect.ImmutableSet)10 Map (java.util.Map)10 Set (java.util.Set)10 Similar (com.baidu.hugegraph.structure.traverser.FusiformSimilarity.Similar)5 Vertex (com.baidu.hugegraph.structure.graph.Vertex)4