Search in sources :

Example 36 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project hugegraph-computer by hugegraph.

the class ClosenessCentralityTest method setup.

@BeforeClass
public static void setup() {
    clearAll();
    HugeClient client = client();
    SchemaManager schema = client.schema();
    schema.propertyKey("rate").asInt().ifNotExist().create();
    schema.vertexLabel("user").useCustomizeStringId().ifNotExist().create();
    schema.edgeLabel("link").sourceLabel("user").targetLabel("user").properties("rate").ifNotExist().create();
    GraphManager graph = client.graph();
    Vertex vA = graph.addVertex(T.label, "user", T.id, "A");
    Vertex vB = graph.addVertex(T.label, "user", T.id, "B");
    Vertex vC = graph.addVertex(T.label, "user", T.id, "C");
    Vertex vD = graph.addVertex(T.label, "user", T.id, "D");
    Vertex vE = graph.addVertex(T.label, "user", T.id, "E");
    Vertex vF = graph.addVertex(T.label, "user", T.id, "F");
    vA.addEdge("link", vB, "rate", 1);
    vB.addEdge("link", vA, "rate", 1);
    vB.addEdge("link", vC, "rate", 2);
    vC.addEdge("link", vB, "rate", 2);
    vB.addEdge("link", vD, "rate", 2);
    vD.addEdge("link", vB, "rate", 2);
    vC.addEdge("link", vD, "rate", 1);
    vD.addEdge("link", vC, "rate", 1);
    vC.addEdge("link", vE, "rate", 3);
    vE.addEdge("link", vC, "rate", 3);
    vD.addEdge("link", vE, "rate", 1);
    vE.addEdge("link", vD, "rate", 1);
    vD.addEdge("link", vF, "rate", 4);
    vF.addEdge("link", vD, "rate", 4);
    vE.addEdge("link", vF, "rate", 2);
    vF.addEdge("link", vE, "rate", 2);
}
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)

Example 37 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project hugegraph-computer by hugegraph.

the class BetweennessCentralityTest method setup.

@BeforeClass
public static void setup() {
    clearAll();
    HugeClient client = client();
    SchemaManager schema = client.schema();
    schema.vertexLabel("user").useCustomizeStringId().ifNotExist().create();
    schema.edgeLabel("link").sourceLabel("user").targetLabel("user").ifNotExist().create();
    GraphManager graph = client.graph();
    Vertex v0 = graph.addVertex(T.label, "user", T.id, "0");
    Vertex v1 = graph.addVertex(T.label, "user", T.id, "1");
    Vertex v2 = graph.addVertex(T.label, "user", T.id, "2");
    Vertex v3 = graph.addVertex(T.label, "user", T.id, "3");
    Vertex v4 = graph.addVertex(T.label, "user", T.id, "4");
    Vertex v5 = graph.addVertex(T.label, "user", T.id, "5");
    Vertex v6 = graph.addVertex(T.label, "user", T.id, "6");
    Vertex v7 = graph.addVertex(T.label, "user", T.id, "7");
    v0.addEdge("link", v1);
    v0.addEdge("link", v2);
    v1.addEdge("link", v0);
    v1.addEdge("link", v2);
    v1.addEdge("link", v5);
    v2.addEdge("link", v0);
    v2.addEdge("link", v1);
    v2.addEdge("link", v3);
    v2.addEdge("link", v4);
    v3.addEdge("link", v2);
    v3.addEdge("link", v4);
    v3.addEdge("link", v5);
    v4.addEdge("link", v2);
    v4.addEdge("link", v3);
    v4.addEdge("link", v5);
    v4.addEdge("link", v6);
    v4.addEdge("link", v7);
    v5.addEdge("link", v1);
    v5.addEdge("link", v3);
    v5.addEdge("link", v4);
    v5.addEdge("link", v6);
    v5.addEdge("link", v7);
    v6.addEdge("link", v4);
    v6.addEdge("link", v5);
    v6.addEdge("link", v7);
    v7.addEdge("link", v4);
    v7.addEdge("link", v5);
    v7.addEdge("link", v6);
}
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)

Example 38 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project hugegraph-computer by hugegraph.

the class RingsDetectionTest method setup.

@BeforeClass
public static void setup() {
    clearAll();
    HugeClient client = client();
    SchemaManager schema = client.schema();
    schema.vertexLabel("user").useCustomizeStringId().ifNotExist().create();
    schema.edgeLabel("know").sourceLabel("user").targetLabel("user").ifNotExist().create();
    GraphManager graph = client.graph();
    Vertex vA = graph.addVertex(T.label, "user", T.id, "A");
    Vertex vB = graph.addVertex(T.label, "user", T.id, "B");
    Vertex vC = graph.addVertex(T.label, "user", T.id, "C");
    Vertex vD = graph.addVertex(T.label, "user", T.id, "D");
    Vertex vE = graph.addVertex(T.label, "user", T.id, "E");
    vA.addEdge("know", vB);
    vA.addEdge("know", vC);
    vA.addEdge("know", vD);
    vB.addEdge("know", vC);
    vC.addEdge("know", vA);
    vC.addEdge("know", vE);
    vD.addEdge("know", vA);
    vD.addEdge("know", vC);
    vE.addEdge("know", vD);
    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)

Example 39 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class GraphService method addVertex.

public GraphView addVertex(int connId, VertexEntity entity) {
    HugeClient client = this.client(connId);
    Vertex vertex = this.buildVertex(connId, entity);
    vertex = client.graph().addVertex(vertex);
    return GraphView.builder().vertices(ImmutableSet.of(vertex)).edges(ImmutableSet.of()).build();
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient)

Example 40 with HugeClient

use of com.baidu.hugegraph.driver.HugeClient in project incubator-hugegraph-toolchain by apache.

the class GraphService method buildEdge.

private EdgeHolder buildEdge(int connId, EdgeEntity entity) {
    HugeClient client = this.client(connId);
    GraphManager graph = client.graph();
    EdgeLabelEntity el = this.elService.get(entity.getLabel(), connId);
    VertexLabelEntity sourceVl = this.vlService.get(el.getSourceLabel(), connId);
    VertexLabelEntity targetVl = this.vlService.get(el.getTargetLabel(), connId);
    Object realSourceId = this.convertVertexId(sourceVl.getIdStrategy(), entity.getSourceId());
    Object realTargetId = this.convertVertexId(targetVl.getIdStrategy(), entity.getTargetId());
    Vertex sourceVertex = graph.getVertex(realSourceId);
    Vertex targetVertex = graph.getVertex(realTargetId);
    Ex.check(el.getSourceLabel().equals(sourceVertex.label()) && el.getTargetLabel().equals(targetVertex.label()), "graph.edge.link-unmatched-vertex", entity.getLabel(), el.getSourceLabel(), el.getTargetLabel(), sourceVertex.label(), targetVertex.label());
    Edge edge = new Edge(entity.getLabel());
    edge.source(sourceVertex);
    edge.target(targetVertex);
    this.fillProperties(connId, el, edge, entity.getProperties());
    return new EdgeHolder(edge, sourceVertex, targetVertex);
}
Also used : EdgeLabelEntity(com.baidu.hugegraph.entity.schema.EdgeLabelEntity) Vertex(com.baidu.hugegraph.structure.graph.Vertex) HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphManager(com.baidu.hugegraph.driver.GraphManager) VertexLabelEntity(com.baidu.hugegraph.entity.schema.VertexLabelEntity) Edge(com.baidu.hugegraph.structure.graph.Edge)

Aggregations

HugeClient (com.baidu.hugegraph.driver.HugeClient)66 Vertex (com.baidu.hugegraph.structure.graph.Vertex)21 ArrayList (java.util.ArrayList)16 ExternalException (com.baidu.hugegraph.exception.ExternalException)15 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)14 ServerException (com.baidu.hugegraph.exception.ServerException)12 GraphManager (com.baidu.hugegraph.driver.GraphManager)11 Edge (com.baidu.hugegraph.structure.graph.Edge)10 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)9 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)8 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)8 Test (org.junit.Test)8 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)7 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)6 ExecuteHistory (com.baidu.hugegraph.entity.query.ExecuteHistory)4 GraphView (com.baidu.hugegraph.entity.query.GraphView)4 LoadOptions (com.baidu.hugegraph.loader.executor.LoadOptions)4 ClientException (com.baidu.hugegraph.rest.ClientException)4 BeforeClass (org.junit.BeforeClass)4 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)3