如何使用sparql访问rdf中子类的父属性?(How to access parent properties of a child class in rdf with sparql?)

编程入门 行业动态 更新时间:2024-10-20 08:35:31
如何使用sparql访问rdf中子类的父属性?(How to access parent properties of a child class in rdf with sparql?)

我正在尝试访问RDF中父类继承的属性。 我使用rdfs属性subClassOf定义了我的子类的实例。

使用乌龟语法:

ex:myClass1 a owl:class; rdfs:range xsd:integer. ex:myClass2 rdfs:subClassOf ex:myClass1. # defining instance of my class ex:instance1 ex:myClass1 1 . ex:instance2 ex:myClass2 2 .

如果我想访问所有ex:myClass1和他的孩子的属性ex:property 。 我是否可以承认ex:myClass2ex:myClass1并编写此SPARQL查询

SELECT ?instance ?value WHERE{ ?instance ex:myClass1 ?value . }

获得我定义的两个值? 或者rdfs:subClassOf没有将子类定义为父类的更具体的版本?

I'm trying to access to the property inherited of a parent class in RDF. I define an instance of my child class using the rdfs property subClassOf.

With a turtle syntax :

ex:myClass1 a owl:class; rdfs:range xsd:integer. ex:myClass2 rdfs:subClassOf ex:myClass1. # defining instance of my class ex:instance1 ex:myClass1 1 . ex:instance2 ex:myClass2 2 .

If I want to access to the property ex:property of all ex:myClass1 and his child. Can I admit that ex:myClass2 is a ex:myClass1 and write this SPARQL query

SELECT ?instance ?value WHERE{ ?instance ex:myClass1 ?value . }

to obtain the two values I've defined? Or rdfs:subClassOf doesn't define a child class as a more specificaly version of the parent class?

最满意答案

为了补充Joshua试图解释的内容,您正在混合模式和数据概念。

我认为你应该定义的是(在简化的RDFS语法中):

ex:property rdfs:domain ex:myClass1 . ex:property rdfs:range xsd:integer . ex:myClass2 rdfs:subClassOf ex:myClass1. #this may be optional depending on the entailment regime your SPARQL enpoint uses ex:myClass1 a owl:class . # defining instance of my class ex:instance1 ex:property 1 . ex:instance2 ex:property 2 .

然后你可以查询

SELECT ?instance ?value WHERE{ ?instance ex:property ?value . }

根据SPARQL端点的蕴含制度,可以通过ex:属性推断出ex:instance1和ex:instance23至少是ex:Class1的实例(如果你想将其中一个作为ex:Class2,你将拥有添加三重ex:instance a ex:Class2到您的商店)

To complement what Joshua tried to explain you are mixing the schema and data concepts.

I think what you should define is (in simplified RDFS syntax):

ex:property rdfs:domain ex:myClass1 . ex:property rdfs:range xsd:integer . ex:myClass2 rdfs:subClassOf ex:myClass1. #this may be optional depending on the entailment regime your SPARQL enpoint uses ex:myClass1 a owl:class . # defining instance of my class ex:instance1 ex:property 1 . ex:instance2 ex:property 2 .

then you can query

SELECT ?instance ?value WHERE{ ?instance ex:property ?value . }

depending on the entailment regime of your SPARQL endpoint, it is inferred through the ex:property that ex:instance1 and ex:instance23 are at least instances of ex:Class1 (if you want to make one of those a ex:Class2 you will have to add the triple ex:instance a ex:Class2 to your store)

更多推荐

本文发布于:2023-07-31 01:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子类   如何使用   属性   rdf   sparql

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!