Page MenuHomePhabricator

(MS 6) create SPARQL for date queries
Closed, ResolvedPublic

Description

if buildQuery is called with a QueryRepresentation that includes a date condition, it produces the correct SPARQL depending on the precision.

IMPORTANT: The queries for month and year precision need to have the end part of their time interval calculated. For months this may include wrapping around the year.

Query Examples:
Something happened on a day https://w.wiki/34zC:

# day -> precision === 11
SELECT ?item ?itemLabel
WHERE
{
  ?item p:P585/psv:P585/wikibase:timeValue "+1789-07-14T00:00:00Z"^^xsd:dateTime.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

something happened in a month https://w.wiki/34zD:

# month -> precision === 10
SELECT ?item ?itemLabel
WHERE
{
  ?item p:P585/psv:P585 ?timeValue.
  
  # has at least the given precision i.e. month
  ?timeValue wikibase:timePrecision ?precision. hint:Prior hint:rangeSafe true. # important for performance
  FILTER(?precision >= 10) # month precision
  
  # points to the correct month
  ?timeValue wikibase:timeValue ?dateTime. hint:Prior hint:rangeSafe true. # important for performance
  FILTER("1789-07-00"^^xsd:dateTime <= ?dateTime &&
         ?dateTime < "1789-08-00"^^xsd:dateTime) # must be manually calculated
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

something happened in a year https://w.wiki/34zE:

# year -> precision === 9
SELECT ?item ?itemLabel
WHERE
{
  ?item p:P585/psv:P585 ?timeValue.
  
  # has at least the given precision i.e. year
  ?timeValue wikibase:timePrecision ?precision. hint:Prior hint:rangeSafe true. # important for performance
  FILTER(?precision >= 9) # year precision
  
  # points to the correct month
  ?timeValue wikibase:timeValue ?dateTime. hint:Prior hint:rangeSafe true. # important for performance
  FILTER("1789-00-00"^^xsd:dateTime <= ?dateTime &&
         ?dateTime < "1790-00-00"^^xsd:dateTime) # must be manually calculated
  
  SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en" }
}

Event Timeline

amy_rc renamed this task from create SPARQL for date queries to (MS 6) create SPARQL for date queries.Wed, Mar 17, 12:27 PM

Change 677633 had a related patch set uploaded (by Michael Große; author: Michael Große):

[wikidata/query-builder@master] Build SPARQL for date queries

https://gerrit.wikimedia.org/r/677633

Change 677633 merged by jenkins-bot:

[wikidata/query-builder@master] Build SPARQL for date queries

https://gerrit.wikimedia.org/r/677633

Change 678048 had a related patch set uploaded (by Ladsgroup; author: Ladsgroup):

[wikidata/query-builder@master] Clean up date sparql tests

https://gerrit.wikimedia.org/r/678048

Change 678048 merged by jenkins-bot:

[wikidata/query-builder@master] Clean up date sparql tests

https://gerrit.wikimedia.org/r/678048