How do I set the language of a variable in SPARQL?

69 Views Asked by At

I know how to set the language of a literal: "foo"@en

But what about ?foo@en (which doesn't work)?

Context: I want to copy a bunch of labels set to en-gb into just en so they play better with the knowledge management tool I'm using. So something like this:

INSERT {
   ?subject skos:prefLabel ?object@en
} 

WHERE {
  ?subject skos:prefLabel ?object .
  FILTER (lang(?object) = "en-gb")
} 
1

There are 1 best solutions below

0
On

str allows you to get the lexical form of a language-tagged literal, and STRLANG allows you to specify the language tag of a literal.

CONSTRUCT { 
  ?subject skos:prefLabel ?label_en .
}

WHERE { 

  ?subject skos:prefLabel ?label_enGB . 
  FILTER (lang(?label_enGB) = "en-gb") .

  BIND( STRLANG(str(?label_enGB), "en") AS ?label_en ) .

}

Example:

  1. ?label_enGB: "foo"@en-gb
  2. str(?label_enGB): "foo"
  3. STRLANG(str(?label_enGB), "en"): "foo"@en