11

是否可以使用 SPARQL 查询定义资源(来自 DBpedia)?我想要有类似 TBox 和 ABox 的东西,它们在语义网的(概念)聚类方法:问题和应用程序(幻灯片 10-11)中显示。例如,对于 DBpedia 资源Stephen King,我想要:

Stephen_King : Person ⊓ Writer ⊓ Male ⊓ …(最具体的类)

4

1 回答 1

12

您可以使用如下查询来询问斯蒂芬金是实例的类,这些类没有斯蒂芬金也是实例的子类。这似乎与“最具体的类”的概念非常吻合。但是,由于(据我所知)没有附加到 DBpedia SPARQL 端点的推理器,因此可能存在可以推断但未明确存在于数据中的子类关系。

select distinct ?type where { 
   dbr:Stephen_King a ?type .
  filter not exists { 
    ?subtype ^a  dbr:Stephen_King ;
             rdfs:subClassOf ?type .
  }
}

SPARQL 结果

实际上,由于每个类都是一个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 )
  }
}

SPARQL 结果

如果你真的想要一个像这些幻灯片中显示的结果字符串,你可以使用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

SPARQL 结果

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
于 2013-10-28T17:33:23.317 回答