问题
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