Search in sources :

Example 46 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class SailLoaderTest method testAll.

@Test
public void testAll() throws Exception {
    KeyIndexableGraph g = new TinkerGraph();
    Sail sail = new GraphSail(g);
    sail.initialize();
    try {
        SailLoader loader = new SailLoader(sail);
        File f = resourceToFile("graph-example-sail-test.trig");
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            assertEquals(0, sc.size());
            loader.load(f);
            sc.rollback();
            assertEquals(29, sc.size());
        } finally {
            sc.close();
        }
    } finally {
        sail.shutDown();
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Sail(org.openrdf.sail.Sail) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) File(java.io.File) Test(org.junit.Test)

Example 47 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class GraphJungTest method testTinkerGraph.

public void testTinkerGraph() {
    GraphJung<TinkerGraph> jung = new GraphJung<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    assertEquals(jung.getVertices().size(), 6);
    assertEquals(jung.getEdges().size(), 6);
    assertEquals(jung.getVertexCount(), 6);
    assertEquals(jung.getEdgeCount(), 6);
    Vertex marko = null;
    Vertex josh = null;
    Vertex vadas = null;
    for (Vertex vertex : jung.getVertices()) {
        assertTrue(jung.containsVertex(vertex));
        for (Edge edge : jung.getOutEdges(vertex)) {
            assertEquals(jung.getSource(edge), vertex);
        }
        for (Edge edge : jung.getInEdges(vertex)) {
            assertEquals(jung.getDest(edge), vertex);
        }
        if (vertex.getId().equals("1")) {
            marko = vertex;
            assertEquals(jung.getOutEdges(vertex).size(), 3);
            assertEquals(jung.getInEdges(vertex).size(), 0);
            assertEquals(jung.getNeighborCount(vertex), 3);
            int count = 0;
            for (Vertex vertex2 : jung.getNeighbors(vertex)) {
                if (vertex2.getId().equals("2"))
                    count++;
                else if (vertex2.getId().equals("4"))
                    count++;
                else if (vertex2.getId().equals("3"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(count, 3);
            assertEquals(jung.getSuccessorCount(vertex), 3);
            count = 0;
            for (Vertex vertex2 : jung.getSuccessors(vertex)) {
                if (vertex2.getId().equals("2"))
                    count++;
                else if (vertex2.getId().equals("4"))
                    count++;
                else if (vertex2.getId().equals("3"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(jung.getPredecessorCount(vertex), 0);
        } else if (vertex.getId().equals("2")) {
            vadas = vertex;
            assertEquals(jung.getOutEdges(vertex).size(), 0);
            assertEquals(jung.getInEdges(vertex).size(), 1);
            assertEquals(jung.getNeighborCount(vertex), 1);
            int count = 0;
            for (Vertex vertex2 : jung.getNeighbors(vertex)) {
                if (vertex2.getId().equals("1"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(count, 1);
            assertEquals(jung.getSuccessorCount(vertex), 0);
            assertEquals(jung.getPredecessorCount(vertex), 1);
            count = 0;
            for (Vertex vertex2 : jung.getPredecessors(vertex)) {
                if (vertex2.getId().equals("1"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(count, 1);
        } else if (vertex.getId().equals("4")) {
            josh = vertex;
            assertEquals(jung.getOutEdges(vertex).size(), 2);
            assertEquals(jung.getInEdges(vertex).size(), 1);
            assertEquals(jung.getNeighborCount(vertex), 3);
            int count = 0;
            for (Vertex vertex2 : jung.getNeighbors(vertex)) {
                if (vertex2.getId().equals("1"))
                    count++;
                else if (vertex2.getId().equals("3"))
                    count++;
                else if (vertex2.getId().equals("5"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(count, 3);
            assertEquals(jung.getSuccessorCount(vertex), 2);
            count = 0;
            for (Vertex vertex2 : jung.getSuccessors(vertex)) {
                if (vertex2.getId().equals("3"))
                    count++;
                else if (vertex2.getId().equals("5"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(count, 2);
            assertEquals(jung.getPredecessorCount(vertex), 1);
            count = 0;
            for (Vertex vertex2 : jung.getPredecessors(vertex)) {
                if (vertex2.getId().equals("1"))
                    count++;
                else
                    assertTrue(false);
            }
            assertEquals(count, 1);
        }
    }
    assertTrue(null != marko);
    assertTrue(null != vadas);
    assertTrue(null != josh);
    assertEquals(jung.findEdgeSet(marko, josh).size(), 1);
    assertTrue(jung.findEdgeSet(marko, josh).contains(jung.findEdge(marko, josh)));
    assertEquals(jung.getDefaultEdgeType(), EdgeType.DIRECTED);
    for (Edge edge : jung.getEdges()) {
        assertTrue(jung.containsEdge(edge));
        assertEquals(jung.getEdgeType(edge), EdgeType.DIRECTED);
        assertEquals(jung.getIncidentCount(edge), 2);
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) GraphJung(com.tinkerpop.blueprints.oupls.jung.GraphJung) Edge(com.tinkerpop.blueprints.Edge)

Example 48 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class ReadOnlyGraphTest method testWrappedElementUniqueness.

public void testWrappedElementUniqueness() {
    Graph graph = new ReadOnlyGraph<TinkerGraph>(TinkerGraphFactory.createTinkerGraph());
    assertEquals(graph.getVertex(1), graph.getVertex(1));
    Set<Vertex> set = new HashSet<Vertex>();
    set.add(graph.getVertex(2));
    set.add(graph.getVertex(2));
    assertEquals(set.size(), 1);
    assertEquals(graph.getEdge(7).hashCode(), graph.getEdge(7).hashCode());
    assertEquals(graph.getEdge(8), graph.getEdge(8));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) WrapperGraph(com.tinkerpop.blueprints.util.wrappers.WrapperGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) IndexableGraph(com.tinkerpop.blueprints.IndexableGraph) Graph(com.tinkerpop.blueprints.Graph) HashSet(java.util.HashSet)

Example 49 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project blueprints by tinkerpop.

the class TinkerGraphSailTest method testTmp.

@Test
public void testTmp() throws Exception {
    KeyIndexableGraph g = new TinkerGraph();
    GraphSail sail = new GraphSail(g, "sp,p,c,pc");
}
Also used : TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) Test(org.junit.Test)

Example 50 with TinkerGraph

use of com.tinkerpop.blueprints.impls.tg.TinkerGraph in project frames by tinkerpop.

the class TypedGraphModuleTest method testDeserializeEdgeType.

public void testDeserializeEdgeType() {
    Graph graph = new TinkerGraph();
    FramedGraphFactory factory = new FramedGraphFactory(new TypedGraphModuleBuilder().withClass(A.class).withClass(B.class).withClass(C.class).build());
    FramedGraph<Graph> framedGraph = factory.create(graph);
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    Edge cE = graph.addEdge(null, v1, v2, "label");
    cE.setProperty("type", "C");
    Base c = framedGraph.getEdge(cE.getId(), Direction.OUT, Base.class);
    assertTrue(c instanceof C);
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) TypedGraphModuleBuilder(com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder) Edge(com.tinkerpop.blueprints.Edge)

Aggregations

TinkerGraph (com.tinkerpop.blueprints.impls.tg.TinkerGraph)105 Vertex (com.tinkerpop.blueprints.Vertex)66 Graph (com.tinkerpop.blueprints.Graph)58 Test (org.junit.Test)42 Edge (com.tinkerpop.blueprints.Edge)33 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 ByteArrayInputStream (java.io.ByteArrayInputStream)11 JSONObject (org.codehaus.jettison.json.JSONObject)10 IMetaverseBuilder (org.pentaho.metaverse.api.IMetaverseBuilder)10 InputStream (java.io.InputStream)9 HashSet (java.util.HashSet)9 JSONTokener (org.codehaus.jettison.json.JSONTokener)8 KeyIndexableGraph (com.tinkerpop.blueprints.KeyIndexableGraph)7 Map (java.util.Map)6 MetaverseBuilder (org.pentaho.metaverse.impl.MetaverseBuilder)6 TypedGraphModuleBuilder (com.tinkerpop.frames.modules.typedgraph.TypedGraphModuleBuilder)5 HashMap (java.util.HashMap)5 Before (org.junit.Before)5 IndexableGraph (com.tinkerpop.blueprints.IndexableGraph)4 IgnoreIdTinkerGraph (com.tinkerpop.blueprints.impls.tg.IgnoreIdTinkerGraph)4