Search code examples
sparqlwikidata

How to get a label's gender for non-english languages in Wikidata


I was wondering how we can get the gender of Wikidata results. For example

SELECT ?s ?sLabel 
WHERE
{
  ?s wdt:P31 wd:Q6256 ; rdfs:label ?sLabel .
   FILTER (lang(?sLabel) = 'fr') .
  } limit 10

I want to get not only the labels in French but also their gender, like this

Canada        Masculin
Bangladesh    Masculin
Norvège       Feminin

Is there anyway to do this using Wikidata queries?


Solution

  • SELECT ?country_label ?language_code ?gender_label {
      ?s wdt:P31 wd:Q6256 ;
         rdfs:label ?country_label .
      FILTER (lang(?country_label) = ?language_code)
      ?lexeme ontolex:sense?/wdt:P5137 ?s ;
              dct:language/wdt:P424 ?language_code .
      OPTIONAL { 
         ?lexeme wdt:P5185 ?gender .
         ?gender rdfs:label ?gender_label .
         FILTER (lang(?gender_label) = ?language_code)
      }
    } VALUES (?language_code) {('de')}
    

    Try it

    More info: https://www.wikidata.org/wiki/Wikidata:Lexicographical_data