0

I am trying to get the label of a wikidata item using its id. My sparql looks like:

SELECT ?label
WHERE
{
  wd:Q245068 rdfs:label ?label .
  FILTER (langMatches( lang(?label), "EN" ) )
}

When I run this, I get 3 results that are all "comedian".

dupes

Why does this return multiple results for the same language/id?

micah
  • 7,596
  • 10
  • 49
  • 90

1 Answers1

1

Yes, that's funny...

The reason is obvious if you just check the item

comedy labels

"English" means three different things (here labeled in German, the international language of high comedy): Canadian, British, and American English. You get all three.

Here's how to avoid it:

SELECT DISTINCT ?label
WHERE {
    wd:Q245068 rdfs:label ?label .
    FILTER (langMatches( lang(?label), "EN" ) )
}

Or, use a more specific language code:

FILTER (langMatches( lang(?label), "EN-GB" ) )

But that runs the risk of not returning any label if it isn't set in the particular variety you've chosen. You can get around that, but really at the end you are just reimplementing the standard service that exists for exactly this purpose:

# just ad "Label" to get the label in the SELECT
SELECT ?item ?itemLabel
WHERE {
    ?item wet:P31 Q5. 

    # WITH THIS SERVICE 
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Matthias Winkelmann
  • 15,870
  • 7
  • 64
  • 76
  • Interesting. And thank you I was just about to ask if you knew how to limit it to just `en-gb`. – micah Aug 18 '21 at 19:15
  • 1
    or `filter(lang(?label) = "en" )` as many people do but then it will fail if one the the English "flavours" is used as language tag - which to be fair is rarely used as far as I can tell from datasets I got in touch with – UninformedUser Aug 18 '21 at 19:17