简体   繁体   English

SPARQL主题及其所有超类的所有谓词 - 对象对

[英]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图。

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.

相关问题 Dlang:获取实例的所有超类的名称作为数组 - Dlang: get names of all superclasses for an instance as array 查找 Perl 类的所有超类的最佳实践是什么? - What is the best practice for finding all the superclasses of a Perl class? 在表单之间传递Object及其所有值 - Passing Object and all of its values between forms 关于对象超类和转换的问题 - Questions about object superclasses and casting OOP设计:一个对象依赖于其所有依赖项的存在 - OOP design: one object dependent on the existence of ALL its dependencies 查看PHP类实例(对象)以查看其所有可用的公共属性和方法的最佳方法是什么? - What is the best way to look inside a PHP class instance (object) to see all of its available public properties and methods? 每个对象应该处理自己的渲染,还是应该由单独的类处理所有渲染? - Should each object handle its own rendering, or should a seperate class handle all rendering? 有没有办法在 object 中循环以打印 c++ 中所有成员的值? - Is there a way to loop inside an object to print the values of all its members in c++? 调用对象/函数中的所有函数 - Calling all functions in an object/function 删除分配给对象的所有内存 - Delete all the memory allocated to an object
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM