use of com.baidu.hugegraph.driver.GraphManager in project incubator-hugegraph-toolchain by apache.
the class PersonalRankApiTest method initPersonalRankGraph.
@BeforeClass
public static void initPersonalRankGraph() {
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("like").sourceLabel("person").targetLabel("movie").ifNotExist().create();
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 a = graph.addVertex(T.label, "movie", T.id, "a", "name", "a");
Vertex b = graph.addVertex(T.label, "movie", T.id, "b", "name", "b");
Vertex c = graph.addVertex(T.label, "movie", T.id, "c", "name", "c");
Vertex d = graph.addVertex(T.label, "movie", T.id, "d", "name", "d");
A.addEdge("like", a);
A.addEdge("like", c);
B.addEdge("like", a);
B.addEdge("like", b);
B.addEdge("like", c);
B.addEdge("like", d);
C.addEdge("like", c);
C.addEdge("like", d);
}
use of com.baidu.hugegraph.driver.GraphManager in project incubator-hugegraph-toolchain by apache.
the class HugeClientHttpsTest method addVertexAndCheckPropertyValue.
private void addVertexAndCheckPropertyValue() {
SchemaManager schema = client.schema();
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("city").asText().ifNotExist().create();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create();
GraphManager graph = client.graph();
Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing");
Map<String, Object> props = ImmutableMap.of("name", "marko", "age", 29, "city", "Beijing");
Assert.assertEquals(props, marko.properties());
}
use of com.baidu.hugegraph.driver.GraphManager in project incubator-hugegraph-toolchain by apache.
the class SingleExample method main.
public static void main(String[] args) throws IOException {
// If connect failed will throw a exception.
HugeClient hugeClient = HugeClient.builder("http://localhost:8080", "hugegraph").build();
SchemaManager schema = hugeClient.schema();
schema.propertyKey("name").asText().ifNotExist().create();
schema.propertyKey("age").asInt().ifNotExist().create();
schema.propertyKey("city").asText().ifNotExist().create();
schema.propertyKey("weight").asDouble().ifNotExist().create();
schema.propertyKey("lang").asText().ifNotExist().create();
schema.propertyKey("date").asDate().ifNotExist().create();
schema.propertyKey("price").asInt().ifNotExist().create();
schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").ifNotExist().create();
schema.vertexLabel("software").properties("name", "lang", "price").primaryKeys("name").ifNotExist().create();
schema.indexLabel("personByCity").onV("person").by("city").secondary().ifNotExist().create();
schema.indexLabel("personByAgeAndCity").onV("person").by("age", "city").secondary().ifNotExist().create();
schema.indexLabel("softwareByPrice").onV("software").by("price").range().ifNotExist().create();
schema.edgeLabel("knows").sourceLabel("person").targetLabel("person").properties("date", "weight").ifNotExist().create();
schema.edgeLabel("created").sourceLabel("person").targetLabel("software").properties("date", "weight").ifNotExist().create();
schema.indexLabel("createdByDate").onE("created").by("date").secondary().ifNotExist().create();
schema.indexLabel("createdByWeight").onE("created").by("weight").range().ifNotExist().create();
schema.indexLabel("knowsByWeight").onE("knows").by("weight").range().ifNotExist().create();
GraphManager graph = hugeClient.graph();
Vertex marko = graph.addVertex(T.label, "person", "name", "marko", "age", 29, "city", "Beijing");
Vertex vadas = graph.addVertex(T.label, "person", "name", "vadas", "age", 27, "city", "Hongkong");
Vertex lop = graph.addVertex(T.label, "software", "name", "lop", "lang", "java", "price", 328);
Vertex josh = graph.addVertex(T.label, "person", "name", "josh", "age", 32, "city", "Beijing");
Vertex ripple = graph.addVertex(T.label, "software", "name", "ripple", "lang", "java", "price", 199);
Vertex peter = graph.addVertex(T.label, "person", "name", "peter", "age", 35, "city", "Shanghai");
marko.addEdge("knows", vadas, "date", "2016-01-10", "weight", 0.5);
marko.addEdge("knows", josh, "date", "2013-02-20", "weight", 1.0);
marko.addEdge("created", lop, "date", "2017-12-10", "weight", 0.4);
josh.addEdge("created", lop, "date", "2009-11-11", "weight", 0.4);
josh.addEdge("created", ripple, "date", "2017-12-10", "weight", 1.0);
peter.addEdge("created", lop, "date", "2017-03-24", "weight", 0.2);
GremlinManager gremlin = hugeClient.gremlin();
System.out.println("==== Path ====");
ResultSet resultSet = gremlin.gremlin("g.V().outE().path()").execute();
Iterator<Result> results = resultSet.iterator();
results.forEachRemaining(result -> {
System.out.println(result.getObject().getClass());
Object object = result.getObject();
if (object instanceof Vertex) {
System.out.println(((Vertex) object).id());
} else if (object instanceof Edge) {
System.out.println(((Edge) object).id());
} else if (object instanceof Path) {
List<Object> elements = ((Path) object).objects();
elements.forEach(element -> {
System.out.println(element.getClass());
System.out.println(element);
});
} else {
System.out.println(object);
}
});
hugeClient.close();
}
use of com.baidu.hugegraph.driver.GraphManager in project hugegraph-computer by hugegraph.
the class TriangleCountTest method setup.
@BeforeClass
public static void setup() {
clearAll();
SchemaManager schema = client().schema();
schema.propertyKey(PROPERTY_KEY).asInt().ifNotExist().create();
schema.vertexLabel(VERTX_LABEL).properties(PROPERTY_KEY).useCustomizeStringId().ifNotExist().create();
schema.edgeLabel(EDGE_LABEL).sourceLabel(VERTX_LABEL).targetLabel(VERTX_LABEL).properties(PROPERTY_KEY).ifNotExist().create();
GraphManager graph = client().graph();
Vertex vA = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_A", PROPERTY_KEY, 1);
Vertex vB = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_B", PROPERTY_KEY, 1);
Vertex vC = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_C", PROPERTY_KEY, 1);
Vertex vD = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_D", PROPERTY_KEY, 1);
Vertex vE = graph.addVertex(T.label, VERTX_LABEL, T.id, "tc_E", PROPERTY_KEY, 1);
vA.addEdge(EDGE_LABEL, vB, PROPERTY_KEY, 1);
vA.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
vB.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
vC.addEdge(EDGE_LABEL, vD, PROPERTY_KEY, 1);
vD.addEdge(EDGE_LABEL, vA, PROPERTY_KEY, 1);
vD.addEdge(EDGE_LABEL, vE, PROPERTY_KEY, 1);
vE.addEdge(EDGE_LABEL, vD, PROPERTY_KEY, 1);
vE.addEdge(EDGE_LABEL, vC, PROPERTY_KEY, 1);
}
use of com.baidu.hugegraph.driver.GraphManager in project hugegraph-computer by hugegraph.
the class RingsDetectionWithFilterTest method setup.
@BeforeClass
public static void setup() {
clearAll();
HugeClient client = client();
SchemaManager schema = client.schema();
schema.propertyKey("weight").asInt().ifNotExist().create();
schema.vertexLabel("user").properties("weight").useCustomizeStringId().ifNotExist().create();
schema.edgeLabel("know").sourceLabel("user").targetLabel("user").properties("weight").ifNotExist().create();
GraphManager graph = client.graph();
Vertex vA = graph.addVertex(T.label, "user", T.id, "A", "weight", 1);
Vertex vB = graph.addVertex(T.label, "user", T.id, "B", "weight", 1);
Vertex vC = graph.addVertex(T.label, "user", T.id, "C", "weight", 1);
Vertex vD = graph.addVertex(T.label, "user", T.id, "D", "weight", 1);
Vertex vE = graph.addVertex(T.label, "user", T.id, "E", "weight", 3);
vA.addEdge("know", vB, "weight", 1);
vA.addEdge("know", vC, "weight", 1);
vA.addEdge("know", vD, "weight", 1);
vB.addEdge("know", vA, "weight", 2);
vB.addEdge("know", vC, "weight", 1);
vB.addEdge("know", vE, "weight", 1);
vC.addEdge("know", vA, "weight", 1);
vC.addEdge("know", vB, "weight", 1);
vC.addEdge("know", vD, "weight", 1);
vD.addEdge("know", vC, "weight", 1);
vD.addEdge("know", vE, "weight", 1);
vE.addEdge("know", vC, "weight", 1);
RingsDetectionTestOutput.EXPECT_RINGS = EXPECT_RINGS;
}
Aggregations