range function in sparql

1.4k views Asked by At

I need all years in a given range as values in sparql (especially for the sesame implementation).

Is there any way to "generate" new numbers in sparql like:

SELECT (RANGE(2,10) AS ?numbers)
WHERE{}
1

There are 1 answers

0
Roman Susi On

Without taking a deeper look, one naive answer in the spirit of RDF is to materialize the numbers and then use FILTER for the range. In other words, just insert them into the graph:

  ex:year ex:anumber "1900"^^xsd:integer .
  ex:year ex:anumber "1901"^^xsd:integer .
  ...  
  ex:year ex:anumber "2100"^^xsd:integer .

And have a pattern in the WHERE section:

  SELECT ?number
  WHERE {
      ex:year ex:number ?number .
      FILTER (?number < 2020)
      FILTER (?number > 1999)
  }

As commented above, it is hard to imagine a use case for "knowing" numbers: what you get will be cross-product with everything else in the query, unless getting numbers is the only purpose of the query or some filtering being applied (in the latter case there is no need to generate numbers at all).