[英]SPARQL all predicate-object pairs of subject and all its superclasses
Imagine you do something crazy and store your object-oriented model as an RDF graph. 想象一下,你做了一些疯狂的事情,并将面向对象的模型存储为RDF图。
shows a simplified example of the inheritance hierarchy and the associated attributes. 显示了继承层次结构和关联属性的简化示例。
In practice, you get such graph structure if you translate some UML class diagram into RDFS. 实际上,如果将一些UML类图转换为RDFS,则会得到这样的图形结构 。
The question is: what SPARQL query can deliver all the predicate-object pairs necessary to instantiate a particular resource of "Class C". 问题是:SPARQL查询可以提供实例化“C类”特定资源所需的所有谓词 - 对象对。 In other words: how do you get all the predicate-object pairs along the whole inheritance chain (only single inheritance). 换句话说:如何在整个继承链中获得所有谓词 - 对象对(仅单个继承)。
Given this diagram, the predicate-object pairs of all members of the class :ClassC
is simply: 给定此图,类的所有成员的谓词 - 对象对:ClassC
只是:
SELECT ?inst ?p ?o
WHERE {
?inst a :ClassC .
Inst ?p ?o .
Keep in mind that there is not property inheritance in RDF/RDFS. 请记住,RDF / RDFS中没有属性继承。 If you want to find all of property/values pairs for ClassA
with entailments for subclasses then useL 如果要查找ClassA
所有属性/值对以及子类的蕴含,请使用L.
SELECT ?inst ?p ?o
WHERE {
?cls rdfs:subClassOf* :ClassA .
?inst a ?cls .
?inst ?p ?o
}
In this respect, RDFS works a bit backwards of one's expectations of OO inheritance. 在这方面,RDFS的工作有点落后于对OO继承的期望。
With the info from @scotthenninger the following query did the job: 使用来自@scotthenninger的信息,以下查询完成了这项工作:
SELECT ?p ?o
WHERE {
:ClassC rdfs:subClassOf* ?anySuperClass .
?anySuperClass ?p ?o .
}
edit: Similar query gets all the self-defined properties and their range along the inheritance chain: 编辑:类似查询获取继承链中的所有自定义属性及其范围:
SELECT ?prop ?obj
WHERE {
:ClassC rdfs:subClassOf* ?anySuperClass .
?prop rdfs:domain ?anySuperClass .
?prop rdfs:range ?obj .
}
End results combined: 最终结果合并:
foo:ID xsd:string
foo:name xsd:string
rdfs:comment xsd:string
foo:similarTo :ClassD
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.