Search in sources :

Example 21 with Update

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

the class MongoRyaDirectExample method testIntersectionOfInference.

public static void testIntersectionOfInference(final SailRepositoryConnection conn, final Sail sail) throws MalformedQueryException, RepositoryException, UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
    log.info("Adding Data");
    final String instances = "INSERT DATA\n" + "{ GRAPH <http://updated/test> {\n" + "  <urn:Susan> a <urn:Mother> . \n" + "  <urn:Mary> a <urn:Woman> . \n" + "  <urn:Mary> a <urn:Parent> . \n" + "}}";
    Update update = conn.prepareUpdate(QueryLanguage.SPARQL, instances);
    update.execute();
    final String inferQuery = "select distinct ?x { GRAPH <http://updated/test> { ?x a <urn:Mother> }}";
    final String explicitQuery = "select distinct ?x { GRAPH <http://updated/test> {\n" + "  { ?x a <urn:Mother> }\n" + "  UNION {\n" + "    ?x a <urn:Woman> .\n" + "    ?x a <urn:Parent> .\n" + "  }\n" + "}}";
    log.info("Running Explicit Query");
    CountingResultHandler resultHandler = new CountingResultHandler();
    TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, explicitQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 2);
    log.info("Running Inference-dependant Query");
    resultHandler.resetCount();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
    log.info("Adding owl:intersectionOf Schema");
    // ONTOLOGY - :Mother intersectionOf[:Woman, :Parent]
    final String ontology = "INSERT DATA\n" + "{ GRAPH <http://updated/test> {\n" + "  <urn:Mother> owl:intersectionOf _:bnode1 . \n" + "  _:bnode1 rdf:first <urn:Woman> . \n" + "  _:bnode1 rdf:rest _:bnode2 . \n" + "  _:bnode2 rdf:first <urn:Parent> . \n" + "  _:bnode2 rdf:rest rdf:nil . \n" + "}}";
    update = conn.prepareUpdate(QueryLanguage.SPARQL, ontology);
    update.execute();
    log.info("Refreshing InferenceEngine");
    ((RdfCloudTripleStore) sail).getInferenceEngine().refreshGraph();
    log.info("Re-running Inference-dependant Query");
    resultHandler.resetCount();
    resultHandler = new CountingResultHandler();
    tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, inferQuery);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 2);
}
Also used : TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 22 with Update

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

the class MongoRyaDirectExample method testInfer.

public static void testInfer(final SailRepositoryConnection conn, final Sail sail) throws MalformedQueryException, RepositoryException, UpdateExecutionException, QueryEvaluationException, TupleQueryResultHandlerException, InferenceEngineException {
    // Add data
    String query = // 
    "INSERT DATA\n" + // 
    "{ \n" + " <http://acme.com/people/Mike> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <urn:type1>.  " + " <urn:type1> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <urn:superclass>.  }";
    log.info("Performing Query");
    final Update update = conn.prepareUpdate(QueryLanguage.SPARQL, query);
    update.execute();
    // refresh the graph for inferencing (otherwise there is a five minute wait)
    ((RdfCloudTripleStore) sail).getInferenceEngine().refreshGraph();
    query = "select ?s { ?s <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <urn:superclass> . }";
    final CountingResultHandler resultHandler = new CountingResultHandler();
    final TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, query);
    tupleQuery.evaluate(resultHandler);
    log.info("Result count : " + resultHandler.getCount());
    Validate.isTrue(resultHandler.getCount() == 1);
    resultHandler.resetCount();
}
Also used : TupleQuery(org.openrdf.query.TupleQuery) Update(org.openrdf.query.Update)

Example 23 with Update

use of org.openrdf.query.Update 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 24 with Update

use of org.openrdf.query.Update 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 25 with Update

use of org.openrdf.query.Update 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)

Aggregations

Update (org.openrdf.query.Update)36 TupleQuery (org.openrdf.query.TupleQuery)33 RepositoryConnection (org.openrdf.repository.RepositoryConnection)6 SailRepository (org.openrdf.repository.sail.SailRepository)3 RdfCloudTripleStore (org.apache.rya.rdftriplestore.RdfCloudTripleStore)2 Test (org.junit.Test)2 SailRepositoryConnection (org.openrdf.repository.sail.SailRepositoryConnection)2 MongoClient (com.mongodb.MongoClient)1 RdfCloudTripleStoreConnection (org.apache.rya.rdftriplestore.RdfCloudTripleStoreConnection)1 RyaSailRepository (org.apache.rya.rdftriplestore.RyaSailRepository)1 InferenceEngine (org.apache.rya.rdftriplestore.inference.InferenceEngine)1 InverseURI (org.apache.rya.rdftriplestore.inference.InverseURI)1 NamespaceManager (org.apache.rya.rdftriplestore.namespace.NamespaceManager)1 URI (org.openrdf.model.URI)1 URIImpl (org.openrdf.model.impl.URIImpl)1 UpdateExecutionException (org.openrdf.query.UpdateExecutionException)1 ParsedUpdate (org.openrdf.query.parser.ParsedUpdate)1 Sail (org.openrdf.sail.Sail)1