是否可以使用SPARQL查询定义资源(来自DBpedia)?我希望在(Conceptual) Clustering methods for the Semantic Web: issues and applications (slides 10–11)中显示类似TBox和ABox的内容。例如,对于DBpedia资源Stephen King,我希望:
Stephen_King:人⊓作家⊓男⊓......(最具体的课程)
答案 0 :(得分:12)
您可以使用如下所示的查询来询问Stephen King所属的类,这些类没有子类,其中Stephen King也是一个实例。这似乎与“最具体的类”的想法完全一致。但是,因为(据我所知)没有任何理由附加到DBpedia SPARQL端点,可能存在可以推断的子类关系但是没有明确的存在于数据中。
select distinct ?type where {
dbr:Stephen_King a ?type .
filter not exists {
?subtype ^a dbr:Stephen_King ;
rdfs:subClassOf ?type .
}
}
实际上,由于每个类本身都是rdfs:subClassOf
,因此您可能希望在该查询中添加另一行,以排除?subtype
和?type
相同的情况:
select distinct ?type where {
dbr:Stephen_King a ?type .
filter not exists {
?subtype ^a dbr:Stephen_King ;
rdfs:subClassOf ?type .
filter ( ?subtype != ?type )
}
}
如果您确实需要像这些幻灯片中显示的那样的结果字符串,可以使用values
将变量绑定到dbr:Stephen_King
,然后使用一些分组和字符串连接来获得更好看的内容(有点):
select
(concat( ?person, " =\n", group_concat(?type; separator=" AND\n")) as ?sentence)
where {
values ?person { dbr:Stephen_King }
?type ^a ?person .
filter not exists {
?subtype ^a ?person ;
rdfs:subClassOf ?type .
filter ( ?subtype != ?type )
}
}
group by ?person
http://dbpedia.org/resource/Stephen_King =
http://dbpedia.org/class/yago/AuthorsOfBooksAboutWritingFiction AND
http://dbpedia.org/ontology/Writer AND
http://schema.org/Person AND
http://xmlns.com/foaf/0.1/Person AND
http://dbpedia.org/class/yago/AmericanSchoolteachers AND
http://dbpedia.org/class/yago/LivingPeople AND
http://dbpedia.org/class/yago/PeopleFromBangor,Maine AND
http://dbpedia.org/class/yago/PeopleFromPortland,Maine AND
http://dbpedia.org/class/yago/PeopleFromSarasota,Florida AND
http://dbpedia.org/class/yago/PeopleSelf-identifyingAsAlcoholics AND
http://umbel.org/umbel/rc/Artist AND
http://umbel.org/umbel/rc/Writer AND
http://dbpedia.org/class/yago/20th-centuryNovelists AND
http://dbpedia.org/class/yago/21st-centuryNovelists AND
http://dbpedia.org/class/yago/AmericanHorrorWriters AND
http://dbpedia.org/class/yago/AmericanNovelists AND
http://dbpedia.org/class/yago/AmericanShortStoryWriters AND
http://dbpedia.org/class/yago/CthulhuMythosWriters AND
http://dbpedia.org/class/yago/HorrorWriters AND
http://dbpedia.org/class/yago/WritersFromMaine AND
http://dbpedia.org/class/yago/PeopleFromDurham,Maine AND
http://dbpedia.org/class/yago/PeopleFromLisbon,Maine AND
http://dbpedia.org/class/yago/PostmodernWriters