【问题标题】:return full wikipedia page for a query using dbpedia使用 dbpedia 返回完整的维基百科页面以进行查询
【发布时间】:2015-02-23 17:31:28
【问题描述】:

我正在使用以下代码来检索给定查询的消歧页面。

#disambiguation function
def disambiguation(name, sparql):
  query = "SELECT DISTINCT ?syn WHERE { { ?disPage dbpedia-owl:wikiPageDisambiguates <http://dbpedia.org/resource/"+name+"> . ?disPage dbpedia-owl:wikiPageDisambiguates ?syn . }  UNION {<http://dbpedia.org/resource/"+name+"> dbpedia-owl:wikiPageDisambiguates ?syn . } }"
  sparql.setQuery(query)
  sparql.setReturnFormat(JSON)  
  results_list = sparql.query().convert()
  return results_list

问题:

是否可以为 results_list 中的每个元素返回完整的维基百科页面?

【问题讨论】:

  • "是否可以为 results_list 中的每个元素返回完整的维基百科页面?"你是什​​么意思“返回完整的维基百科页面”? DBpedia 不存储维基百科页面;它存储从中提取的数据。不过,您可以从相应的 DBpedia 资源中检索信息。
  • 您可能会发现Retrieving properties of redirected resource 很有帮助。
  • 我实际上想检索整个维基百科页面。例如:当我找到不同语言的名称时,我想转到相应的维基百科页面并检索其相应的页面
  • 您在问题中没有提到任何关于 Go 的内容;你只要求 SPARQL 和 Python。
  • 纠正我。如果我返回相应维基百科页面的链接,那么我可以正确检索那里的文本吗?

标签: python sparql dbpedia


【解决方案1】:

简化您的查询

SELECT DISTINCT ?syn WHERE {
  { ?disPage dbpedia-owl:wikiPageDisambiguates <http://dbpedia.org/resource/"+name+"> .
    ?disPage dbpedia-owl:wikiPageDisambiguates ?syn . }
  UNION
  { <http://dbpedia.org/resource/"+name+"> dbpedia-owl:wikiPageDisambiguates ?syn . }
}

这个查询可以更简洁地写成

select distinct ?syn where {
  ?syn (dbpedia-owl:wikiPageDisambiguates|^dbpedia-owl:wikiPageDisambiguates)* dbpedia:name
}

此查询表示通过 dbpedia-owl:wikiPageDisambiguates 属性的路径在任意方向查找连接到 dbpedia:name 的所有内容。

获取维基百科文章 URL

I actually wanted to retrieve the whole wikipedia page. For example: When I find a name in a different language I want to Go to the corresponding wikipedia page and retrieve its corresponding page

如果您确实想要检索页面(使用其他库或任何您拥有的库),那么您只需要获取 Wikipedia 文章 URL。这就是 foaf:isPrimaryTopicOf 属性的值。例如,如果您查看 Johnny Cash 的属性值,您会看到

http://dbpedia.org/resource/Johnny_Cash foaf:isPrimaryTopicOf http://en.wikipedia.org/wiki/Johnny_Cash

基于此,听起来您希望查询更像:

select distinct ?page where {
  ?syn (dbpedia-owl:wikiPageDisambiguates|^dbpedia-owl:wikiPageDisambiguates)* dbpedia:name ;
       foaf:isPrimaryTopicOf ?page

}

那么 ?page 的每个值都应该是一个可以下载的维基百科文章 URL。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-26
相关资源
最近更新 更多