1

I'm studying non-temporal SPARQL Queries and I'm a bit confused about the concept of RDF triples..

Say, I want to find all employees that cancelled a job and then later chose to complete the same job that they cancelled. So how can I store the date that they cancelled the job and the date they chose to do the same job?

Would the following work?

SELECT ?emp
    WHERE
    {
      ?emp :cancelledJob ?job
      ?emp :dateCancelled ?date1 
      ?emp :selectedJob ?job 
      ?emp :dateSelectedJob ?date2 
      FILTER(?date1 < ?date2) 
    }
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
Landon
  • 21
  • 2
  • 8
  • 2
    If both dates have the same datatype which is supported by SPARQL, e.g. `xsd:date`, it will work. – UninformedUser Mar 30 '17 at 10:37
  • 1
    @AKSW Are you sure it wlil work with `xsd:date`? Looking at the [operating mappings](https://www.w3.org/TR/2013/REC-sparql11-query-20130321/#OperatorMapping), I'm not sure whether support for date type stuff aside from `xsd:dateTime` is required, even if some endpoints might support it. (E.g., RobV mentions converting things to `xsd:dateTime` in http://stackoverflow.com/questions/24051435/filter-by-date-range-in-sparql). – Joshua Taylor Mar 30 '17 at 21:31
  • Hm, looking at the documents I guess you're right. The standard seems to cover only `xsd:dateTime`. I'm wondering whether there is some kind of subsumption, i.e. `xsd:dateTime` should be more specific than `xsd:date`. But I guess that's even not part of the XML Schema and simply beeing a syntax error. Thank's for correction! – UninformedUser Mar 31 '17 at 06:58

1 Answers1

3

Your query will work if the values of ?date1 and ?date2 are such that they comparable with < as defined in the standard, or if the specific implementation that you're using extends the < operator to handle them. The operator mapping for SPARQL is given in the standard, at 17.3 Operator Mapping. The datatypes that the standard dictates, along with their mappings are:

numeric         op:numeric-less-than(A, B)
simple literal  op:numeric-equal(fn:compare(A, B), -1)
xsd:string      op:numeric-equal(fn:compare(STR(A), STR(B)), -1)
xsd:boolean     op:boolean-less-than(A, B)
xsd:dateTime    op:dateTime-less-than(A, B)

So, if your dates are any of those types, your query will work. Some implementations might handle additional types, too.

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353