You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jena.apache.org by "Nouwt, B. (Barry)" <ba...@tno.nl.INVALID> on 2020/08/31 14:00:20 UTC

time ontology

Hi everyone,

for a project I have a set of sosa:Observation's and would like to use the elegant W3C Time ontology (https://www.w3.org/TR/owl-time/). I especially like the way they have a time:after and time:before object property and I would like to use those as a filter in my SPARQL query (note that I do know the SPARQL FILTER keyword exists that supports datetime comparisons, i.e. FILTER (?date > "2020-05-01T13:00:00Z"^^xsd:dateTime && ?date < "2020-05-03T11:00:00Z"^^xsd:dateTime) ).

When I try to realize this I run into a problem and I am wondering what other think about this. I would like to execute the following example query:

PREFIX test: <https://www.tno.nl/test/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX time: <http://www.w3.org/2006/time#>
PREFIX sosa: <http://www.w3.org/ns/sosa/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT * WHERE {
                ?mea rdf:type sosa:Observation .
                ?mea sosa:hasSimpleResult ?result .
                ?mea test:measureTime ?time1 .
                ?time1 rdf:type time:Instant .
                ?time1 time:inXSDDateTime ?timeValue .
                ?time1 time:after ?time2 .
                ?time1 time:before ?time3 .
                ?time2 rdf:type time:Instant .
                ?time2 time:inXSDDateTime "2020-05-01T13:00:00Z"^^xsd:dateTime .
                ?time3 rdf:type time:Instant .
                ?time3 time:inXSDDateTime "2020-05-03T11:00:00Z"^^xsd:dateTime .
}

Which I would like to return all observations within the two specified time instances (defined using variables ?time2 and ?time3), but I cannot get this to work. The problem is that, to make this work, my triple store would need to contain all possible ?time2 and ?time3 datetimes for every observation, which is impractical (and impossible).

Any ideas on how to solve this without using the SPARQL FILTER keyword? Was W3C's Time ontology not designed with this kind of usage in mind?

Kind regards and thanks in advance,

Barry

This message may contain information that is not intended for you. If you are not the addressee or if this message was sent to you by mistake, you are requested to inform the sender and delete the message. TNO accepts no liability for the content of this e-mail, for the manner in which you use it and for damage of any kind resulting from the risks inherent to the electronic transmission of messages.

RE: time ontology

Posted by "Nouwt, B. (Barry)" <ba...@tno.nl.INVALID>.
Hi Greg, thanks for the detailed explanation!

Although I would prefer to solve this at the reasoner level, I'm indeed considering to look into ARQ property functions and whether they can help me with my use case.

Thanks! Barry

-----Original Message-----
From: Greg <ga...@mail.com>
Sent: dinsdag 1 september 2020 22:35
To: users@jena.apache.org
Subject: Re: time ontology

Hi Barry,

 From what I can remember the standard was focussed upon providing a vocabularly to represent data rather than defining functionality.

You could implement the 'time:after' and 'time:before' as Property Functions and then register them with your ARQ Engine. They are fairly straightforward to implement once the input and output interfaces are understood. Don't know who implemented and documented these originally:

https://jena.apache.org/documentation/query/writing_propfuncs.html

They were used in the GeoSPARQL module for triples such as '?area1 geo:sfContains ?area2' (see 'org.apache.jena.geosparql.geo.topological.SFContainsPF'). In that code there are some layers of generalisation to cover possible use cases and support features and other implementation details of the standard. It is probably unnecessarily daunting for your case.

Ultimately, they invoke an equivalent Filter Function that returns a boolean NodeValue (as a QueryIterator), which I would expect to be your return value.

If you know/decide that the subject and object will always be bound to a value then alot of the complexity can be removed. The 'PFuncSimple'
interface and 'QueryIterSingleton' will probably be enough to wrap around the dateTime comparison.

In your query example, the graph will need to be traversed to find the required triples and their object values based on the subject variables.
This can be done using the active Graph in the ExecutionContext, e.g 'Graph graph = execCxt.getActiveGraph();' followed by 'graph.find(SUBJECT, PREDICATE, null)' and then handling the iterator to unwrap the 'triple.getObject()'.

Hope this helps,

Greg

On 31/08/2020 15:00, Nouwt, B. (Barry) wrote:
> Hi everyone,
>
> for a project I have a set of sosa:Observation's and would like to use the elegant W3C Time ontology (https://www.w3.org/TR/owl-time/). I especially like the way they have a time:after and time:before object property and I would like to use those as a filter in my SPARQL query (note that I do know the SPARQL FILTER keyword exists that supports datetime comparisons, i.e. FILTER (?date > "2020-05-01T13:00:00Z"^^xsd:dateTime && ?date < "2020-05-03T11:00:00Z"^^xsd:dateTime) ).
>
> When I try to realize this I run into a problem and I am wondering what other think about this. I would like to execute the following example query:
>
> PREFIX test: <https://www.tno.nl/test/> PREFIX rdf:
> <http://www.w3.org/1999/02/22-rdf-syntax-ns#<http://www.w3.org/1999/02/22-rdf-syntax-ns>>
> PREFIX time: <http://www.w3.org/2006/time#<http://www.w3.org/2006/time>> PREFIX sosa:
> <http://www.w3.org/ns/sosa/> PREFIX xsd:
> <http://www.w3.org/2001/XMLSchema#<http://www.w3.org/2001/XMLSchema>>
>
> SELECT * WHERE {
>                  ?mea rdf:type sosa:Observation .
>                  ?mea sosa:hasSimpleResult ?result .
>                  ?mea test:measureTime ?time1 .
>                  ?time1 rdf:type time:Instant .
>                  ?time1 time:inXSDDateTime ?timeValue .
>                  ?time1 time:after ?time2 .
>                  ?time1 time:before ?time3 .
>                  ?time2 rdf:type time:Instant .
>                  ?time2 time:inXSDDateTime "2020-05-01T13:00:00Z"^^xsd:dateTime .
>                  ?time3 rdf:type time:Instant .
>                  ?time3 time:inXSDDateTime "2020-05-03T11:00:00Z"^^xsd:dateTime .
> }
>
> Which I would like to return all observations within the two specified time instances (defined using variables ?time2 and ?time3), but I cannot get this to work. The problem is that, to make this work, my triple store would need to contain all possible ?time2 and ?time3 datetimes for every observation, which is impractical (and impossible).
>
> Any ideas on how to solve this without using the SPARQL FILTER keyword? Was W3C's Time ontology not designed with this kind of usage in mind?
>
> Kind regards and thanks in advance,
>
> Barry
>
> This message may contain information that is not intended for you. If you are not the addressee or if this message was sent to you by mistake, you are requested to inform the sender and delete the message. TNO accepts no liability for the content of this e-mail, for the manner in which you use it and for damage of any kind resulting from the risks inherent to the electronic transmission of messages.
>

Re: time ontology

Posted by Greg <ga...@mail.com>.
Hi Barry,

 From what I can remember the standard was focussed upon providing a
vocabularly to represent data rather than defining functionality.

You could implement the 'time:after' and 'time:before' as Property
Functions and then register them with your ARQ Engine. They are fairly
straightforward to implement once the input and output interfaces are
understood. Don't know who implemented and documented these originally:

https://jena.apache.org/documentation/query/writing_propfuncs.html

They were used in the GeoSPARQL module for triples such as '?area1
geo:sfContains ?area2' (see
'org.apache.jena.geosparql.geo.topological.SFContainsPF'). In that code
there are some layers of generalisation to cover possible use cases and
support features and other implementation details of the standard. It is
probably unnecessarily daunting for your case.

Ultimately, they invoke an equivalent Filter Function that returns a
boolean NodeValue (as a QueryIterator), which I would expect to be your
return value.

If you know/decide that the subject and object will always be bound to a
value then alot of the complexity can be removed. The 'PFuncSimple'
interface and 'QueryIterSingleton' will probably be enough to wrap
around the dateTime comparison.

In your query example, the graph will need to be traversed to find the
required triples and their object values based on the subject variables.
This can be done using the active Graph in the ExecutionContext, e.g
'Graph graph = execCxt.getActiveGraph();' followed by
'graph.find(SUBJECT, PREDICATE, null)' and then handling the iterator to
unwrap the 'triple.getObject()'.

Hope this helps,

Greg

On 31/08/2020 15:00, Nouwt, B. (Barry) wrote:
> Hi everyone,
>
> for a project I have a set of sosa:Observation's and would like to use the elegant W3C Time ontology (https://www.w3.org/TR/owl-time/). I especially like the way they have a time:after and time:before object property and I would like to use those as a filter in my SPARQL query (note that I do know the SPARQL FILTER keyword exists that supports datetime comparisons, i.e. FILTER (?date > "2020-05-01T13:00:00Z"^^xsd:dateTime && ?date < "2020-05-03T11:00:00Z"^^xsd:dateTime) ).
>
> When I try to realize this I run into a problem and I am wondering what other think about this. I would like to execute the following example query:
>
> PREFIX test: <https://www.tno.nl/test/>
> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
> PREFIX time: <http://www.w3.org/2006/time#>
> PREFIX sosa: <http://www.w3.org/ns/sosa/>
> PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
>
> SELECT * WHERE {
>                  ?mea rdf:type sosa:Observation .
>                  ?mea sosa:hasSimpleResult ?result .
>                  ?mea test:measureTime ?time1 .
>                  ?time1 rdf:type time:Instant .
>                  ?time1 time:inXSDDateTime ?timeValue .
>                  ?time1 time:after ?time2 .
>                  ?time1 time:before ?time3 .
>                  ?time2 rdf:type time:Instant .
>                  ?time2 time:inXSDDateTime "2020-05-01T13:00:00Z"^^xsd:dateTime .
>                  ?time3 rdf:type time:Instant .
>                  ?time3 time:inXSDDateTime "2020-05-03T11:00:00Z"^^xsd:dateTime .
> }
>
> Which I would like to return all observations within the two specified time instances (defined using variables ?time2 and ?time3), but I cannot get this to work. The problem is that, to make this work, my triple store would need to contain all possible ?time2 and ?time3 datetimes for every observation, which is impractical (and impossible).
>
> Any ideas on how to solve this without using the SPARQL FILTER keyword? Was W3C's Time ontology not designed with this kind of usage in mind?
>
> Kind regards and thanks in advance,
>
> Barry
>
> This message may contain information that is not intended for you. If you are not the addressee or if this message was sent to you by mistake, you are requested to inform the sender and delete the message. TNO accepts no liability for the content of this e-mail, for the manner in which you use it and for damage of any kind resulting from the risks inherent to the electronic transmission of messages.
>