Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve aliases from wikidata

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

like image 874
Lupanoide Avatar asked Nov 14 '16 16:11

Lupanoide


2 Answers

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.

like image 76
Finn Årup Nielsen Avatar answered Oct 31 '22 11:10

Finn Årup Nielsen


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
like image 5
Michail Michailidis Avatar answered Oct 31 '22 12:10

Michail Michailidis