10

I'm traying to get the regions of Italy in both Italian and English. I can get then in one laguage with this query...

PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?RegionIT ?RegionITLabel ?ISO_code ?Geo
{
?RegionIT wdt:P31 wd:Q16110;
wdt:P300 ?ISO_code; 
wdt:P625 ?Geo 
           SERVICE wikibase:label { bd:serviceParam wikibase:language "it"  }
}

ORDER BY ?regionITLabel

... but adding another language using the standard SPARQL syntax doesn't work.

Ivo Velitchkov
  • 2,361
  • 11
  • 21
  • Multiple labels using the label service: https://stackoverflow.com/questions/49118702/sparql-querying-wikidata-labels-for-more-than-one-language – Stanislav Kralin Mar 06 '18 at 11:10

2 Answers2

13

... but adding another language using the standard SPARQL syntax doesn't work.

How are you doing that? This works:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?RegionIT ?label (lang(?label) as ?label_lang)  ?ISO_code ?Geo
{
    ?RegionIT wdt:P31 wd:Q16110;
              wdt:P300 ?ISO_code; 
              wdt:P625 ?Geo ;
              rdfs:label ?label
}
order by ?RegionIT

Link to try query

To limit to just Italian and English filter on the lang:

PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX wikibase: <http://wikiba.se/ontology#>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wdt: <http://www.wikidata.org/prop/direct/>

SELECT DISTINCT ?RegionIT ?label ?ISO_code ?Geo
{
    ?RegionIT wdt:P31 wd:Q16110;
              wdt:P300 ?ISO_code; 
              wdt:P625 ?Geo ;
              rdfs:label ?label
    filter(lang(?label) = 'it' || lang(?label) = 'en')
}
order by ?RegionIT

Link to try query

Obviously that multiplies the number of results, one for each language. If that's an issue you can do:

...
rdfs:label ?label_it , ?label_en
filter(lang(?label_it) = 'it' && lang(?label_en) = 'en')
...

which is effectively what the language service does.

user205512
  • 8,798
  • 29
  • 28
  • Thanks. This indeed answers the question. My intention was to learn how to achieve it with `SERVICE wikibase:label` but that wasn't clear from the question. Yet, I'd appreciate any ideas about that. – Ivo Velitchkov Apr 06 '17 at 19:34
  • 3
    you can request several languages with `SERVICE wikibase:label` like so: `SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en" }`, but it's only a fallback mechanism, you will only get the first defined label from the requested languages, not one label per language. – maxlath Apr 06 '17 at 21:20
9

Let's list all countries in English and Russian.

#List of countries in English and Russian
SELECT ?country ?label_en ?label_ru
WHERE
{
    ?country wdt:P31 wd:Q6256.
    ?country rdfs:label ?label_en filter (lang(?label_en) = "en").
    ?country rdfs:label ?label_ru filter (lang(?label_ru) = "ru").
}

SPARQL query

This example was taken from the tutorial Research in programming Wikidata, section "Countries".