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



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

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

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

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

DBpedia 的SPARQL结果

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 .
}

最新更新