use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class ArbitraryLengthQueryTest method testWithoutSubquery.
/**
* This test works. The expected result is 6 rows ranging from "Model1Class 1" through "Model1Class 6".
*
* @throws RepositoryException
* @throws QueryEvaluationException
* @throws TupleQueryResultHandlerException
*
* @throws MalformedQueryException
*/
public void testWithoutSubquery() throws RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, MalformedQueryException {
final String query = "SELECT ?i ?i_label ?i_class ?i_v1" + "WHERE {" + "?i <http://www.w3.org/2000/01/rdf-schema#label> ?i_label ." + "?i a ?i_class ." + "?i_class <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://dragon-research.com/cham/model/model1#Model1Class> ." + "OPTIONAL { ?i <http://dragon-research.com/cham/model/model1#name> ?i_v1 } ." + "}" + "ORDER BY ?i_label";
final RepositoryConnection conn = repository.getConnection();
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
RdfCloudTripleStoreConnectionTest.CountTupleHandler countTupleHandler = new RdfCloudTripleStoreConnectionTest.CountTupleHandler();
tupleQuery.evaluate(countTupleHandler);
assertEquals(6, countTupleHandler.getCount());
conn.close();
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class ArbitraryLengthQueryTest method testWithSubquery.
/**
* This test fails. The expected result is 6 rows ranging from "Model1Class 1 Event" to "Model1Class 6 Event". The
* current result is a RejectedExecutionException.
*
* @throws RepositoryException
* @throws QueryEvaluationException
* @throws TupleQueryResultHandlerException
*
* @throws MalformedQueryException
*/
public void testWithSubquery() throws RepositoryException, QueryEvaluationException, TupleQueryResultHandlerException, MalformedQueryException {
final String query = "SELECT ?i ?i_label ?i_class ?i_v1 ?i_v2 ?i_v2_label ?i_v2_class ?i_v2_v1" + "WHERE {" + "?i <http://www.w3.org/2000/01/rdf-schema#label> ?i_label ." + "?i a ?i_class ." + "?i_class <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://dragon-research.com/cham/model/model1#Event> ." + "OPTIONAL { ?i <http://dragon-research.com/cham/model/model1#name> ?i_v1 } ." + "?i <http://dragon-research.com/cham/model/model1#hasTemporalEntity> ?i_v2 ." + "{" + "SELECT ?i_v2 ?i_v2_label ?i_v2_class ?i_v2_v1" + "WHERE {" + "?i_v2 <http://www.w3.org/2000/01/rdf-schema#label> ?i_v2_label ." + "?i_v2 a ?i_v2_class ." + "?i_v2_class <http://www.w3.org/2000/01/rdf-schema#subClassOf>* <http://dragon-research.com/cham/model/model1#TemporalInstant> ." + "OPTIONAL { ?i_v2 <http://dragon-research.com/cham/model/model1#dateTime> ?i_v2_v1 } ." + "}" + "ORDER BY ?i_v2_label" + "}" + "}" + "ORDER BY ?i_label";
final RepositoryConnection conn = repository.getConnection();
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
RdfCloudTripleStoreConnectionTest.CountTupleHandler countTupleHandler = new RdfCloudTripleStoreConnectionTest.CountTupleHandler();
tupleQuery.evaluate(countTupleHandler);
assertEquals(6, countTupleHandler.getCount());
conn.close();
}
use of org.openrdf.query.TupleQuery 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();
}
use of org.openrdf.query.TupleQuery 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());
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RdfCloudTripleStoreConnectionTest method testPOPredRange.
public void testPOPredRange() 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 {" + "?x ?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(cth.getCount(), 2);
}
Aggregations