Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grouping data by month in SPARQL?

Tags:

date

rdf

sparql

Is it possible to extract month element from the date using SPARQL and group results by it. I am using W3 time ontology for defining dates in format "2009-12-31"^^xsd:date.

So in case of "2009-12-31"^^xsd:date I would like to extract 12.

Is this even possible. If so, how can do that?

like image 597
gintas Avatar asked Mar 08 '12 15:03

gintas


1 Answers

In SPARQL 1.1 there's a month() function (http://www.w3.org/TR/sparql11-query/#func-month) which extracts the month from ISO dates.

you can group by month using the GROUP BY keyword, as in:

SELECT ?mon SUM(?val)
WHERE {
  ?x :date ?date ;
     :value ?val .
}
GROUP BY (month(?date) AS ?mon)

The only slight problem is that SPARQL systems aren't required to process xsd:date datatypes, just xsd:dateTime, but many will handle it correctly.

like image 50
Steve Harris Avatar answered Oct 16 '22 07:10

Steve Harris