Search in sources :

Example 51 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class GraphMLReaderTestSuite method testReadingTinkerGraphExample3MappingIDs.

public void testReadingTinkerGraphExample3MappingIDs() throws Exception {
    Graph graph = this.graphTest.generateGraph();
    if (graph.getFeatures().supportsEdgeIteration && graph.getFeatures().supportsVertexIteration) {
        this.stopWatch();
        GraphMLReader r = new GraphMLReader(graph);
        r.setVertexIdKey("_id");
        r.setEdgeIdKey("_id");
        r.inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-3.xml"), 1000);
        printPerformance(graph.toString(), null, "graph-example-3 loaded", this.stopWatch());
        Set<String> vertexIds = new HashSet<String>();
        Set<String> vertexKeys = new HashSet<String>();
        Set<String> vertexNames = new HashSet<String>();
        int vertexCount = 0;
        for (Vertex v : graph.getVertices()) {
            vertexCount++;
            vertexIds.add(v.getId().toString());
            vertexNames.add(v.getProperty("name").toString());
            for (String key : v.getPropertyKeys()) vertexKeys.add(key);
        }
        Set<String> edgeIds = new HashSet<String>();
        Set<String> edgeKeys = new HashSet<String>();
        Set<String> edgeLabels = new HashSet<String>();
        int edgeCount = 0;
        for (Edge e : graph.getEdges()) {
            edgeCount++;
            edgeIds.add(e.getId().toString());
            edgeLabels.add(e.getLabel());
            for (String key : e.getPropertyKeys()) edgeKeys.add(key);
        }
        assertEquals(vertexCount, 6);
        assertEquals(vertexIds.size(), 6);
        assertEquals(vertexKeys.contains("name"), true);
        assertEquals(vertexKeys.contains("age"), true);
        assertEquals(vertexKeys.contains("lang"), true);
        assertEquals(vertexKeys.contains("_id"), false);
        assertEquals(vertexKeys.size(), 3);
        assertTrue(vertexNames.contains("marko"));
        assertTrue(vertexNames.contains("josh"));
        assertTrue(vertexNames.contains("peter"));
        assertTrue(vertexNames.contains("vadas"));
        assertTrue(vertexNames.contains("ripple"));
        assertTrue(vertexNames.contains("lop"));
        assertEquals(edgeCount, 6);
        assertEquals(edgeIds.size(), 6);
        assertEquals(edgeKeys.contains("weight"), true);
        assertEquals(edgeKeys.contains("_id"), false);
        assertEquals(edgeKeys.contains("_label"), true);
        assertEquals(edgeKeys.size(), 2);
        assertEquals(edgeLabels.size(), 2);
        assertEquals(edgeLabels.contains("has high fived"), false);
        assertEquals(edgeLabels.contains("knows"), true);
        assertEquals(edgeLabels.contains("created"), true);
    }
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge) HashSet(java.util.HashSet)

Example 52 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class GraphMLReaderTestSuite method testReadingTinkerGraphExample3MappingAll.

public void testReadingTinkerGraphExample3MappingAll() throws Exception {
    Graph graph = this.graphTest.generateGraph();
    if (graph.getFeatures().supportsEdgeIteration && graph.getFeatures().supportsVertexIteration) {
        this.stopWatch();
        GraphMLReader r = new GraphMLReader(graph);
        r.setVertexIdKey("_id");
        r.setEdgeIdKey("_id");
        r.setEdgeLabelKey("_label");
        r.inputGraph(GraphMLReader.class.getResourceAsStream("graph-example-3.xml"), 1000);
        printPerformance(graph.toString(), null, "graph-example-3 loaded", this.stopWatch());
        Set<String> vertexIds = new HashSet<String>();
        Set<String> vertexKeys = new HashSet<String>();
        Set<String> vertexNames = new HashSet<String>();
        int vertexCount = 0;
        for (Vertex v : graph.getVertices()) {
            vertexCount++;
            vertexIds.add(v.getId().toString());
            vertexNames.add(v.getProperty("name").toString());
            for (String key : v.getPropertyKeys()) vertexKeys.add(key);
        }
        Set<String> edgeIds = new HashSet<String>();
        Set<String> edgeKeys = new HashSet<String>();
        Set<String> edgeLabels = new HashSet<String>();
        int edgeCount = 0;
        for (Edge e : graph.getEdges()) {
            edgeCount++;
            edgeIds.add(e.getId().toString());
            edgeLabels.add(e.getLabel());
            for (String key : e.getPropertyKeys()) edgeKeys.add(key);
        }
        assertEquals(vertexCount, 6);
        assertEquals(vertexIds.size(), 6);
        assertEquals(vertexKeys.contains("name"), true);
        assertEquals(vertexKeys.contains("age"), true);
        assertEquals(vertexKeys.contains("lang"), true);
        assertEquals(vertexKeys.contains("_id"), false);
        assertEquals(vertexKeys.size(), 3);
        assertTrue(vertexNames.contains("marko"));
        assertTrue(vertexNames.contains("josh"));
        assertTrue(vertexNames.contains("peter"));
        assertTrue(vertexNames.contains("vadas"));
        assertTrue(vertexNames.contains("ripple"));
        assertTrue(vertexNames.contains("lop"));
        assertEquals(edgeCount, 6);
        assertEquals(edgeIds.size(), 6);
        assertEquals(edgeKeys.contains("weight"), true);
        assertEquals(edgeKeys.contains("_id"), false);
        assertEquals(edgeKeys.contains("_label"), false);
        assertEquals(edgeKeys.size(), 1);
        assertEquals(edgeLabels.size(), 2);
        assertEquals(edgeLabels.contains("has high fived"), true);
        assertEquals(edgeLabels.contains("knows"), false);
        assertEquals(edgeLabels.contains("created"), true);
    }
    graph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge) HashSet(java.util.HashSet)

Example 53 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class BatchGraphTest method loadingTest.

public void loadingTest(int total, int bufferSize, VertexIDType type, LoadingFactory ids) {
    final VertexEdgeCounter counter = new VertexEdgeCounter();
    MockTransactionalGraph tgraph = null;
    if (ignoreIDs) {
        tgraph = new MockTransactionalGraph(new IgnoreIdTinkerGraph());
    } else {
        tgraph = new MockTransactionalGraph(new TinkerGraph());
    }
    BLGraph graph = new BLGraph(tgraph, counter, ids);
    BatchGraph<BLGraph> loader = new BatchGraph<BLGraph>(graph, type, bufferSize);
    if (assignKeys) {
        loader.setVertexIdKey(vertexIDKey);
        loader.setEdgeIdKey(edgeIDKey);
    }
    // Create a chain
    int chainLength = total;
    Vertex previous = null;
    for (int i = 0; i <= chainLength; i++) {
        Vertex next = loader.addVertex(ids.getVertexID(i));
        next.setProperty(UID, i);
        counter.numVertices++;
        counter.totalVertices++;
        if (previous != null) {
            Edge e = loader.addEdge(ids.getEdgeID(i), loader.getVertex(previous.getId()), loader.getVertex(next.getId()), "next");
            e.setProperty(UID, i);
            counter.numEdges++;
        }
        previous = next;
    }
    loader.stopTransaction(TransactionalGraph.Conclusion.SUCCESS);
    assertTrue(tgraph.allSuccessful());
    loader.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 54 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class BatchGraphTest method testQuadLoading.

public void testQuadLoading() {
    int numEdges = 10000;
    String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
    TinkerGraph graph = new TinkerGraph();
    BatchGraph bgraph = new BatchGraph(new WritethroughGraph(graph), VertexIDType.STRING, 1000);
    for (String[] quad : quads) {
        Vertex[] vertices = new Vertex[2];
        for (int i = 0; i < 2; i++) {
            vertices[i] = bgraph.getVertex(quad[i]);
            if (vertices[i] == null)
                vertices[i] = bgraph.addVertex(quad[i]);
        }
        Edge edge = bgraph.addEdge(null, vertices[0], vertices[1], quad[2]);
        edge.setProperty("annotation", quad[3]);
    }
    assertEquals(numEdges, BaseTest.count(graph.getEdges()));
    bgraph.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Edge(com.tinkerpop.blueprints.Edge)

Example 55 with Edge

use of com.tinkerpop.blueprints.Edge in project blueprints by tinkerpop.

the class BatchGraphTest method testLoadingWithExisting2.

public void testLoadingWithExisting2() {
    int numEdges = 1000;
    String[][] quads = generateQuads(100, numEdges, new String[] { "knows", "friend" });
    TinkerGraph tg = new IgnoreIdTinkerGraph();
    BatchGraph bg = new BatchGraph(new WritethroughGraph(tg), VertexIDType.STRING, 100);
    try {
        bg.setLoadingFromScratch(false);
        fail();
    } catch (IllegalStateException e) {
    }
    bg.setVertexIdKey("uid");
    bg.setLoadingFromScratch(false);
    try {
        bg.setVertexIdKey(null);
        fail();
    } catch (IllegalStateException e) {
    }
    Graph graph = null;
    int counter = 0;
    for (String[] quad : quads) {
        if (counter < numEdges / 2)
            graph = tg;
        else
            graph = bg;
        Vertex[] vertices = new Vertex[2];
        for (int i = 0; i < 2; i++) {
            vertices[i] = graph.getVertex(quad[i]);
            if (vertices[i] == null)
                vertices[i] = graph.addVertex(quad[i]);
        }
        Edge edge = graph.addEdge(null, vertices[0], vertices[1], quad[2]);
        edge.setProperty("annotation", quad[3]);
        counter++;
    }
    assertEquals(numEdges, BaseTest.count(tg.getEdges()));
    bg.shutdown();
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) TransactionalGraph(com.tinkerpop.blueprints.TransactionalGraph) IgnoreIdTinkerGraph(com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph) MockTransactionalGraph(com.tinkerpop.blueprints.impls.tg.MockTransactionalGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

Edge (com.tinkerpop.blueprints.Edge)214 Vertex (com.tinkerpop.blueprints.Vertex)141 Test (org.junit.Test)53 Graph (com.tinkerpop.blueprints.Graph)49 TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)49 HashSet (java.util.HashSet)28 OrientVertex (com.tinkerpop.blueprints.impls.orient.OrientVertex)13 ArrayList (java.util.ArrayList)13 Collection (java.util.Collection)11 JSONObject (org.codehaus.jettison.json.JSONObject)11 HashMap (java.util.HashMap)10 OrientEdge (com.tinkerpop.blueprints.impls.orient.OrientEdge)9 OrientGraph (com.tinkerpop.blueprints.impls.orient.OrientGraph)9 OCommandSQL (com.orientechnologies.orient.core.sql.OCommandSQL)8 Map (java.util.Map)8 OrientBaseGraph (com.tinkerpop.blueprints.impls.orient.OrientBaseGraph)7 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)6 OSQLSynchQuery (com.orientechnologies.orient.core.sql.query.OSQLSynchQuery)6 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)6 URI (org.openrdf.model.URI)6