从维基百科API中获取名人

问题描述 投票:1回答:3

我正试图从维基百科API中获取仍然活着的人,但我还没弄明白该怎么做。

我发现this question与我的相同,据我所知,唯一的方法是搜索只有birth_date参数的人,我该怎么做呢?

例如,如果我想搜索“罗纳尔多”,我应该列出一个名为罗纳尔多的人,他们还活着。我唯一关心的数据是出生日期,姓名和姓氏,如果死亡,最终死亡日期。

我想出的唯一一件事是:

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

但是它没有做我想做的工作,因为它只获得了传记和链接。

ajax rest api wikipedia-api mediawiki-api
3个回答
3
投票

您可以在此处执行以下查询:https://query.wikidata.org/以获取您感兴趣的详细信息。

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 

2
投票

请查看以下查询:

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.

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


0
投票

使用structured data query service。通用API没有提供过多的过滤方式。

© www.soinside.com 2019 - 2024. All rights reserved.