How to retrieve aliases from wikidata
Asked Answered
A

3

6

I'm trying to retrieve some information from Wikidata and I have found interesting to collect the aliases of the voices. For examples Francesco Totti is also known as il Capitano or er Pupone : wikidata of Francesco Totti

I'm trying to retrieve all the serie a's football players with this sparql query:

SELECT ?subject ?nomeLabel ?cognomeLabel ?subjectLabel WHERE {
  ?subject wdt:P31 wd:Q5.

  ?subject p:P54 ?team .
  ?team ps:P54 wd:""" + team_code +""" .
  FILTER NOT EXISTS { ?team pq:P582 ?end
    }
OPTIONAL{
  ?subject wdt:P735 ?nome .
  ?subject wdt:P734 ?cognome .
  }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it". }
}
ORDER BY (?cognomeLabel)

How I can modify my query to take also the aliases? Thanks

Ardin answered 14/11, 2016 at 16:29 Comment(0)
G
11

I have attempted a query with various labels. Here just for Roma:

SELECT distinct ?subject ?subjectLabel ?nomeLabel ?cognomeLabel ?nickname ?alternative ?subjectAltLabel WHERE {
  ?subject wdt:P31 wd:Q5.
  ?subject p:P54 ?team .
  ?team ps:P54 wd:Q2739 .
  FILTER NOT EXISTS { ?team pq:P582 ?end . }
  OPTIONAL { ?subject wdt:P735 ?nome . }
  OPTIONAL { ?subject wdt:P734 ?cognome . }
  OPTIONAL { ?subject wdt:P1449 ?nickname . }
  OPTIONAL { ?subject skos:altLabel ?alternative . }
  SERVICE wikibase:label { bd:serviceParam wikibase:language "it,en,fr". }
}
ORDER BY (?cognomeLabel) 

I believe the P1449 property should be the most appropriate property to store an alias/nickname, but it does not seem to be used that much for football players. I just added "il Capitano" to Francesco Totti. Beyond that one there does not seem to be other nicknames for Roma players.

The "Also known as" label (in the right column) is not necessarily the nickname, but may be a spelling variation.

Galvanism answered 14/11, 2016 at 17:45 Comment(1)
It works! It was from a long time that I have tried to find a solution. Thanks a lot Finn!Ardin
B
5

Something more generic if someone is interested in all properties that will return only the english also known as:

SELECT ?property ?propertyLabel ?propertyDescription (GROUP_CONCAT(DISTINCT(?altLabel); separator = ", ") AS ?altLabel_list) WHERE {
    ?property a wikibase:Property .
    OPTIONAL { ?property skos:altLabel ?altLabel . FILTER (lang(?altLabel) = "en") }
    SERVICE wikibase:label { bd:serviceParam wikibase:language "en" .}
 }
GROUP BY ?property ?propertyLabel ?propertyDescription
LIMIT 5000
Brummett answered 6/3, 2018 at 11:24 Comment(0)
C
4

Another more simple example for male actors with itemAltLabel :

#Male Actors
SELECT ?item ?itemLabel ?itemAltLabel
WHERE 
{
    ?item wdt:P21 wd:Q6581097.
  ?item wdt:P106 wd:Q33999.
  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
Calamus answered 14/10, 2020 at 15:4 Comment(1)
that last line should be SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }Briefcase

© 2022 - 2024 — McMap. All rights reserved.