问题描述
我正在使用DBpedia在R中使用SPARQL获取页面类别。但是,它存在一些问题。我正在使用的源代码:
I am using DBpedia to getting page category using SPARQL in R. However, there are having some problems on it. Source code I am using:
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT ?categoryUri ?categoryName WHERE {
<http://dbpedia.org/resource/xxx> dcterms:subject ?categoryUri.
## xxx are random words (e.g. Agree, Film, Work, Plan...)
?categoryUri rdfs:label ?categoryName.
FILTER (lang(?categoryName) = "en")
}
问题是:
-
如果单词需要重定向(例如,同意->协议),则无法检索类别
Category cannot be retrieved if the words need to be redirected (e.g. Agree -> Agreement)
上面的源代码无法使用歧义页面,因为单词类别(例如工作)中有很多子页面
Disambiguation pages cannot be used from the above source code, because there are so many sub-pages within the category of word (e.g. Work)
那么,如何解决以上问题?如果有人可以提供帮助,我将非常感激!!!
So, how can I resolve the above problems? I am really appreciate if anyone can offer your help!!!
推荐答案
SPARQL只会执行您编写的内容,所以没有魔术。如果某些资源:s
可能通过属性:p
连接到其他资源,则添加三元模式:s:p?o。
-有时您甚至可能考虑使用属性路径,以解决:p $ c $的传递闭包的问题。 c>,即
:s:p *?o。
。
SPARQL does only do what you write, so there is no magic behind. If some resource :s
is possibly connected to others by a property :p
, add a triple pattern :s :p ?o .
- sometimes you might even consider to use a property path in case of the resolution of the transitive closure of :p
, i.e. :s :p* ?o .
.
已解决重定向:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT * WHERE
{ <http://dbpedia.org/resource/Agree> (dbo:wikiPageRedirects)* ?page
OPTIONAL
{ ?page dcterms:subject ?categoryUri}
}
请注意 OPTIONAL
子句,这在这里是必需的,因为并非DBpedia中的所有资源都属于一个类别。
Note the OPTIONAL
clause, which is necessary here because not all resources in DBpedia belong to a category.
包括歧义页面:
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT * WHERE
{ <http://dbpedia.org/resource/Agree> (dbo:wikiPageRedirects)*/(dbo:wikiPageDisambiguates)* ?page
OPTIONAL
{ ?page dcterms:subject ?categoryUri}
}
这篇关于DBpedia使用sparql获取页面类别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!