Search in sources :

Example 41 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class GraphSailTest method testBlankNodesUnique.

@Test
public void testBlankNodesUnique() throws Exception {
    String ex = "http://example.org/ns#";
    URI class1 = new URIImpl(ex + "Class1");
    clear();
    int edgesBefore, verticesBefore;
    SailConnection sc = sail.getConnection();
    try {
        sc.begin();
        edgesBefore = countEdges();
        verticesBefore = countVertices();
    } finally {
        sc.rollback();
        sc.close();
    }
    // Load a file once.
    addFile(SailTest.class.getResourceAsStream("graph-example-bnodes.trig"), RDFFormat.TRIG);
    sc = sail.getConnection();
    try {
        assertEquals(3, countStatements(sc, class1, RDFS.SUBCLASSOF, null, false));
        assertEquals(edgesBefore + 14, countEdges());
        assertEquals(verticesBefore + 10, countVertices());
    } finally {
        sc.rollback();
        sc.close();
    }
    // Load the file again.
    // Loading the same file twice results in extra vertices and edges,
    // since blank nodes assume different identities on each load.
    addFile(SailTest.class.getResourceAsStream("graph-example-bnodes.trig"), RDFFormat.TRIG);
    sc = sail.getConnection();
    try {
        assertEquals(5, countStatements(sc, class1, RDFS.SUBCLASSOF, null, false));
        assertEquals(edgesBefore + 23, countEdges());
        assertEquals(verticesBefore + 12, countVertices());
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : SailConnection(org.openrdf.sail.SailConnection) URIImpl(org.openrdf.model.impl.URIImpl) URI(org.openrdf.model.URI) Test(org.junit.Test)

Example 42 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class GraphSailTest method getGetVertex.

@Test
public void getGetVertex() throws Exception {
    GraphSail gSail = (GraphSail) sail;
    SailConnection sc = gSail.getConnection();
    try {
        sc.begin();
        Vertex type = gSail.getVertex(RDF.TYPE);
        assertNull(type);
        sc.addStatement(RDF.TYPE, RDFS.LABEL, new LiteralImpl("type"));
        type = gSail.getVertex(RDF.TYPE);
        assertNotNull(type);
        assertEquals(RDF.TYPE.stringValue(), type.getProperty(GraphSail.VALUE));
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) LiteralImpl(org.openrdf.model.impl.LiteralImpl) SailConnection(org.openrdf.sail.SailConnection) Test(org.junit.Test)

Example 43 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class GraphSailTest method testCodePlay.

@Test
public void testCodePlay() throws Exception {
    Sail sail = new GraphSail(new TinkerGraph());
    sail.initialize();
    try {
        SailConnection sc = sail.getConnection();
        try {
            sc.begin();
            ValueFactory vf = sail.getValueFactory();
            sc.addStatement(vf.createURI("http://tinkerpop.com#1"), vf.createURI("http://tinkerpop.com#knows"), vf.createURI("http://tinkerpop.com#3"), vf.createURI("http://tinkerpop.com"));
            sc.addStatement(vf.createURI("http://tinkerpop.com#1"), vf.createURI("http://tinkerpop.com#name"), vf.createLiteral("marko"), vf.createURI("http://tinkerpop.com"));
            sc.addStatement(vf.createURI("http://tinkerpop.com#3"), vf.createURI("http://tinkerpop.com#name"), vf.createLiteral("josh"), vf.createURI("http://tinkerpop.com"));
            CloseableIteration<? extends Statement, SailException> results = sc.getStatements(null, null, null, false);
            try {
                System.out.println("get statements: ?s ?p ?o ?g");
                while (results.hasNext()) {
                    System.out.println(results.next());
                }
            } finally {
                results.close();
            }
            System.out.println("\nget statements: http://tinkerpop.com#3 ?p ?o ?g");
            results = sc.getStatements(vf.createURI("http://tinkerpop.com#3"), null, null, false);
            try {
                while (results.hasNext()) {
                    System.out.println(results.next());
                }
            } finally {
                results.close();
            }
            SPARQLParser parser = new SPARQLParser();
            CloseableIteration<? extends BindingSet, QueryEvaluationException> sparqlResults;
            String queryString = "SELECT ?x ?y WHERE { ?x <http://tinkerpop.com#knows> ?y }";
            ParsedQuery query = parser.parseQuery(queryString, "http://tinkerPop.com");
            System.out.println("\nSPARQL: " + queryString);
            sparqlResults = sc.evaluate(query.getTupleExpr(), query.getDataset(), new EmptyBindingSet(), false);
            try {
                while (sparqlResults.hasNext()) {
                    System.out.println(sparqlResults.next());
                }
            } finally {
                sparqlResults.close();
            }
            Graph graph = ((GraphSail) sail).getBaseGraph();
            System.out.println();
            for (Vertex v : graph.getVertices()) {
                System.out.println("------");
                System.out.println(v);
                for (String key : v.getPropertyKeys()) {
                    System.out.println(key + "=" + v.getProperty(key));
                }
            }
            for (Edge e : graph.getEdges()) {
                System.out.println("------");
                System.out.println(e);
                for (String key : e.getPropertyKeys()) {
                    System.out.println(key + "=" + e.getProperty(key));
                }
            }
        } finally {
            sc.rollback();
            sc.close();
        }
    } finally {
        sail.shutDown();
    }
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) SPARQLParser(org.openrdf.query.parser.sparql.SPARQLParser) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) ParsedQuery(org.openrdf.query.parser.ParsedQuery) ValueFactory(org.openrdf.model.ValueFactory) SailException(org.openrdf.sail.SailException) EmptyBindingSet(org.openrdf.query.impl.EmptyBindingSet) SailConnection(org.openrdf.sail.SailConnection) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) KeyIndexableGraph(com.tinkerpop.blueprints.KeyIndexableGraph) QueryEvaluationException(org.openrdf.query.QueryEvaluationException) Sail(org.openrdf.sail.Sail) Edge(com.tinkerpop.blueprints.Edge) Test(org.junit.Test)

Example 44 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class SailTest method testClearNamespaces.

// namespaces //////////////////////////////////////////////////////////////
@Test
public void testClearNamespaces() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        CloseableIteration<? extends Namespace, SailException> namespaces;
        int count;
        count = 0;
        namespaces = sc.getNamespaces();
        while (namespaces.hasNext()) {
            namespaces.next();
            count++;
        }
        namespaces.close();
        assertTrue(count > 0);
    // TODO: actually clear namespaces (but this wipes them out for
    // subsequent tests)
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) SailException(org.openrdf.sail.SailException) Test(org.junit.Test)

Example 45 with SailConnection

use of org.openrdf.sail.SailConnection in project blueprints by tinkerpop.

the class SailTest method testGetNamespace.

@Test
public void testGetNamespace() throws Exception {
    SailConnection sc = sail.getConnection();
    try {
        // FIXME: temporary
        //sc.setNamespace("foo", "http://example.org/foo/");
        //showNamespaces(sc);
        String name;
        name = sc.getNamespace("bogus");
        assertNull(name);
        // assertEquals(name, "http://www.w3.org/1999/02/22-rdf-syntax-ns#");
        name = sc.getNamespace("rdfs");
        //sc.commit();
        assertEquals(name, "http://www.w3.org/2000/01/rdf-schema#");
    } finally {
        sc.rollback();
        sc.close();
    }
}
Also used : NotifyingSailConnection(org.openrdf.sail.NotifyingSailConnection) SailConnection(org.openrdf.sail.SailConnection) Test(org.junit.Test)

Aggregations

SailConnection (org.openrdf.sail.SailConnection)55 Test (org.junit.Test)34 NotifyingSailConnection (org.openrdf.sail.NotifyingSailConnection)28 URI (org.openrdf.model.URI)25 SailException (org.openrdf.sail.SailException)14 Sail (org.openrdf.sail.Sail)10 ValueFactory (org.openrdf.model.ValueFactory)9 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)8 AccumuloRdfConfiguration (org.apache.rya.accumulo.AccumuloRdfConfiguration)5 RyaClient (org.apache.rya.api.client.RyaClient)5 Literal (org.openrdf.model.Literal)5 Resource (org.openrdf.model.Resource)5 Statement (org.openrdf.model.Statement)5 ParsedQuery (org.openrdf.query.parser.ParsedQuery)5 SPARQLParser (org.openrdf.query.parser.sparql.SPARQLParser)5 URIImpl (org.openrdf.model.impl.URIImpl)4 BindingSet (org.openrdf.query.BindingSet)4 Vertex (com.tinkerpop.blueprints.Vertex)3 EmptyBindingSet (org.openrdf.query.impl.EmptyBindingSet)3 RDFHandlerException (org.openrdf.rio.RDFHandlerException)3