Search code examples
sparqlwikidata

Get alias values from Wikidata for a given property?


For a given property like 'occupation (P106)', I want to retrieve all its aliases like: profession, job, work, career, employment, craft. All of this is present on the properties wikidata page, under 'Also known as'. How can I go about retrieving this using SPARQL? I tried using the following query.

  SELECT ?predicate ?object WHERE {
  wdt:P106 wdt:P1449 ?predicate .  //Nickname
  wdt:P106 wdt:P734 ?predicate .   //Family Name
  wdt:P106 wdt:P735 ?predicate .  //Given Name
  wdt:P106 skos:altLabel ?predicate . 
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}

Solution

  • SELECT ?altLabel
    {
     VALUES (?wd) {(wd:P106)}
     ?wd skos:altLabel ?altLabel .
     FILTER (lang(?altLabel) = "en")
    }
    

    or

    SELECT ?altLabel
    {
     VALUES (?wdt) {(wdt:P106)}
     ?wd wikibase:directClaim ?wdt .
     ?wd skos:altLabel ?altLabel .
     FILTER (lang(?altLabel) = "en")
    }
    

    These paragraphs provide some explanation:


    Update

    You still could use the label service:

    SELECT ?wdAltLabel
    {
     VALUES (?wdt) {(wdt:P106)}
     ?wd wikibase:directClaim ?wdt .
     SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
    }