使用DBpedia在两个维基百科类别之间的常见超类别

时间:2014-09-21 15:52:52

标签: sparql jena wikipedia dbpedia

我有以下SPARQL查询,它应该检索Category:Computer_science类别和Category:German_scientists

之间的常见类别
SELECT DISTINCT ?subject WHERE {
?subject <http://purl.org/dc/terms/subject> ?cat1, ?cat2 .
?cat1 skos:broader? / skos:broader? / skos:broader?         
  <http://dbpedia.org/resource/Category:Computer_science> .     
?cat2 skos:broader? / skos:broader? / skos:broader?
  <http://dbpedia.org/resource/Category:German_scientists>.
} LIMIT 10

我需要获得最接近他们的类别或者两个类别的最短路径,我该怎么做?例如,如何在(computer_science)和(German_scientists)之间的每个常见类别之间获得长度?

2 个答案:

答案 0 :(得分:3)

Virtuoso,为DBpedia数据提供服务的端点支持对属性路径的非标准SPARQL扩展:而不仅仅是p*p+p?,表示路径为Virtuoso长度分别为“零或更多”,“一个或多个”和“零或一个”,也支持p{m,n},意思是长度“至少为m且最多为n”的路径。通过尝试n = 0并增加m值的以下查询,我开始得到m = 4的结果:

prefix category: <http://dbpedia.org/resource/Category:>

select distinct ?super where {
  ?super (^skos:broader){0,4} category:Computer_science, category:German_scientists
}
super
-----------------------------------------------
http://dbpedia.org/resource/Category:Technology
http://dbpedia.org/resource/Category:Science

答案 1 :(得分:0)

为澄清起见::查询是以下答案的PREFIX版本,遵循当前规范:

PREFIX dbpedia: <http://dbpedia.org/resource/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dbc: <http://dbpedia.org/resource/Category:>
select distinct ?super where {
  ?super (^skos:broader){0,4} dbc:Computer_science, dbc:German_scientists
} 

SPARQL RESULTS

super
--------------------------------------------
http://dbpedia.org/resource/Category:Science_and_technology