How to capture the language identifiers of labels along with them in result fields?

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>
  ?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: <>
SELECT DISTINCT ?term ?label ?lang
FROM <https://some.graph>
    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?

Hi Wu-Lee,

BIND support and enhancements are a version 7.x and higher feature re Virtuoso’s SPARQL support.


As it happens, I find that a query response as JSON includes the language ID as a separate attribute, which does the job for me.

However, your answer suggests that if this weren’t the case, I’d be stuck without upgrading?