如何使用SPARQL获取三个类之间通用的所有语义数据?

时间:2013-12-19 10:52:17

标签: sparql semantics

我有一个场景,用户可以选择多个类,我需要构建动态SPARQL查询来获取满足所有选定类之间存在的所有关系(如果有)的所有数据。我如何实现这一目标?

假设用户选择三个类 - Population,Drugname,SideEffects。现在他试图找到这三个类之间存在的所有常见数据。如何构建SPARQL查询来实现此目的?我需要一个连接这三个类的示例SPARQL查询。

1 个答案:

答案 0 :(得分:2)

如果要检索某些资源具有相同值的属性(因此您可能也希望检索该值),可以使用如下查询:

select ?p ?o where {
  dbpedia:Bob_Dylan ?p ?o .
  dbpedia:Tom_Waits ?p ?o .
  dbpedia:The_Byrds ?p ?o .
}

SPARQL results from DBpedia

p                                                o
--------------------------------------------------------------------------------------------------------------------------
http://www.w3.org/1999/02/22-rdf-syntax-ns#type  http://www.w3.org/2002/07/owl#Thing
http://www.w3.org/1999/02/22-rdf-syntax-ns#type  http://dbpedia.org/ontology/Agent
http://www.w3.org/1999/02/22-rdf-syntax-ns#type  http://schema.org/MusicGroup
http://www.w3.org/1999/02/22-rdf-syntax-ns#type  http://dbpedia.org/class/yago/YagoLegalActor
http://www.w3.org/1999/02/22-rdf-syntax-ns#type  http://dbpedia.org/class/yago/YagoLegalActorGeo
http://purl.org/dc/terms/subject                 http://dbpedia.org/resource/Category:Rock_and_Roll_Hall_of_Fame_inductees
http://dbpedia.org/ontology/recordLabel          http://dbpedia.org/resource/Asylum_Records
http://dbpedia.org/ontology/genre                http://dbpedia.org/resource/Rock_music
http://dbpedia.org/property/genre                http://dbpedia.org/resource/Rock_music
http://dbpedia.org/property/label                http://dbpedia.org/resource/Asylum_Records
http://dbpedia.org/property/wordnet_type         http://www.w3.org/2006/03/wn/wn20/instances/synset-musician-noun-1

您还可以使用这样的查询来查找某些特定属性与所有这三个人相关的主题(但在DBpedia上它没有任何答案):

select ?s ?p where {
  ?s ?p dbpedia:Bob_Dylan, dbpedia:Tom_Waits, dbpedia:The_Byrds .
}