Home
Categories
Dictionary
Glossary
Download
Project Details
Changes Log
What Links Here
FAQ
License

Owl-time request creation



The org.da.protoframework.jena.common.sparql.SparqlRequest class allows to create SPARQL requests easily without having to write the request "by hand". This class is available in the JenaCommon.jar jar file.

See SPARQL request creation for information about crating general requests.

SparqlRequest API for owl-time requests

The SparqlRequest class has the following specific API for GeoSparql requests:

public class org.da.protoframework.jena.common.sparql.SparqlRequest
An utility which generates a SPARQL request.

Modifier and Type Method and Description
boolean addTime(String var, String varTime, boolean isDateTime)
Get the time for an individual

Optional constructs

The addOptionalConstruct() method allows to create an OPTIONAL construct withih the Sparql request. This construct can contain several expressions. The API SparqlRequest.Optional result is:

public class org.da.protoframework.jena.common.SparqlRequest.Optional
The optional construct.

Modifier and Type Method and Description
boolean addDistance(String var, String fromVar, String varDist, short unit, boolean isExact)
Specifies a GeoSparql function to get the distance between two individuals
boolean addGeometry(String var, String varLat, String varLon, boolean isExact)
Specifies a GeoSparql function to get the latitude and longitude of an individual

Examples

Geometry example

Suppose that we have an ontology with an Waypoint class. We want to create a request getting the list of Waypoints and their latitude and longitude.

We can do:
      SparqlRequest request = new SparqlRequest("sitac");
      request.addSelect("wpt");
      request.addSelect("lat");
      request.addSelect("lon");
      request.addType("wpt", "Waypoint");
      request.addGeometry("wpt", "lat", "lon", true);
      String query = request.getSPARQL();
We will generate the following query:
      SELECT ?wpt lat ?lon
      WHERE
      {
        ?wpt rdf:type sitac:Waypoint .
        ?wpt sitac:hasExactGeometry ?auto_1 .
        ?auto_1 sitac:asWKT ?auto_2 .
        BIND (xs:decimal(replace( str(?auto_2), "^[^0-9\\.-]*([-]?[0-9\\.]+) .*$", "$1" )) as ?lon)
        BIND (xs:decimal(replace( str(?auto_2), "^.* ([-]?[0-9\\.]+)[^0-9\\.]*$", "$1" )) as ?lat)   
      }      

Distance example

Now we also have an Aircraft individual, and we want to get the distance between each Waypoint and our Aircraft.

We can do:
      SparqlRequest request = new SparqlRequest("sitac");
      request.addSelect("wpt");
      request.addSelect("dist");
      request.addType("wpt", "Waypoint");      
      request.addAdditionalVariable("ac");
      request.addType("ac", "Aircraft");  
      request.addPropertyValue("ac", "Label", "MyAircraft");
      request.addDistance("wpt", "ac", "dist", SparqlRequest.DISTANCE_M, true);
      String query = request.getSPARQL();
      SELECT ?wpt ?dist
      WHERE {
        ?wpt rdf:type sitac:Waypoint .
        ?wpt sitac:hasExactGeometry ?auto_1 .
        ?auto_1 sitac:asWKT ?auto_2 . 
        ?ac rdf:type sitac:Aircraft .
        ?ac sitac:Label "MyAircraft" .       
        ?ac sitac:hasExactGeometry ?auto_3 .
        ?auto_3 sitac:asWKT ?auto_4 .                 
        BIND (geof:distance(?auto_2, ?auto_4, <http://www.opengis.net/def/uom/OGC/1.0/meter>) as ?dist)
     }

See also


Categories: builtin-applis

Copyright 2017-2020 Dassault Aviation. All Rights Reserved. Documentation and source under the LGPL v3 licence