Search in sources :

Example 51 with RepositoryConnection

use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testNotDuplicateUris.

public void testNotDuplicateUris() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    URI uri2 = vf.createURI(litdupsNS, "uri1");
    URI uri3 = vf.createURI(litdupsNS, "uri1");
    conn.add(cpu, loadPerc, uri1);
    conn.add(cpu, loadPerc, uri2);
    conn.add(cpu, loadPerc, uri3);
    conn.commit();
    RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true, new Resource[0]);
    int count = 0;
    while (result.hasNext()) {
        count++;
        result.next();
    }
    result.close();
    assertEquals(1, count);
    // clean up
    conn.remove(cpu, loadPerc, uri1);
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Statement(org.openrdf.model.Statement) URI(org.openrdf.model.URI)

Example 52 with RepositoryConnection

use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testMMRTS152.

public void testMMRTS152() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "testPred");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    conn.add(cpu, loadPerc, uri1);
    conn.commit();
    RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, false, new Resource[0]);
    while (result.hasNext()) {
        assertTrue(result.hasNext());
        assertNotNull(result.next());
    }
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Statement(org.openrdf.model.Statement) URI(org.openrdf.model.URI)

Example 53 with RepositoryConnection

use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testClearAllGraph.

public void testClearAllGraph() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    String insert = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ex: <http://example/addresses#>\n" + "INSERT DATA\n" + "{ GRAPH ex:G1 {\n" + "<http://example/book3> dc:title    \"A new book\" ;\n" + "                         dc:creator  \"A.N.Other\" .\n" + "}\n" + "}";
    Update update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    insert = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "PREFIX ex: <http://example/addresses#>\n" + "INSERT DATA\n" + "{ GRAPH ex:G2 {\n" + "<http://example/book3> dc:title    \"A new book\" ;\n" + "                         dc:creator  \"A.N.Other\" .\n" + "}\n" + "}";
    update = conn.prepareUpdate(QueryLanguage.SPARQL, insert);
    update.execute();
    String query = "PREFIX dc: <http://purl.org/dc/elements/1.1/>\n" + "select * where { <http://example/book3> ?p ?o. }";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(4, tupleHandler.getCount());
    tupleHandler = new CountTupleHandler();
    conn.clear();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(0, tupleHandler.getCount());
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 54 with RepositoryConnection

use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testSymmPropOf.

public void testSymmPropOf() throws Exception {
    if (internalInferenceEngine == null) {
        // infer not supported;
        return;
    }
    RepositoryConnection conn = repository.getConnection();
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "friendOf"), RDF.TYPE, OWL.SYMMETRICPROPERTY));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "Bob"), vf.createURI(litdupsNS, "friendOf"), vf.createURI(litdupsNS, "Jeff")));
    conn.add(new StatementImpl(vf.createURI(litdupsNS, "James"), vf.createURI(litdupsNS, "friendOf"), vf.createURI(litdupsNS, "Jeff")));
    conn.commit();
    conn.close();
    internalInferenceEngine.refreshGraph();
    conn = repository.getConnection();
    String query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:friendOf lit:Bob.}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(1, tupleHandler.getCount());
    query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:friendOf lit:James.}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(1, tupleHandler.getCount());
    query = "PREFIX rdfs: <" + RDFS.NAMESPACE + ">\n" + "PREFIX rdf: <" + RDF.NAMESPACE + ">\n" + "PREFIX lit: <" + litdupsNS + ">\n" + "select * where {?s lit:friendOf lit:Jeff.}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleHandler = new CountTupleHandler();
    tupleQuery.evaluate(tupleHandler);
    assertEquals(2, tupleHandler.getCount());
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) StatementImpl(org.openrdf.model.impl.StatementImpl) TupleQuery(org.openrdf.query.TupleQuery)

Example 55 with RepositoryConnection

use of org.openrdf.repository.RepositoryConnection in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testEvaluate.

// public void testAddAuth() throws Exception {
// RepositoryConnection conn = repository.getConnection();
// URI cpu = vf.createURI(litdupsNS, "cpu");
// URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
// URI uri1 = vf.createURI(litdupsNS, "uri1");
// URI uri2 = vf.createURI(litdupsNS, "uri2");
// URI uri3 = vf.createURI(litdupsNS, "uri3");
// URI auth1 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "1");
// URI auth2 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "2");
// URI auth3 = vf.createURI(RdfCloudTripleStoreConstants.AUTH_NAMESPACE, "3");
// conn.add(cpu, loadPerc, uri1, auth1, auth2, auth3);
// conn.add(cpu, loadPerc, uri2, auth2, auth3);
// conn.add(cpu, loadPerc, uri3, auth3);
// conn.commit();
// 
// //query with no auth
// RepositoryResult<Statement> result = conn.getStatements(cpu, loadPerc, null, true);
// int count = 0;
// while (result.hasNext()) {
// count++;
// result.next();
// }
// assertEquals(0, count);
// result.close();
// 
// String query = "select * where {" +
// "<" + cpu.toString() + "> ?p ?o1." +
// "}";
// TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
// tupleQuery.setBinding(RdfCloudTripleStoreConfiguration.CONF_QUERY_AUTH, vf.createLiteral("2"));
// CountTupleHandler cth = new CountTupleHandler();
// tupleQuery.evaluate(cth);
// assertEquals(2, cth.getCount());
// 
// conn.close();
// }
public void testEvaluate() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    URI uri1 = vf.createURI(litdupsNS, "uri1");
    conn.add(cpu, loadPerc, uri1);
    conn.commit();
    String query = "select * where {" + "?x <" + loadPerc.stringValue() + "> ?o1." + "}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler cth = new CountTupleHandler();
    tupleQuery.evaluate(cth);
    assertEquals(cth.getCount(), 1);
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) TupleQuery(org.openrdf.query.TupleQuery) URI(org.openrdf.model.URI)

Aggregations

RepositoryConnection (org.openrdf.repository.RepositoryConnection)71 TupleQuery (org.openrdf.query.TupleQuery)27 URI (org.openrdf.model.URI)24 RepositoryException (org.openrdf.repository.RepositoryException)20 Test (org.junit.Test)15 Statement (org.openrdf.model.Statement)11 YardException (org.apache.stanbol.entityhub.servicesapi.yard.YardException)10 Literal (org.openrdf.model.Literal)9 RdfRepresentation (org.apache.stanbol.entityhub.model.sesame.RdfRepresentation)6 Representation (org.apache.stanbol.entityhub.servicesapi.model.Representation)6 StatementImpl (org.openrdf.model.impl.StatementImpl)6 Update (org.openrdf.query.Update)6 InputStream (java.io.InputStream)5 Value (org.openrdf.model.Value)5 Repository (org.openrdf.repository.Repository)5 SailRepository (org.openrdf.repository.sail.SailRepository)5 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)4 Resource (org.openrdf.model.Resource)4 InputStreamReader (java.io.InputStreamReader)3 SparqlFieldQuery (org.apache.stanbol.entityhub.query.sparql.SparqlFieldQuery)3