I'm trying to find out what XQuery/XPath functions are supported on a given platform. That is - I'd like to be able to test the capabiities of the platform using a query, if that's possible. I'm currently using OWLIM+Sesame+dotNetRdf and tried to use op:subtract-dayTimeDuration-from-date. I got an error saying "org.openrdf.query.parser.sparql.ast.VisitorException: QName 'op:subtract-dayTimeDuration-from-date' uses an undefined prefix". The use case is to filter out anything older than some date relative to today. the following pseudocode is kinda what I'm after FILTER(?theDateImLookingAt > today.subtractDays(28))

The XQuery spec states, in relation to functions with a op: prefix, that "These functions are not available directly to users, and there is no requirement that implementations should actually provide these functions. For this reason, no namespace is associated with the op prefix."

But every one of the functions that I want to use for date calculations has an op: prefix. What am I to do?

asked 24 Jul '12, 06:53

Andrew%20Matthews's gravatar image

Andrew Matthews ♦♦
accept rate: 0%

SPARQL (1.1) has standardised the XPath/XQuery-related functions that should be available (and you don't use a namespace).

Unfortunately it's not a long list...

permanent link

answered 24 Jul '12, 08:44

Barry%20Norton's gravatar image

Barry Norton
accept rate: 19%

I assume implementers will provide value-added features beyond what is mandatory (you know - like adequate date handling ;). I'd also like to ensure I don't stumble into vendor lock-in. That calls for something like a Modernizr-style capability testing polyfills to hide platform idiosyncrasies.

(24 Jul '12, 22:57) Andrew Matthews ♦♦ Andrew%20Matthews's gravatar image

So firstly lets deal with the XPath/XQuery spec part:

"These functions are not available directly to users, and there is no requirement that implementations should actually provide these functions. For this reason, no namespace is associated with the op prefix."

As the quote you provided states the op: functions are not expected to be exposed to users, this is because they reflect the underlying implementation of general purpose operators like + and -

So in XPath/XQuery it would be legitimate to write (today - "P28D") to do that subtract operation.

Now the problem you have is that SPARQL defines what operator mappings must be supported in Section 11.3 (SPARQL 1.0) and Section 17.3 (SPARQL 1.1) - note the tables are identical between the specs the section numbers changed due to new features and document reorganization in the 1.1 spec.

In the XPath arithmetic section you will see that implementations are only required to support + and - for numerics but that they do support > and < for date times. Thus you can do your date comparison but not the date subtraction part with a standards compliant SPARQL implementation.

However the SPARQL specification does allow for implementations to add support for additional operand mappings, for example the latest ARQ versions support + and - arithmetic between date times and durations. If your implementation did support this then you could right your FILTER like so:

FILTER(?theDate > (?today - "P28D"^^xsd:duration) )

Therefore you can only do what you want if the implementation supports the appropriate extension. I'd talk to the Sesame and OWLIM developers to see whether this is supported (or just try it and see what happens). From dotNetRDF's point of view the query will look perfectly valid written this way so I don't think dotNetRDF gets in your way here but let me know if it does.

permanent link

answered 24 Jul '12, 12:08

Rob%20Vesse's gravatar image

Rob Vesse ♦
accept rate: 29%


FWIW Sesame/OWLIM currently do not support + and - on datetimes and durations. There is an outstanding feature request for this functionality though.

(24 Jul '12, 16:57) Jeen Broekstra ♦ Jeen%20Broekstra's gravatar image

Hi Jeen, Do you know whether the feature is likely to be given any priority?

FWIW, I suspect most devs use date arithmetic very frequently in app development - only time will tell whether it appears more or less often in SPARQL queries, but I don't see any reason why not.

(24 Jul '12, 23:08) Andrew Matthews ♦♦ Andrew%20Matthews's gravatar image

At the moment, the feature is not given very high priority because we have received very few requests from the user community about it. If that changes, it will become more important, obviously.

Moreover, if someone is keen to try and implement this him/herself and provide a patch, we'd be happy to integrate it. Integration into the SPARQL engine isn't particularly difficult, it's getting the intricacies of datetime/duration arithmetic right that makes this time-consuming.

(25 Jul '12, 00:43) Jeen Broekstra ♦ Jeen%20Broekstra's gravatar image

finding out what functions are supported by a triple store

As a more general and slightly-off-topic but somehow somewhat related answer to the general thrust of the question ...

SPARQL 1.1 Service Descriptions will (hopefully) standardise some standard vocabulary for SPARQL endpoints to advertise their wares, including supported features like functions and extended functions.

This is more of a "watch this space" answer, since I don't know if (m)any endpoints are currently making such descriptions available yet.

permanent link

answered 24 Jul '12, 22:04

Signified's gravatar image

Signified ♦
accept rate: 37%


What I really need is a polyfill so I don't have to write queries against a lowest common denominator subset of the (de facto) standard. I'm not sure how that could be done in a platform independent way given the diversity of the platforms concerned.

(24 Jul '12, 23:12) Andrew Matthews ♦♦ Andrew%20Matthews's gravatar image

Andrew, why not do today.subtractDays(28) in your host language, then interpolate it in the query?

permanent link

answered 10 Aug '12, 09:00

Vladimir%20Alexiev's gravatar image

Vladimir Ale...
accept rate: 9%

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:


question asked: 24 Jul '12, 06:53

question was seen: 1,750 times

last updated: 31 Oct '12, 10:18