Search in sources :

Example 56 with TupleQuery

use of org.openrdf.query.TupleQuery in project incubator-rya by apache.

the class GeowaveDirectExample 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);
}
Also used : TupleQuery(org.openrdf.query.TupleQuery)

Example 57 with TupleQuery

use of org.openrdf.query.TupleQuery in project incubator-rya by apache.

the class GeowaveDirectExample method testAddPointAndWithinSearchWithPCJ.

private static void testAddPointAndWithinSearchWithPCJ(final SailRepositoryConnection conn) throws Exception {
    final String update = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "INSERT DATA { " + // 
    "  <urn:feature> a geo:Feature ; " + // 
    "    geo:hasGeometry [ " + // 
    "      a geo:Point ; " + // 
    "      geo:asWKT \"Point(-77.03524 38.889468)\"^^geo:wktLiteral " + // 
    "    ] . " + "}";
    final Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update);
    u.execute();
    String queryString;
    TupleQuery tupleQuery;
    CountingResultHandler tupleHandler;
    // point outside search ring
    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 . " + // 
    "  FILTER(geof:sfWithin(?wkt, \"POLYGON((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " + // 
    "}";
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("point outside search ring, Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 0);
    // point inside search ring
    queryString = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  " + // ?e ?l ?o" //
    "SELECT ?feature ?point ?wkt " + // 
    "{" + // + "  ?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)) " + // 
    "}";
    // 
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("point inside search ring, Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 1);
    // point inside search ring with Pre-Computed Join
    queryString = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  " + // ?e ?l ?o" //
    "SELECT ?feature ?point ?wkt " + // 
    "{" + // + "  ?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)) " + // 
    "}";
    // 
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("point inside search ring with Pre-Computed Join, Result count : " + tupleHandler.getCount());
    // may see points from
    Validate.isTrue(tupleHandler.getCount() >= 1);
    // during previous runs
    // point outside search ring with PCJ
    queryString = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  " + // ?e ?l ?o " //
    "SELECT ?feature ?point ?wkt " + // 
    "{" + // + "  ?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((-77 39, -76 39, -76 38, -77 38, -77 39))\"^^geo:wktLiteral)) " + // 
    "}";
    // 
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("point outside search ring with PCJ, Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 0);
    // point inside search ring with different Pre-Computed Join
    queryString = // 
    "PREFIX geo: <http://www.opengis.net/ont/geosparql#>  " + // 
    "PREFIX geof: <http://www.opengis.net/def/function/geosparql/>  " + // ?wkt ?e ?c ?l ?o " //
    "SELECT ?feature ?point " + // 
    "{" + // + "  ?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)) " + // 
    "}";
    // 
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, queryString);
    tupleHandler = new CountingResultHandler();
    tupleQuery.evaluate(tupleHandler);
    log.info("point inside search ring with different Pre-Computed Join, Result count : " + tupleHandler.getCount());
    Validate.isTrue(tupleHandler.getCount() == 1);
}
Also used : TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 58 with TupleQuery

use of org.openrdf.query.TupleQuery in project incubator-rya by apache.

the class GeowaveDirectExample 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);
}
Also used : TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 59 with TupleQuery

use of org.openrdf.query.TupleQuery in project incubator-rya by apache.

the class GeowaveDirectExample method testTemporalFreeGeoSearch.

private static void testTemporalFreeGeoSearch(final SailRepositoryConnection conn) throws MalformedQueryException, RepositoryException, UpdateExecutionException, TupleQueryResultHandlerException, QueryEvaluationException {
    // Once upon a time, a meeting happened, in a place and time, attended by 5 paladins and another.
    final String update = // 
    "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#>  " + // 
    "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> " + // 
    "PREFIX ex: <http://example.com/#> " + // 
    "INSERT DATA { " + // 
    "  ex:feature719 a geo:Feature ; " + // 
    "    geo:hasGeometry [ " + // 
    "      a geo:Point ; " + // 
    "      geo:asWKT \"Point(-77.03524 38.889468)\"^^geo:wktLiteral " + // 
    "    ] . " + // 
    "  ex:event719 a time:Instant ;" + // 4 seconds
    "          time:inXSDDateTime  '2001-01-01T01:01:04-08:00' ;" + // 
    "          ex:locatedAt ex:feature719 ;" + // 
    "			 ex:attendee ex:person01;" + // 
    "			 ex:attendee ex:person02;" + // 
    "			 ex:attendee ex:person03;" + // Use a blank node instead of person04
    "			 ex:attendee [a ex:Person ; rdfs:label 'Paladin Ogier the Dane' ] ;" + // 
    "			 ex:attendee ex:person05;" + // 
    "			 ex:attendee ex:person06." + // 
    "  ex:person01 a ex:Person ;" + // 
    "          rdfs:label \"Paladin Fossil\"." + // 
    "  ex:person02 a ex:Person ;" + // 
    "          rdfs:label \"Paladin Paul Denning\"." + // 
    "  ex:person03 a ex:Person ;" + // 
    "          rdfs:label 'Paladin Will Travel'." + // 
    "  ex:person05 a ex:Person ;" + // 
    "          rdfs:label 'Paladin dimethyl disulfide'." + // 
    "  ex:person06 a ex:Person ;" + // 
    "          rdfs:label 'Ignore me'." + // 
    "" + "}";
    final Update u = conn.prepareUpdate(QueryLanguage.SPARQL, update);
    u.execute();
    String queryString;
    TupleQuery tupleQuery;
    CountingResultHandler tupleHandler;
    // Find all events after a time, located in a polygon square, whose attendees have label names beginning with "Pal"
    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#>  " + // 
    "PREFIX ex: <http://example.com/#>  " + // 
    "SELECT ?feature ?point ?wkt ?event ?time ?person ?match" + // 
    "{" + // 
    "	 ?event a  time:Instant ; \n" + // 
    "    time:inXSDDateTime ?time ; \n" + // 
    "    ex:locatedAt ?feature ;" + // 
    "    ex:attendee ?person." + // 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 ex: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());
    Validate.isTrue(tupleHandler.getCount() == 5);
}
Also used : TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 60 with TupleQuery

use of org.openrdf.query.TupleQuery in project incubator-rya by apache.

the class RdfCloudTripleStoreConnectionTest method testSPOSubjRange.

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

Aggregations

TupleQuery (org.openrdf.query.TupleQuery)86 Update (org.openrdf.query.Update)33 RepositoryConnection (org.openrdf.repository.RepositoryConnection)27 URI (org.openrdf.model.URI)13 BindingSet (org.openrdf.query.BindingSet)12 MalformedQueryException (org.openrdf.query.MalformedQueryException)11 TupleQueryResult (org.openrdf.query.TupleQueryResult)11 QueryEvaluationException (org.openrdf.query.QueryEvaluationException)10 RepositoryException (org.openrdf.repository.RepositoryException)10 SailRepository (org.openrdf.repository.sail.SailRepository)10 HashSet (java.util.HashSet)8 Literal (org.openrdf.model.Literal)8 TupleQueryResultHandlerException (org.openrdf.query.TupleQueryResultHandlerException)8 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)8 Sail (org.openrdf.sail.Sail)7 StatementImpl (org.openrdf.model.impl.StatementImpl)6 VisibilityBindingSet (org.apache.rya.api.model.VisibilityBindingSet)5 PcjMetadata (org.apache.rya.indexing.pcj.storage.PcjMetadata)5 Test (org.junit.Test)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3