Fetch famous people from Wikipedia API

感情迁移 提交于 2019-12-20 03:54:24

问题


I'm trying to fetch people who are still alive from Wikipedia API but I haven't figured out how to do it.

I found this question which is the same as mine and as far as I understood the only way is to search for people who only have the birth_date parameter, how do I actually do that?

For instance, if I wanted to search for "Ronaldo", I should get a list of all people called Ronaldo who are still alive. The only data I care about are date of birth, name and surname, and eventually date of death if they die.

The only thing I came up with is this:

https://en.wikipedia.org/w/api.php?action=opensearch&search=%22Ronaldo%22&format=json

But it doesn't do the job that I'd like it to do because it only gets the biography and link.


回答1:


Please look at the following query:

SELECT distinct ?item ?itemLabel ?itemDescription (SAMPLE(?DR) as ?DR) (SAMPLE(?RIP) as ?RIP) (SAMPLE(?image)as ?image) (SAMPLE(?article)as ?article) WHERE {
  ?item wdt:P31 wd:Q5.
  ?item ?label "Ronaldo"@en.  
  ?article schema:about ?item .
  ?article schema:inLanguage "en" .
  ?article schema:isPartOf <https://en.wikipedia.org/>.  
  OPTIONAL{?item wdt:P569 ?DR .} # P569 : Date of birth
  OPTIONAL{?item wdt:P570 ?RIP .}     # P570 : Date of death
  OPTIONAL{?item wdt:P18 ?image .}     # P18 : image  

  SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }    
}
GROUP BY ?item ?itemLabel ?itemDescription

Query on Wikidata.

You can add Filter on death date to see only alive people.




回答2:


You can execute the following query here: https://query.wikidata.org/ in order to fetch the details you are interested in.

SELECT  DISTINCT ?id ?idLabel (SAMPLE(?birth) as ?birth_date) 
 (SAMPLE(?death_date) as ?dateOfDeath)  WHERE {
?id wdt:P31 wd:Q5.
?id wdt:P569 ?birth .
OPTIONAL{?id wdt:P570 ?death_date .}
SERVICE wikibase:label { 
bd:serviceParam wikibase:language "en".
?id rdfs:label ?idLabel .
}?id ?label "Ronaldo"@en. 
}
GROUP BY ?id ?idLabel 



回答3:


Use the structured data query service. The generic API does not provide much in the way of filtering.



来源:https://stackoverflow.com/questions/48946820/fetch-famous-people-from-wikipedia-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!