Retrieve linked wikidata entities having a wikipedia page

痞子三分冷 提交于 2021-02-10 20:32:05

问题


I want to query wikidata by free text or by category, to return entities who has a corresponding wikipedia page.

For each page (or for a selected page) I want to fetch all the linked wikidata entities who have a corresponding wikipedia article.

Note that:

  • for each wikipedia page and linked pages, I want to fetch the corresponding Wikidata Id
  • a linked wikidata entity may exist on other wikipedias, not necessarily in the queried language

(e.g. a page in French History is available in multiple languages; I may have linked pages in French only as well as others multiple languages).

I cannot figure out which wikidata APIs to corresponding ones in wikipedia, to query linked articles, and how to query linked pages that exist even beyond a selected language.

I looked at:

https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI

https://stackoverflow.com/a/57983365/305883

https://www.mediawiki.org/wiki/API:Links

For example I may start with this sparql query:

SELECT ?item ?type ?itemLabel ?typeLabel WHERE {
 {
   SELECT ?item WHERE {
    SERVICE wikibase:mwapi {
      bd:serviceParam wikibase:endpoint "en.wikipedia.org" .
      bd:serviceParam wikibase:api "Generator" .
      bd:serviceParam mwapi:generator "search" .
      bd:serviceParam mwapi:gsrsearch "artificial intelligence" .
      bd:serviceParam mwapi:gsrlimit "max" .
      ?item wikibase:apiOutputItem mwapi:item .
    }
  } LIMIT 100
 }
 hint:Prior hint:runFirst "true".
 ?item wdt:P31|wdt:P279 ?type .
 SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} LIMIT 100

Could you show examples to expand or adapt this query ?

Could you suggest other references than https://www.mediawiki.org/wiki/Wikidata_Query_Service/User_Manual/MWAPI , for an extensive use to callout to Mediawiki API from SPARQL (so that I can exploit wikidata and wikipedia) ?

来源:https://stackoverflow.com/questions/58890582/retrieve-linked-wikidata-entities-having-a-wikipedia-page

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