如何使用Wikidata dump从Wikidata页面/Q号获取关联的(英语)Wikipedia页面? [英] How to get associated (English) Wikipedia page from Wikidata page / Q number using Wikidata dump?
问题描述
仅对于文本而言,Wikidata转储中的单个项目包含多个名称:
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 .
在本文的Wikidata页面上( http://www.wikidata.org/entity/Q26 ),其中哪一个(如果有的话)对应于相关的(英文)维基百科页面上使用的规范化名称?
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?
推荐答案
获取谓词为schema:partOf且对象为所需维基百科的三元组(例如,
Grab the triple in which the predicate is schema:partOf and the object is the wikipedia you want (for example, https://en.wikipedia.org/).
下面是使用Python的rdflib的示例:
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.
这篇关于如何使用Wikidata dump从Wikidata页面/Q号获取关联的(英语)Wikipedia页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!