0

Given the following triples describe Forklift1 location at the different times:

:forklift1 
   :location :station1, :dockdoor1;
   :9305fc5f-d43d :station1;
   :a4e9-2bcd5b97 :dockdoor1;
  .
:9305fc5f-d43d a :location;
   :createdDate "2022-01-02T10:00:00.000-05:00"^^xsd:dateTime; 
   :expiryDate "2022-01-03T14:00:00.000-05:00"^^xsd:dateTime; 
  .
:a4e9-2bcd5b97 a :location;
   :createdDate "2022-01-03T14:00:00.000-05:00"^^xsd:dateTime; 
  .

To retrieve Forklift1's current location, a SPARQL query is:

select ?o where { 
    :forklift1 :location ?o 
    optional{:forklift1 ?px ?o. ?px a :location. optional{?px :createdDate ?createdDate} optional {?px :expiryDate ?expiryDate}}
    filter (!bound(?expiryDate)) 
  }

?o :dockdoor1

My goal is to make Query Engine return the same result but with a much simpler query:

select ?s where { 
    :forklift1 :location ?o.
}

?o :dockdoor1

I am using Jena TBD + ARQ; I read some documents, it can be done by customizing ARQ Query Engine. For each Triple pattern :forklift1 :location ?o, to programmatically add the new property instance pattern optional{:forklift1 ?px ?o. ?px a :location. optional{?px :createdDate ?createdDate} optional {?px :expiryDate ?expiryDate}} filter (!bound(?expiryDate)). I am not hands on this and don't know where to start.

Does anyone know how to do this? Your help will move my work forward!

Tony
  • 1
  • 1
  • your query is overly complicated. `select ?o where { :forklift1 :location ?o FILTER NOT EXISTS { :o :expiryDate ?expiryDate }}` would be enough. – UninformedUser Jan 30 '22 at 04:21
  • other than that, a custom query engine that simply transforms the query before executing would be one way to go, example is here: https://github.com/apache/jena/blob/main/jena-examples/src/main/java/arq/examples/engine/MyQueryEngine.java - you could either append triple patterns on the query structure, but maybe better would be to work on the algebra – UninformedUser Jan 30 '22 at 04:24
  • 1
    Thank you for the reply and the example! It helps me to start in the right direction. I will give it a try to transform the query, and modify the algebra expression. BTW, you are right, the query can be simplified, it was for location at any given timeline. – Tony Jan 30 '22 at 15:02

0 Answers0