I’m trying to write a SPARQL query which returns all terms in one or more vocabularies, and their labels in selected language, for a web interface which needs to show a drop-down selection in a given language.
The query of a single vocabulary with English labels looks something like this:
SELECT DISTINCT ?term ?label
FROM <https://some.graph>
WHERE {
?term a skos:Concept .
?term skos:inScheme <https://example/vocabulary/> .
?term skos:prefLabel ?label .
FILTER (langMatches(lang(?label), "en"))
}
What I would like to achieve is, given a list of language identifiers, to build a query for several languages at once, and capture the language identifier in the results - so that there is a ?lang
field containing the identifier appropriate to the label.
Something like this might work for two languages, say EN
and FR
:
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
SELECT DISTINCT ?term ?label ?lang
FROM <https://some.graph>
WHERE {
?term
a skos:Concept ;
skos:inScheme <https://example/vocabulary/> ;
skos:prefLabel ?label .
BIND (lang(?label) AS ?lang)
FILTER (langMatches(lang(?label), "en") || langMatches(lang(?label), "fr"))
}
The problem I have is that BIND seems not to be supported on the version of Virtuoso I currently have access to (6.1 VOS on Ubuntu). Is there a way to do this which works with this version?