Search in sources :

Example 1 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityWithoutIntermediaryWithVertex.

@Test
public void testFusiformSimilarityWithoutIntermediaryWithVertex() {
    Vertex p1 = getVertex("person", "name", "p1");
    Vertex p2 = getVertex("person", "name", "p2");
    Vertex p3 = getVertex("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).withIntermediary(false).withVertex(true);
    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.id(), entry.getKey());
    Assert.assertEquals(2, entry.getValue().size());
    Set<Similar> similars = entry.getValue();
    for (Similar similar : similars) {
        if (similar.id().equals(p2.id())) {
            Assert.assertEquals(ImmutableSet.of(), similar.intermediaries());
        } else {
            Assert.assertEquals(p3.id(), similar.id());
            Assert.assertEquals(ImmutableSet.of(), similar.intermediaries());
        }
    }
    Set<Vertex> vertices = ImmutableSet.of(p1, p2, p3);
    Assert.assertEquals(vertices, results.vertices());
}
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) Similar(com.baidu.hugegraph.structure.traverser.FusiformSimilarity.Similar) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityCapacity.

@Test
public void testFusiformSimilarityCapacity() {
    FusiformSimilarityRequest.Builder builder = FusiformSimilarityRequest.builder();
    builder.sources().label("person").property("name", "p1");
    builder.label("read").direction(Direction.OUT).minNeighbors(8).alpha(0.8D).groupProperty("city").minGroups(2);
    builder.capacity(10).limit(-1);
    FusiformSimilarityRequest request = builder.build();
    Assert.assertThrows(ServerException.class, () -> {
        fusiformSimilarityAPI.post(request);
    }, e -> {
        String expect = "Exceed capacity '10' while " + "finding fusiform similarity";
        Assert.assertContains(expect, e.getMessage());
    });
}
Also used : FusiformSimilarityRequest(com.baidu.hugegraph.structure.traverser.FusiformSimilarityRequest) Test(org.junit.Test)

Example 3 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityWithIntermediaryAndVertex.

@Test
public void testFusiformSimilarityWithIntermediaryAndVertex() {
    Vertex p1 = getVertex("person", "name", "p1");
    Vertex p2 = getVertex("person", "name", "p2");
    Vertex p3 = getVertex("person", "name", "p3");
    Vertex b2 = getVertex("book", "name", "b2");
    Vertex b3 = getVertex("book", "name", "b3");
    Vertex b4 = getVertex("book", "name", "b4");
    Vertex b5 = getVertex("book", "name", "b5");
    Vertex b6 = getVertex("book", "name", "b6");
    Vertex b7 = getVertex("book", "name", "b7");
    Vertex b8 = getVertex("book", "name", "b8");
    Vertex b9 = getVertex("book", "name", "b9");
    Object p1Id = p1.id();
    Object p2Id = p2.id();
    Object p3Id = p3.id();
    Object b2Id = b2.id();
    Object b3Id = b3.id();
    Object b4Id = b4.id();
    Object b5Id = b5.id();
    Object b6Id = b6.id();
    Object b7Id = b7.id();
    Object b8Id = b8.id();
    Object b9Id = b9.id();
    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).withIntermediary(true).withVertex(true);
    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(p1Id, entry.getKey());
    Assert.assertEquals(2, entry.getValue().size());
    Set<Similar> similars = entry.getValue();
    Set<Object> p2Inter = ImmutableSet.of(b2Id, b3Id, b4Id, b5Id, b6Id, b7Id, b8Id, b9Id);
    Set<Object> p3Inter = ImmutableSet.of(b3Id, b4Id, b5Id, b6Id, b7Id, b8Id, b9Id);
    for (Similar similar : similars) {
        if (similar.id().equals(p2Id)) {
            Assert.assertEquals(p2Inter, similar.intermediaries());
        } else {
            Assert.assertEquals(p3Id, similar.id());
            Assert.assertEquals(p3Inter, similar.intermediaries());
        }
    }
    Set<Vertex> vertices = ImmutableSet.of(p1, p2, p3, b2, b3, b4, b5, b6, b7, b8, b9);
    Assert.assertEquals(vertices, results.vertices());
}
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) Similar(com.baidu.hugegraph.structure.traverser.FusiformSimilarity.Similar) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarity.

@Test
public void testFusiformSimilarity() {
    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);
}
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 5 with FusiformSimilarityRequest

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

the class FusiformSimilarityApiTest method testFusiformSimilarityWithIntermediaryWithoutVertex.

@Test
public void testFusiformSimilarityWithIntermediaryWithoutVertex() {
    Vertex p1 = getVertex("person", "name", "p1");
    Vertex p2 = getVertex("person", "name", "p2");
    Vertex p3 = getVertex("person", "name", "p3");
    Vertex b2 = getVertex("book", "name", "b2");
    Vertex b3 = getVertex("book", "name", "b3");
    Vertex b4 = getVertex("book", "name", "b4");
    Vertex b5 = getVertex("book", "name", "b5");
    Vertex b6 = getVertex("book", "name", "b6");
    Vertex b7 = getVertex("book", "name", "b7");
    Vertex b8 = getVertex("book", "name", "b8");
    Vertex b9 = getVertex("book", "name", "b9");
    Object p1Id = p1.id();
    Object p2Id = p2.id();
    Object p3Id = p3.id();
    Object b2Id = b2.id();
    Object b3Id = b3.id();
    Object b4Id = b4.id();
    Object b5Id = b5.id();
    Object b6Id = b6.id();
    Object b7Id = b7.id();
    Object b8Id = b8.id();
    Object b9Id = b9.id();
    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).withIntermediary(true).withVertex(false);
    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(p1Id, entry.getKey());
    Assert.assertEquals(2, entry.getValue().size());
    Set<Similar> similars = entry.getValue();
    Set<Object> p2Inter = ImmutableSet.of(b2Id, b3Id, b4Id, b5Id, b6Id, b7Id, b8Id, b9Id);
    Set<Object> p3Inter = ImmutableSet.of(b3Id, b4Id, b5Id, b6Id, b7Id, b8Id, b9Id);
    for (Similar similar : similars) {
        if (similar.id().equals(p2Id)) {
            Assert.assertEquals(p2Inter, similar.intermediaries());
        } else {
            Assert.assertEquals(p3Id, similar.id());
            Assert.assertEquals(p3Inter, similar.intermediaries());
        }
    }
    Set<Vertex> vertices = ImmutableSet.of();
    Assert.assertEquals(vertices, results.vertices());
}
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) Similar(com.baidu.hugegraph.structure.traverser.FusiformSimilarity.Similar) 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