从维基百科 API 中获取名人 [英] Fetch famous people from Wikipedia API

查看:42
本文介绍了从维基百科 API 中获取名人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 Wikipedia API 获取还活着的人,但我还没有想出如何去做.

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

我发现了这个问题,这和我的一样,到目前为止据我所知,唯一的方法是搜索只有birth_date 参数的人,我该怎么做?

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?

例如,如果我想搜索Ronaldo",我应该得到一个所有名为 Ronaldo 的还活着的人的列表.我唯一关心的数据是出生日期、姓名和姓氏,如果他们死了,最终的死亡日期.

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.

我唯一想到的是:

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.

推荐答案

请看下面的查询:

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

在维基数据上查询.

您可以在死亡日期添加过滤器以仅查看活着的人.

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

这篇关于从维基百科 API 中获取名人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆