Search in sources :

Example 6 with GraphManager

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);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) BeforeClass(org.junit.BeforeClass)

Example 7 with GraphManager

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());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager)

Example 8 with GraphManager

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();
}
Also used : Path(com.baidu.hugegraph.structure.graph.Path) Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) ResultSet(com.baidu.hugegraph.structure.gremlin.ResultSet) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) GremlinManager(com.baidu.hugegraph.driver.GremlinManager) Edge(com.baidu.hugegraph.structure.graph.Edge) Result(com.baidu.hugegraph.structure.gremlin.Result)

Example 9 with GraphManager

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);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) BeforeClass(org.junit.BeforeClass)

Example 10 with GraphManager

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;
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) BeforeClass(org.junit.BeforeClass)

Aggregations

GraphManager (com.baidu.hugegraph.driver.GraphManager)16 Vertex (com.baidu.hugegraph.structure.graph.Vertex)14 HugeClient (com.baidu.hugegraph.driver.HugeClient)11 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)11 BeforeClass (org.junit.BeforeClass)8 Edge (com.baidu.hugegraph.structure.graph.Edge)4 GremlinManager (com.baidu.hugegraph.driver.GremlinManager)1 EdgeLabelEntity (com.baidu.hugegraph.entity.schema.EdgeLabelEntity)1 VertexLabelEntity (com.baidu.hugegraph.entity.schema.VertexLabelEntity)1 PathDeserializer (com.baidu.hugegraph.serializer.PathDeserializer)1 Path (com.baidu.hugegraph.structure.graph.Path)1 Result (com.baidu.hugegraph.structure.gremlin.Result)1 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)1 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)1 ArrayList (java.util.ArrayList)1