Search in sources :

Example 6 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityWithMultiTimesEdges.

@Test
public void testFusiformSimilarityWithMultiTimesEdges() {
    Vertex p1 = getVertex("person", "name", "p1");
    Vertex p2 = getVertex("person", "name", "p2");
    Vertex p3 = getVertex("person", "name", "p3");
    Object id1 = p1.id();
    Object id2 = p2.id();
    Object id3 = p3.id();
    FusiformSimilarityRequest.Builder builder = FusiformSimilarityRequest.builder();
    builder.sources().ids(id1, id2, id3);
    builder.label("write").direction(Direction.OUT).minNeighbors(3).alpha(0.666D);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(1, results.size());
    Map.Entry<Object, Set<Similar>> entry = results.first();
    Assert.assertEquals(id1, entry.getKey());
    Assert.assertEquals(1, entry.getValue().size());
    Set<Object> actual = entry.getValue().stream().map(Similar::id).collect(Collectors.toSet());
    Assert.assertEquals(ImmutableSet.of(id3), actual);
}
Also used : FusiformSimilarity(com.baidu.hugegraph.structure.traverser.FusiformSimilarity) Vertex(com.baidu.hugegraph.structure.graph.Vertex) 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 7 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityTop.

@Test
public void testFusiformSimilarityTop() {
    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).top(2);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity 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(6).alpha(0.8D).top(1);
    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(1, entry.getValue().size());
    expected = ImmutableSet.of(p2);
    actual = entry.getValue().stream().map(Similar::id).collect(Collectors.toSet());
    Assert.assertEquals(expected, actual);
}
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) Similar(com.baidu.hugegraph.structure.traverser.FusiformSimilarity.Similar) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 8 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityMinGroupCount.

@Test
public void testFusiformSimilarityMinGroupCount() {
    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.7D).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity 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(6).alpha(0.8D).groupProperty("city").minGroups(3);
    builder.capacity(-1).limit(-1);
    request = builder.build();
    results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(0, results.size());
}
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 9 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityAlpha.

@Test
public void testFusiformSimilarityAlpha() {
    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).groupProperty("city").minGroups(2);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity 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(6).alpha(0.83D).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(1, entry.getValue().size());
    expected = ImmutableSet.of(p2);
    actual = entry.getValue().stream().map(Similar::id).collect(Collectors.toSet());
    Assert.assertEquals(expected, actual);
}
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) Similar(com.baidu.hugegraph.structure.traverser.FusiformSimilarity.Similar) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 10 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityWithoutEdgeLabel.

@Test
public void testFusiformSimilarityWithoutEdgeLabel() {
    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.direction(Direction.OUT).minNeighbors(8).alpha(0.875D);
    builder.capacity(-1).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    FusiformSimilarity results = fusiformSimilarityAPI.post(request);
    Assert.assertEquals(3, results.size());
    Map<Object, Set<Object>> expected = ImmutableMap.of(p1, ImmutableSet.of(p2, p3), p2, ImmutableSet.of(p1), p3, ImmutableSet.of(p1, p2));
    for (Map.Entry<Object, Set<Similar>> e : results.similarsMap().entrySet()) {
        Object key = e.getKey();
        Set<Object> actual = e.getValue().stream().map(Similar::id).collect(Collectors.toSet());
        Assert.assertEquals(expected.get(key), actual);
    }
}
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)

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