Sparnatural icon indicating copy to clipboard operation
Sparnatural copied to clipboard

Use the YEAR SPARQL function in TimeProperty-Year widget

Open ch-sander opened this issue 8 months ago • 6 comments

The TimeProperty-Year widget renders a filter like so:

FILTER((?date_1727_4 >= "1599-12-31T23:06:33Z"^^xsd:dateTime) && (?date_1727_4 <= "1650-12-31T23:06:31Z"^^xsd:dateTime))

However, my ?date_1727_4 is "1616"^^xsd:gYear

This clearly fails. What would work is:

FILTER(YEAR(?date_1727_4) >= 1599 && YEAR(?date_1727_4) <= 1650)

Wouldn't make sense to render the SPARQL like this for TimeProperty-Year generally? It should work for all xsd date formats!

ch-sander avatar May 07 '25 07:05 ch-sander

This clearly fails.

Well, it is not that clear. Date datatypes have a semantic, and triplestores should be able to compare xsd:dateTime with xsd:gYear. I raised the concern a few years ago to GraphDB support, and now GraphDB supports this. For example try this query:

PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
select ?x where {
    VALUES (?x ?pointInTime) {
        (<http://example.fr/1> "2012"^^xsd:gYear)
        (<http://example.fr/2> "2012-06-01"^^xsd:date)
        (<http://example.fr/3> "2012-06-01T23:06:33Z"^^xsd:dateTime)
    }
    FILTER(?pointInTime < "2015-01-01T00:00:00Z"^^xsd:dateTime)
} limit 100

In GraphDB you correctly get the 3 results, even though their associated pointInTime is expressed with 3 different datatypes. Try it on your triplestore to see the behavior.

The point is that date comparisons in SPARQL is defined in terms of xsd:dateTime only (https://www.w3.org/TR/sparql11-query/#OperatorMapping) this is why we set all date criterias to xsd:dateTime)

tfrancart avatar May 07 '25 08:05 tfrancart

But re-reading your suggestion, I think you are right that using the YEAR operator would be more robust - we would not depend on the triplestore semantics

tfrancart avatar May 07 '25 08:05 tfrancart

I use oxigraph. Maybe @Tpt will implement this in the future, too

ch-sander avatar May 07 '25 08:05 ch-sander

Yes, Oxigraph currently does not implement xsd:gYear < xsd:dateTime. But it's definitely something that is easy to add.

Tpt avatar May 08 '25 07:05 Tpt

Checking back on this, has oxigraph meanwhile maybe enhanced xsd:gYear parsing @Tpt or Sparnatural implemented YEAR() parsing @tfrancart ?

Our project and its use of both would greatly benefit 😁

ch-sander avatar Jul 28 '25 06:07 ch-sander

https://github.com/oxigraph/oxigraph/releases/tag/v0.5.0-beta.2

I guess this will do the trick @Tpt . Great!

ch-sander avatar Aug 07 '25 19:08 ch-sander