Temporal RDF Example
3.2 spatio-temporal query language for linked data
Traditionally, SPARQL has been the query language for RDF data. It is a W3C recommendation that operates at the level of RDF graphs. However, SPARQL does not support spatio-temporal query. Using SPARQL for querying spatio-temporal information becomes relatively complex for building the query due to the complicated expressions. Additionally, it requires the user has to be familiar with the representation model and uses specific constructs triple patterns to the underlying spatio-temporal model. This section will review several spatio-temporal query languages for RDF that have been proposed recently to address this challenge.
In [107], the authors introduce the spatio-temporal model, namely stRDF, and its corresponding stSPARQL query language. The stSPARQL is an extension of SPARQL with additional temporal and spatial operators. Besides, it also defines two new variable types, namely spatial variables and temporal variables. The spatial variables can be used in basic graph patterns, refers to spatial literals denoting semi-linear point sets. The temporal variables can be used as the last term in a new defined temporal basic graph pattern, called quad pattern, refers to the valid time
7 http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/asWK 8 http://www.opengis.net/ont/OGC-GeoSPARQL/1.0/asGM
3.2 spatio-temporal query language for linked data 39
of a triple. In the query translation phase, along with the temporal and spatial constants, these two type of variables can be taken as arguments of the spatial and temporal functions. Moreover, they can be used in the SELECT, FILTER, and HAVING clause of a SPARQL query. stSPARQL uses vectors of points for representing the different geometries and it does not support querying using qualitative operators as well as spatio-temporal reasoning.
Resuming the illustrative example query in Chapter1, Listing3.3presents a translation of this query into stSPARQL. The stSPARQL extensions are marked in red colour. In this example, the stSPARQL query expressions involve model specific triples (i.e, strdf:hasGeometry), spatial function (i.e, strdf:within), temporal variable (i.e, ?T) and its constraint (t>="01/01/2019" and t<="31/03/2019"). The example also implies that users have to be familiar with details of the underlying stRDF model for constructing a query.
SELECT ?attractions (avg(?value) as ?avg)
Listing 3.3: An example of stSPARQL query.
Similar to stSPARQL, the query language SPARQL-ST [142] also introduces spatial and temporal variables. In particular, the spatial variables (denoted by a % prefix) are used to represent the complex spatial features. In [142], the authors also extend the concept of SPARQL mapping in order to map a spatial variable to a set of triples that represents the required spatial information.
Similarly, temporal variables (denoted by a # prefix) are mapped to time intervals and can appear in the fourth position of a temporal triple pattern in the style of [71]. Furthermore, in SPARQL-ST, two special filters are introduced, namely SPATIAL FILTER and TEMPORAL FILTER. These filters are used to filter the results with spatial and temporal constraints (OGC Simple Feature Access topological relations and distance for the spatial part, and Allen’s interval calculus [8] for the temporal part). In order to enable the realization of this query language, the used spatial and temporal operators need to be implemented. Despite the fact that SPARQL-ST is an extension of SPARQL and is designed for querying RDF graphs, the ontology and data, however, are stored
40 related work
Listing 3.4: An example of SPARQL-ST query.
#return the average air temperature value of 2019.
SELECT (avg(?value) as ?avg)
Listing 3.5: An example of t-SPARQL time point query.
in a relational database. Therefore, to execute the SPARQL-ST query, a given query needs to be translated to the corresponding SQL query prior to execution. The first version of SPARQL-ST is built on top of Oracle’s DBMS. This consequently leads to several drawbacks, i.e, reasoning and linked data modeling are difficult to apply (model semantic data in RDF is much easier than in SQL). Listing3.4illustrates our aforementioned motivation query in SPARQL-ST language.
t-SPARQL [189] is also another extension of SPARQL with additional operators for expressing temporal queries. In fact, this is a temporal language that is built upon the temporal named graph model [189], previously mentioned in Section3.1.2. Similar to SPARQL-ST, the t-SPARQL queries are translated to SPARQL prior to execution. To retrieve the temporal information, the language supports two types of temporal queries: time point query and temporal query. The time point query supports retrieving information which is valid at a specified point in time, while temporal query is used for both wild-card intervals and time points. These wild-cards can be used to bind a variable to the validity period of a triple or to express temporal relationships between intervals. t-SPARQL allows one form of temporal wild-cards [?s, ?e] which binds the literal start time (?s) and end time (?e) values. Note that, t-SPARQL limits to retrieving temporal information and does not take into account the spatial aspect. Examples of time-point and wild-cards queries are shown in Listings3.5,3.6respectively.
3.2 spatio-temporal query language for linked data 41
#return the average air temperature value for the time period 01/01/19 to 31/03/19.
SELECT (avg(?value) as ?avg) WHERE{
?sensor a sosa:Sensor;
sosa:observes iot:AirTemperature.
?obs sosa:madeBySensor ?sensor.
[01/01/19,31/03/19]?obs sosa:hasSimpleResult ?value.
}
Listing 3.6: An example of t-SPARQL temporal query.
3.2.1 GeoSPARQL query language
The aforementioned GeoSPARQL data models [19] have provided the corresponding SPARQL-like query language. The major contribution of the GeoSPARQL language is providing a stan-dard and flexible way that ask for relationships between spatial objects. These come in the form of topological binary properties which can be used in SPARQL query triple patterns as a normal predicate. These spatial predicates are then translated by the query rewrite component based on the predefined rules. Normally, these properties aim to ask the relationships between objects of the geo:Geometry class. However, with the support from the provided GeoSPARQL’s query rewrite rules, they can also be used for the geo:Features objects, or between geo:Features and geo:Geometries. Several topological relations are supported: equals, disjoint, intersects, touches, within, contains, overlaps, and crosses. Listing 3.7 illustrates the GeoSPARQL query that uses topological relation (geo:sfWithin) in query triple pattern.
SELECT ?attractions WHERE{
?entity skos:broader dbr:Category:Tourism_by_city .
?places skos:broader ?entity .
?attractions dcterms:subject ?places .
?attractions dbo:country ?country .
?country dbo:location dbr:Europe.
?attractions geo:lat ?lat.
?attractions geo:long ?long.
?attractions geo:hasGeometry ?attrLoc.
?station a got:WeatherStation;
geo:hasGeometry ?stationLocation.
?stationLocation geo:sfWithin ?attrLoc.
}
Listing 3.7: An example of GeoSPARQL query example that uses topological binary properties as predicate.
Besides the topological binary properties, GeoSPARQL also provides a set of SPARQL extension functions for spatial computation. These functions can be used in FILTER clause for different purposes. For example, they can take multiple geometries as predicates and produce either a new geometry or another datatype as a result. Another functionality of these functions is to test the topological relation between the geometries, which returns a Boolean value. Listing3.8 presents an example of the boolean topological functions, namely ogcf:intersects , which returns true if two geometries intersect.
42 related work
SELECT ?sensorLocation WHERE{
?sensor a sosa:Sensor;
sosa:isHostedBy ?sensorLocation;
sosa:observes iot:AirTemperature.
FILTER(ogcf:intersects(?sensorLocation,"POLYGON((-77.089005 38.913574,-77.029953 38.913574, -77.029953 38.886321,-77.089005 38.886321,-77.089005 38.913574))"^^ogc:WKTLiteral))
}}
}
Listing 3.8: GeoSPARQL query example using spatial function.
The GeoSPARQL has become a standard SPARQL query language with spatial computation support and has been used in many European projects. Our proposed spatio-temporal query language also adopts the GeoSPARQL query language syntax, which will be presented in Chap-ter6.