Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SPARQL entity lists inside select queries

Tags:

sparql

In the following DBpedia query, is there a way to consolidate the UNIONs into a single pattern?

PREFIX prop: <http://resedia.org/ontology/>
PREFIX res: <http://resedia.org/resource/>
SELECT DISTINCT ?language ?label 
WHERE { 
  {res:Spain prop:language ?language} 
    UNION
  {res:France prop:language ?language}
    UNION
  {res:Italy prop:language ?language}
  ?language rdfs:label ?label .
  FILTER langMatches(lang(?label), "en") 
}

The SPARQL spec mentions something about RDF collections but I don't really understand what it's describing. It seemed like the following syntax should work, but it didn't.

PREFIX prop: <http://resedia.org/ontology/>
PREFIX res: <http://resedia.org/resource/>
SELECT DISTINCT ?language ?label 
WHERE { 
  (res:Spain res:France res:Italy) prop:language ?language
  ?language rdfs:label ?label .
  FILTER langMatches(lang(?label), "en") 
}

Is there a way to define a list (or "multiset", or "bag") of URIs like this inside a SELECT query?

like image 312
wynz Avatar asked Feb 18 '26 22:02

wynz


1 Answers

In SPARQL 1.1 you can do

SELECT DISTINCT ?language ?label 
WHERE {
  ?country prop:language ?language .
  ?language rdfs:label ?label .
  VALUES ?country { res:Spain res:France res:Italy }
  FILTER langMatches(lang(?label), "en") 
}
like image 102
Blake Regalia Avatar answered Feb 21 '26 14:02

Blake Regalia



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!