Grouping data by month in SPARQL?

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

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

Is it possible. If so, how to do it?

+4
source share
1 answer

In SPARQL 1.1, there is a month () function ( http://www.w3.org/TR/sparql11-query/#func-month ) that extracts a month from ISO dates.

you can group by month using the GROUP BY keyword, for example:

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

The only small problem is that for SPARQL systems you do not need to process xsd: date data types, just xsd: dateTime, but many of them will handle them correctly.

+5
source

Source: https://habr.com/ru/post/1400406/


All Articles