Search in sources :

Example 11 with RepositoryConnection

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

the class ArbitraryLengthQueryTest method load.

/**
 * Load the t-box and a-box turtle from strings defined within this class.
 *
 * @throws RepositoryException
 * @throws RDFParseException
 * @throws IOException
 */
private void load() throws RepositoryException, RDFParseException, IOException {
    final RepositoryConnection conn = repository.getConnection();
    // T-Box
    String ttlString = MODEL_TTL;
    InputStream stringInput = new ByteArrayInputStream(ttlString.getBytes());
    conn.add(stringInput, "http://dragon-research.com/cham/model/model1", RDFFormat.TURTLE, new Resource[] {});
    // A-Box
    ttlString = BUCKET_TTL;
    stringInput = new ByteArrayInputStream(ttlString.getBytes());
    conn.add(stringInput, "http://dragon-research.com/cham/bucket/bucket1", RDFFormat.TURTLE, new Resource[] {});
    conn.commit();
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 12 with RepositoryConnection

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

the class RdfCloudTripleStoreConnectionTest method testDuplicateLiterals.

public void testDuplicateLiterals() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc");
    Literal lit1 = vf.createLiteral(0.0);
    Literal lit2 = vf.createLiteral(0.0);
    Literal lit3 = vf.createLiteral(0.0);
    conn.add(cpu, loadPerc, lit1);
    conn.add(cpu, loadPerc, lit2);
    conn.add(cpu, loadPerc, lit3);
    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, lit1);
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Statement(org.openrdf.model.Statement) Literal(org.openrdf.model.Literal) URI(org.openrdf.model.URI)

Example 13 with RepositoryConnection

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

the class RdfCloudTripleStoreConnectionTest method testNamedGraphLoad2.

public void testNamedGraphLoad2() throws Exception {
    InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("namedgraphs.trig");
    assertNotNull(stream);
    RepositoryConnection conn = repository.getConnection();
    conn.add(stream, "", RDFFormat.TRIG);
    conn.commit();
    RepositoryResult<Statement> statements = conn.getStatements(null, vf.createURI("http://www.example.org/vocabulary#name"), null, true, vf.createURI("http://www.example.org/exampleDocument#G1"));
    int count = 0;
    while (statements.hasNext()) {
        statements.next();
        count++;
    }
    statements.close();
    assertEquals(1, count);
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) InputStream(java.io.InputStream) Statement(org.openrdf.model.Statement)

Example 14 with RepositoryConnection

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

the class RdfCloudTripleStoreConnectionTest method testClearGraph.

public void testClearGraph() 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(new URIImpl("http://example/addresses#G2"));
    tupleQuery.evaluate(tupleHandler);
    assertEquals(2, tupleHandler.getCount());
    tupleHandler = new CountTupleHandler();
    conn.clear(new URIImpl("http://example/addresses#G1"));
    tupleQuery.evaluate(tupleHandler);
    assertEquals(0, tupleHandler.getCount());
    conn.close();
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) TupleQuery(org.openrdf.query.TupleQuery) URIImpl(org.openrdf.model.impl.URIImpl) Update(org.openrdf.query.Update)

Example 15 with RepositoryConnection

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

the class RdfCloudTripleStoreConnectionTest method testSPOPredRange.

public void testSPOPredRange() throws Exception {
    RepositoryConnection conn = repository.getConnection();
    URI loadPerc = vf.createURI(litdupsNS, "loadPerc1");
    URI loadPerc2 = vf.createURI(litdupsNS, "loadPerc2");
    URI loadPerc3 = vf.createURI(litdupsNS, "loadPerc3");
    URI loadPerc4 = vf.createURI(litdupsNS, "loadPerc4");
    Literal six = vf.createLiteral("6");
    Literal sev = vf.createLiteral("7");
    Literal ten = vf.createLiteral("10");
    conn.add(cpu, loadPerc, six);
    conn.add(cpu, loadPerc2, sev);
    conn.add(cpu, loadPerc4, ten);
    conn.commit();
    String query = "PREFIX org.apache: <" + NAMESPACE + ">\n" + "select * where {" + "<" + cpu.stringValue() + "> ?p ?o.\n" + "FILTER(org.apache:range(?p, <" + loadPerc.stringValue() + ">, <" + loadPerc3.stringValue() + ">))." + "}";
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    CountTupleHandler cth = new CountTupleHandler();
    tupleQuery.evaluate(cth);
    conn.close();
    assertEquals(2, cth.getCount());
}
Also used : RepositoryConnection(org.openrdf.repository.RepositoryConnection) Literal(org.openrdf.model.Literal) 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