use of com.baidu.hugegraph.structure.graph.Vertex 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()));
}
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class NeighborRankApiTest method initNeighborRankGraph.
@BeforeClass
public static void initNeighborRankGraph() {
GraphManager graph = graph();
SchemaManager schema = schema();
schema.propertyKey("name").asText().ifNotExist().create();
schema.vertexLabel("person").properties("name").useCustomizeStringId().ifNotExist().create();
schema.vertexLabel("movie").properties("name").useCustomizeStringId().ifNotExist().create();
schema.edgeLabel("follow").sourceLabel("person").targetLabel("person").ifNotExist().create();
schema.edgeLabel("like").sourceLabel("person").targetLabel("movie").ifNotExist().create();
schema.edgeLabel("directedBy").sourceLabel("movie").targetLabel("person").ifNotExist().create();
Vertex O = graph.addVertex(T.label, "person", T.id, "O", "name", "O");
Vertex A = graph.addVertex(T.label, "person", T.id, "A", "name", "A");
Vertex B = graph.addVertex(T.label, "person", T.id, "B", "name", "B");
Vertex C = graph.addVertex(T.label, "person", T.id, "C", "name", "C");
Vertex D = graph.addVertex(T.label, "person", T.id, "D", "name", "D");
Vertex E = graph.addVertex(T.label, "movie", T.id, "E", "name", "E");
Vertex F = graph.addVertex(T.label, "movie", T.id, "F", "name", "F");
Vertex G = graph.addVertex(T.label, "movie", T.id, "G", "name", "G");
Vertex H = graph.addVertex(T.label, "movie", T.id, "H", "name", "H");
Vertex I = graph.addVertex(T.label, "movie", T.id, "I", "name", "I");
Vertex J = graph.addVertex(T.label, "movie", T.id, "J", "name", "J");
Vertex K = graph.addVertex(T.label, "person", T.id, "K", "name", "K");
Vertex L = graph.addVertex(T.label, "person", T.id, "L", "name", "L");
Vertex M = graph.addVertex(T.label, "person", T.id, "M", "name", "M");
O.addEdge("follow", A);
O.addEdge("follow", B);
O.addEdge("follow", C);
D.addEdge("follow", O);
A.addEdge("follow", B);
A.addEdge("like", E);
A.addEdge("like", F);
B.addEdge("like", G);
B.addEdge("like", H);
C.addEdge("like", I);
C.addEdge("like", J);
E.addEdge("directedBy", K);
F.addEdge("directedBy", B);
F.addEdge("directedBy", L);
G.addEdge("directedBy", M);
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class NeighborRankApiTest method testNeighborRankWithIsolatedVertex.
@Test
public void testNeighborRankWithIsolatedVertex() {
Vertex isolate = graph().addVertex(T.label, "person", T.id, "isolate", "name", "isolate-vertex");
NeighborRankAPI.Request.Builder builder;
builder = NeighborRankAPI.Request.builder();
builder.source("isolate").alpha(0.9);
builder.steps().direction(Direction.BOTH);
NeighborRankAPI.Request request = builder.build();
List<Ranks> ranks = neighborRankAPI.post(request);
Assert.assertEquals(2, ranks.size());
Assert.assertEquals(ImmutableMap.of("isolate", 1.0D), ranks.get(0));
Assert.assertEquals(ImmutableMap.of(), ranks.get(1));
graph().removeVertex(isolate.id());
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class PathsApiTest method testPathsPostWithNearest.
@Test
public void testPathsPostWithNearest() {
Object markoId = getVertexId("person", "name", "marko");
Object rippleId = getVertexId("software", "name", "ripple");
Object joshId = getVertexId("person", "name", "josh");
Object lopId = getVertexId("software", "name", "lop");
Vertex tom = graph().addVertex(T.label, "person", "name", "Tom", "age", 29, "city", "Shanghai");
Vertex jim = graph().addVertex(T.label, "person", "name", "Jim", "age", 29, "city", "Shanghai");
Vertex java = graph().addVertex(T.label, "software", "name", "java", "lang", "java", "price", 199);
Object tomId = tom.id();
Object jimId = jim.id();
Object javaId = java.id();
graph().addEdge(tomId, "created", rippleId, "date", "2016-01-10", "city", "Beijing");
graph().addEdge(tomId, "created", javaId, "date", "2017-01-10", "city", "Hongkong");
graph().addEdge(jimId, "created", javaId, "date", "2017-01-10", "city", "Hongkong");
PathsRequest.Builder builder = PathsRequest.builder();
builder.sources().ids(markoId);
builder.targets().ids(jimId);
builder.step().direction(Direction.BOTH);
builder.maxDepth(6);
PathsRequest request = builder.build();
PathsWithVertices pathsWithVertices = pathsAPI.post(request);
List<PathsWithVertices.Paths> paths = pathsWithVertices.paths();
Assert.assertEquals(2, paths.size());
List<List<Object>> expected = ImmutableList.of(ImmutableList.of(markoId, lopId, joshId, rippleId, tomId, javaId, jimId), ImmutableList.of(markoId, joshId, rippleId, tomId, javaId, jimId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
builder = PathsRequest.builder();
builder.sources().ids(markoId);
builder.targets().ids(jimId);
builder.step().direction(Direction.BOTH);
builder.nearest(true);
builder.maxDepth(6);
request = builder.build();
pathsWithVertices = pathsAPI.post(request);
paths = pathsWithVertices.paths();
Assert.assertEquals(1, paths.size());
expected = ImmutableList.of(ImmutableList.of(markoId, joshId, rippleId, tomId, javaId, jimId));
for (PathsWithVertices.Paths path : paths) {
Assert.assertTrue(expected.contains(path.objects()));
}
}
use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.
the class RingsRaysApiTest method prepareSchemaAndGraph.
@BeforeClass
public static void prepareSchemaAndGraph() {
BaseApiTest.initPropertyKey();
BaseApiTest.initVertexLabel();
BaseApiTest.initEdgeLabel();
BaseApiTest.initIndexLabel();
BaseApiTest.initVertex();
BaseApiTest.initEdge();
schema().vertexLabel("node").useCustomizeNumberId().ifNotExist().create();
schema().edgeLabel("link").sourceLabel("node").targetLabel("node").ifNotExist().create();
Vertex v1 = graph().addVertex(T.label, "node", T.id, 1);
Vertex v2 = graph().addVertex(T.label, "node", T.id, 2);
Vertex v3 = graph().addVertex(T.label, "node", T.id, 3);
// Path length 5
v1.addEdge("link", v2);
v2.addEdge("link", v3);
v3.addEdge("link", v1);
v3.addEdge("link", v2);
}
Aggregations