How to get associated (English) Wikipedia page from Wikidata page / Q number using Wikidata dump?

我的未来我决定 提交于 2019-12-13 04:03:42

问题


For @en text alone, a single item from the Wikidata dump contains multiple names:

<http://www.wikidata.org/entity/Q26> <http://www.w3.org/2000/01/rdf-schema#label> "Northern Ireland"@en .
<http://www.wikidata.org/entity/Q26> <http://www.w3.org/2004/02/skos/core#prefLabel> "Northern Ireland"@en .
<http://www.wikidata.org/entity/Q26> <http://schema.org/name> "Northern Ireland"@en .

On the Wikidata page for this article (http://www.wikidata.org/entity/Q26), which of these (if any) corresponds to the canonicalized name used on the associated (English) the Wikipedia page?


回答1:


Grab the triple in which the predicate is schema:partOf and the object is the wikipedia you want (for example, https://en.wikipedia.org/).

Here's an example using Python's rdflib:

>>> import rdflib
>>> g = rdflib.Graph()
>>> r = g.parse("https://www.wikidata.org/entity/Q26.nt")
>>> for s, p, o in g:
...     if p == rdflib.URIRef('http://schema.org/isPartOf') and o == rdflib.URIRef('https://en.wikipedia.org/'):
...             print(s)
... 
https://en.wikipedia.org/wiki/Northern_Ireland

You can adjust this approach according to whatever parser you're using, of course.



来源:https://stackoverflow.com/questions/48332827/how-to-get-associated-english-wikipedia-page-from-wikidata-page-q-number-usi

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