'Get the @language tag from a SPARQL request
I use http://dbpedia.org/sparql to do this request:
PREFIX res: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?trad
where{
res:Apple
rdfs:label ?trad
}
which returns me the following result:
How do I get the language tag (@ar, @es, @fr) in a separated column?
I've seen on w3.org something that could maybe help:
Any ideas?
Solution 1:[1]
SPARQL documentation contains everything about SPARQL, thus, it's always the most appropriate source to dig into.
In your case, the part about the language of an RDF term is useful.
PREFIX res: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?trad (lang(?trad) as ?lang) WHERE {
res:Apple rdfs:label ?trad
}
Solution 2:[2]
To assemble "@fr", "@es", and "@ar" language tag values into one table, with separated columns, try the SPARQL UNION keyword, and FILTER with the language function on each variable:
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?french ?spanish ?arabic
where{ { dbr:Apple rdfs:label ?french FILTER ( lang(?french) = "fr" ) }
UNION
{ dbr:Apple rdfs:label ?spanish FILTER ( lang(?spanish) = "es" ) }
UNION
{ dbr:Apple rdfs:label ?arabic FILTER ( lang(?arabic) = "ar" ) }}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | UninformedUser |
Solution 2 | m_lane_nw |