Search in sources :

Example 46 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class BatchInsertTest method testBatchInsertInTwoLoops.

@Test
public void testBatchInsertInTwoLoops() {
    int vertexCount = BATCH_SIZE;
    List<Vertex> persons = new ArrayList<>(BATCH_SIZE);
    List<Vertex> softwares = new ArrayList<>(BATCH_SIZE);
    List<Edge> edges = new ArrayList<>(BATCH_SIZE);
    for (int i = 1; i <= vertexCount; i++) {
        Vertex person = new Vertex("person").property("name", "P-" + i).property("age", i);
        Vertex software = new Vertex("software").property("name", "S-" + i).property("lang", "java");
        persons.add(person);
        softwares.add(software);
    }
    graph().addVertices(persons);
    graph().addVertices(softwares);
    for (int i = 0; i < vertexCount; i++) {
        Vertex person = persons.get(i);
        Vertex software = softwares.get(i);
        Edge edge = new Edge("created").source(person).target(software).property("date", "2018-12-25");
        edges.add(edge);
    }
    graph().addEdges(edges);
    Assert.assertEquals(2 * BATCH_SIZE, graph().listVertices(-1).size());
    Assert.assertEquals(BATCH_SIZE, graph().listEdges(-1).size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) ArrayList(java.util.ArrayList) Edge(com.baidu.hugegraph.structure.graph.Edge) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Example 47 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex 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 48 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class WeightedShortestPathApiTest method testWeightedShortestPathWithVertex.

@Test
public void testWeightedShortestPathWithVertex() {
    WeightedPath weightedPath = weightedShortestPathAPI.get("A", "Z", Direction.BOTH, null, "weight", -1, 0, -1, true);
    Assert.assertEquals(5, weightedPath.vertices().size());
    List<Object> expected = ImmutableList.of("A", "H", "I", "J", "Z");
    for (Vertex vertex : weightedPath.vertices()) {
        Assert.assertTrue(expected.contains(vertex.id()));
    }
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) WeightedPath(com.baidu.hugegraph.structure.traverser.WeightedPath) Test(org.junit.Test)

Example 49 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class WeightedShortestPathApiTest method initShortestPathGraph.

@BeforeClass
public static void initShortestPathGraph() {
    schema().propertyKey("weight").asDouble().ifNotExist().create();
    schema().vertexLabel("node").useCustomizeStringId().ifNotExist().create();
    schema().edgeLabel("link").sourceLabel("node").targetLabel("node").properties("weight").ifNotExist().create();
    schema().edgeLabel("relateTo").sourceLabel("node").targetLabel("node").properties("weight").ifNotExist().create();
    Vertex va = graph().addVertex(T.label, "node", T.id, "A");
    Vertex vb = graph().addVertex(T.label, "node", T.id, "B");
    Vertex vc = graph().addVertex(T.label, "node", T.id, "C");
    Vertex vd = graph().addVertex(T.label, "node", T.id, "D");
    Vertex ve = graph().addVertex(T.label, "node", T.id, "E");
    Vertex vf = graph().addVertex(T.label, "node", T.id, "F");
    Vertex vg = graph().addVertex(T.label, "node", T.id, "G");
    Vertex vh = graph().addVertex(T.label, "node", T.id, "H");
    Vertex vi = graph().addVertex(T.label, "node", T.id, "I");
    Vertex vj = graph().addVertex(T.label, "node", T.id, "J");
    Vertex vk = graph().addVertex(T.label, "node", T.id, "K");
    Vertex vl = graph().addVertex(T.label, "node", T.id, "L");
    Vertex vm = graph().addVertex(T.label, "node", T.id, "M");
    Vertex vn = graph().addVertex(T.label, "node", T.id, "N");
    Vertex vo = graph().addVertex(T.label, "node", T.id, "O");
    Vertex vp = graph().addVertex(T.label, "node", T.id, "P");
    Vertex vq = graph().addVertex(T.label, "node", T.id, "Q");
    Vertex vr = graph().addVertex(T.label, "node", T.id, "R");
    Vertex vz = graph().addVertex(T.label, "node", T.id, "Z");
    /*
         *   "link":
         *   A --0.2--> B --0.4--> C --0.8--> D --0.6--> Z
         *     ----------------10---------------------->
         *     <--0.5-- E <--0.3-- F <--0.4-- G <--0.1--
         *     <-------------------8--------------------
         *     --0.1--> H --0.1--> I <--0.1-- J <--0.2--
         *     -----0.4----> K -----0.5-----> L <--0.3--
         *   "relateTo":
         *     -----1.4-----> M -----3.8----> N --3.5-->
         *     <----2.2------ O <----3.3----- P <-1.6---
         *     -----3.1-----> Q <----2.0----- R --1.3-->
         */
    va.addEdge("link", vb, "weight", 0.2D);
    vb.addEdge("link", vc, "weight", 0.4D);
    vc.addEdge("link", vd, "weight", 0.8D);
    vd.addEdge("link", vz, "weight", 0.6D);
    va.addEdge("link", vz, "weight", 10.0D);
    vz.addEdge("link", vg, "weight", 0.1D);
    vg.addEdge("link", vf, "weight", 0.4D);
    vf.addEdge("link", ve, "weight", 0.3D);
    ve.addEdge("link", va, "weight", 0.5D);
    vz.addEdge("link", va, "weight", 8.0D);
    va.addEdge("link", vh, "weight", 0.1D);
    vh.addEdge("link", vi, "weight", 0.1D);
    vz.addEdge("link", vj, "weight", 0.2D);
    vj.addEdge("link", vi, "weight", 0.1D);
    va.addEdge("link", vk, "weight", 0.4D);
    vk.addEdge("link", vl, "weight", 0.5D);
    vz.addEdge("link", vl, "weight", 0.3D);
    va.addEdge("relateTo", vm, "weight", 1.4D);
    vm.addEdge("relateTo", vn, "weight", 3.8D);
    vn.addEdge("relateTo", vz, "weight", 3.5D);
    vz.addEdge("relateTo", vp, "weight", 1.6D);
    vp.addEdge("relateTo", vo, "weight", 3.3D);
    vo.addEdge("relateTo", va, "weight", 2.2D);
    va.addEdge("relateTo", vq, "weight", 3.1D);
    vr.addEdge("relateTo", vq, "weight", 2.0D);
    vr.addEdge("relateTo", vz, "weight", 1.3D);
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) BeforeClass(org.junit.BeforeClass)

Example 50 with Vertex

use of com.baidu.hugegraph.structure.graph.Vertex in project incubator-hugegraph-toolchain by apache.

the class TraverserManagerTest method testIterateVerticesByShard.

@Test
public void testIterateVerticesByShard() {
    List<Shard> shards = traverser().vertexShards(1 * 1024 * 1024);
    List<Vertex> vertices = new LinkedList<>();
    for (Shard shard : shards) {
        Iterator<Vertex> iter = traverser().iteratorVertices(shard, 1);
        while (iter.hasNext()) {
            vertices.add(iter.next());
        }
    }
    Assert.assertEquals(6, vertices.size());
}
Also used : Vertex(com.baidu.hugegraph.structure.graph.Vertex) Shard(com.baidu.hugegraph.structure.graph.Shard) LinkedList(java.util.LinkedList) Test(org.junit.Test) BaseClientTest(com.baidu.hugegraph.BaseClientTest)

Aggregations

Vertex (com.baidu.hugegraph.structure.graph.Vertex)165 Test (org.junit.Test)110 Edge (com.baidu.hugegraph.structure.graph.Edge)33 HugeClient (com.baidu.hugegraph.driver.HugeClient)22 ArrayList (java.util.ArrayList)21 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)18 BaseClientTest (com.baidu.hugegraph.BaseClientTest)17 BeforeClass (org.junit.BeforeClass)17 GraphManager (com.baidu.hugegraph.driver.GraphManager)14 BatchVertexRequest (com.baidu.hugegraph.structure.graph.BatchVertexRequest)13 Path (com.baidu.hugegraph.structure.graph.Path)11 Result (com.baidu.hugegraph.structure.gremlin.Result)10 ResultSet (com.baidu.hugegraph.structure.gremlin.ResultSet)10 List (java.util.List)10 BaseApiTest (com.baidu.hugegraph.api.BaseApiTest)9 ImmutableList (com.google.common.collect.ImmutableList)6 ImmutableMap (com.google.common.collect.ImmutableMap)6 Map (java.util.Map)6 RestResult (com.baidu.hugegraph.rest.RestResult)5 PathsWithVertices (com.baidu.hugegraph.structure.traverser.PathsWithVertices)5