use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class CbSailProducer method performSelect.
protected Object performSelect(final String query, final String auth, final Boolean infer) throws RepositoryException, MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException {
final TupleQuery tupleQuery = connection.prepareTupleQuery(QueryLanguage.SPARQL, query);
if (auth != null && auth.length() > 0) {
tupleQuery.setBinding(CONF_QUERY_AUTH, valueFactory.createLiteral(auth));
}
if (infer != null) {
tupleQuery.setBinding(CONF_INFER, valueFactory.createLiteral(infer));
}
if (CbSailEndpoint.CbSailOutput.BINARY.equals(queryOutput)) {
final List listOutput = new ArrayList();
final TupleQueryResultHandlerBase handler = new TupleQueryResultHandlerBase() {
@Override
public void handleSolution(final BindingSet bindingSet) throws TupleQueryResultHandlerException {
final Map<String, String> map = new HashMap<String, String>();
for (final String s : bindingSet.getBindingNames()) {
map.put(s, bindingSet.getBinding(s).getValue().stringValue());
}
listOutput.add(map);
}
};
tupleQuery.evaluate(handler);
return listOutput;
} else if (CbSailEndpoint.CbSailOutput.XML.equals(queryOutput)) {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final SPARQLResultsXMLWriter sparqlWriter = new SPARQLResultsXMLWriter(baos);
tupleQuery.evaluate(sparqlWriter);
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
} else {
throw new IllegalArgumentException("Query Output[" + queryOutput + "] is not recognized");
}
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class TriplestoreProvenanceCollectorTest method testCollect.
@Test
public void testCollect() throws ProvenanceCollectionException, RepositoryException, MalformedQueryException, QueryEvaluationException {
Sail ms = new MemoryStore();
SailRepository repo = new SailRepository(ms);
repo.initialize();
TriplestoreProvenanceCollector coll = new TriplestoreProvenanceCollector(repo, "fakeUser", "SPARQL");
coll.recordQuery("fakeQuery");
String queryString = "SELECT ?x ?y WHERE { ?x ?p ?y } ";
TupleQuery tupleQuery = repo.getConnection().prepareTupleQuery(QueryLanguage.SPARQL, queryString);
TupleQueryResult result = tupleQuery.evaluate();
// TODO not asserting on the results.
assertTrue(result.hasNext());
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RyaGeoDirectExample method testTemporalFreeGeoSearch.
private static void testTemporalFreeGeoSearch(final SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, UpdateExecutionException, TupleQueryResultHandlerException, QueryEvaluationException {
String queryString;
TupleQuery tupleQuery;
CountingResultHandler tupleHandler;
// ring containing point
queryString = //
"PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + //
"PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + //
"PREFIX time: <http://www.w3.org/2006/time#> " + //
"PREFIX tempo: <tag:rya-rdf.org,2015:temporal#> " + //
"PREFIX fts: <http://rdf.useekm.com/fts#> " + //
"SELECT ?feature ?point ?wkt ?event ?time ?person ?match" + //
"{" + //
" ?event a time:Instant . \n" + //
" ?event time:inXSDDateTime ?time . \n" + // after 3 seconds
" FILTER(tempo:after(?time, '2001-01-01T01:01:03-08:00') ) \n" + //
" ?feature a geo:Feature . " + //
" ?feature geo:hasGeometry ?point . " + //
" ?point a geo:Point . " + //
" ?point geo:asWKT ?wkt . " + //
" FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)). " + //
" ?person a <http://example.org/ontology/Person> . " + //
" ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . " + //
" FILTER(fts:text(?match, \"pal*\")) " + //
"}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleHandler = new CountingResultHandler();
tupleQuery.evaluate(tupleHandler);
log.info("Result count : " + tupleHandler.getCount());
// TODO ==5 some data is missing for this query!
Validate.isTrue(tupleHandler.getCount() == 0);
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RyaGeoDirectExample method testDeleteGeoData.
private static void testDeleteGeoData(final SailRepositoryConnection conn) throws Exception {
// Delete all stored points
final String sparqlDelete = //
"PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + //
"PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + //
"DELETE {\n" + //
" ?feature a geo:Feature . " + //
" ?feature geo:hasGeometry ?point . " + //
" ?point a geo:Point . " + //
" ?point geo:asWKT ?wkt . " + "}\n" + "WHERE { \n" + //
" ?feature a geo:Feature . " + //
" ?feature geo:hasGeometry ?point . " + //
" ?point a geo:Point . " + //
" ?point geo:asWKT ?wkt . " + //
"}";
final Update deleteUpdate = conn.prepareUpdate(QueryLanguage.SPARQL, sparqlDelete);
deleteUpdate.execute();
String queryString;
TupleQuery tupleQuery;
CountingResultHandler tupleHandler;
// Find all stored points
queryString = //
"PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + //
"PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + //
"SELECT ?feature ?point ?wkt " + //
"{" + //
" ?feature a geo:Feature . " + //
" ?feature geo:hasGeometry ?point . " + //
" ?point a geo:Point . " + //
" ?point geo:asWKT ?wkt . " + //
"}";
tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
tupleHandler = new CountingResultHandler();
tupleQuery.evaluate(tupleHandler);
log.info("Result count : " + tupleHandler.getCount());
Validate.isTrue(tupleHandler.getCount() == 0);
}
use of org.openrdf.query.TupleQuery in project incubator-rya by apache.
the class RyaGeoDirectExample method testGeoFreetextWithPCJSearch.
private static void testGeoFreetextWithPCJSearch(final SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, TupleQueryResultHandlerException, QueryEvaluationException {
// ring outside point
final String queryString = //
"PREFIX geo: <http://www.opengis.net/ont/geosparql#> " + //
"PREFIX fts: <http://rdf.useekm.com/fts#> " + //
"PREFIX geof: <http://www.opengis.net/def/function/geosparql/> " + //
"SELECT ?feature ?point ?wkt ?e ?c ?l ?o ?person ?match " + //
"{" + //
" ?person a <http://example.org/ontology/Person> . " + //
" ?person <http://www.w3.org/2000/01/rdf-schema#label> ?match . " + //
" FILTER(fts:text(?match, \"!alice & hose\")) " + //
" ?e a ?c . " + //
" ?e <http://www.w3.org/2000/01/rdf-schema#label> ?l . " + //
" ?e <uri:talksTo> ?o . " + //
" ?feature a geo:Feature . " + //
" ?feature geo:hasGeometry ?point . " + //
" ?point a geo:Point . " + //
" ?point geo:asWKT ?wkt . " + //
" FILTER(geof:sfWithin(?wkt, \"POLYGON((-78 39, -77 39, -77 38, -78 38, -78 39))\"^^geo:wktLiteral)) " + //
"}";
final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
final CountingResultHandler tupleHandler = new CountingResultHandler();
tupleQuery.evaluate(tupleHandler);
log.info("Result count : " + tupleHandler.getCount());
// TODO ==1 some data is missing for this query!
Validate.isTrue(tupleHandler.getCount() == 0);
}
Aggregations