如何通过使用SPARQL获得OWL类的数据和对象属性? [英] How to get data and object properties of an OWL class by using SPARQL?

查看:497
本文介绍了如何通过使用SPARQL获得OWL类的数据和对象属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含许多类的复杂的OWL本体.我需要使用哪种SPARQL查询来获取一个OWL类(例如Person类)的数据和对象属性?

I have a complex OWL ontology with many classes. What SPARQL query do I need to use to obtain data and object properties of one OWL class (e.g., Person class)?

推荐答案

除了 Jukka Matilainen的答案之外,还有需要考虑的几点. OWL不是面向对象的编程语言,并且类和属性的概念与面向对象的编程语言中的类和属性不同.当我们断言

In addition to Jukka Matilainen's answer, there are a few points that should be taken into consideration. OWL is not an object oriented programming language, and the concept of classes and properties are not the same as classes and properties in object oriented programming languages. When we assert that

p rdfs:domain C

我们没有做任何限制p可以为其赋值的个人的事情.也就是说,我们看到的并不一致

we're not doing anything that restricts the individuals that p can have a value for. That is, it's not inconsistent if we see

x p something

,我们不知道xC.实际上,当我们说p的域是C时,我们实际上是在说,只要我们有形式为x p something的三元组,就可以推断 xC.我们可以将其写为三元组的推理规则:

and we don't know that x is a C. In fact, what we're actually saying when we say that p's domain is C is that any time we have a triple of the form x p something, we can infer that x is a C. We can write this as an inference rule on triples:

 x p _     p rdfs:domain C
 ------------------------- [1]
       x rdf:type C

rdfs:subClassOf的推理规则结合使用时,可能会产生一些令人惊讶的后果.特别是,回想一下,当C rdfs:subClassOf D时,这意味着只要我们拥有C的实例,就可以推断出它也是D的实例.作为推论规则:

This has some potentially surprising consequences when combined with the inference rules for rdfs:subClassOf. In particular, recall that when C rdfs:subClassOf D, this means that any time we have an instance of C, we can infer that it is also an instance of D. As an inference rule:

x rdf:type C    C rdfs:subClassOf D
----------------------------------- [2]
        x rdf:type D

为什么这会导致令人惊讶的结果?好吧,这意味着如果p的域是C,并且CD的子类,那么也可以说D.为什么会这样呢?好吧,假设x p _p rdfs:domain CC rdfs:subClassOf D.好吧,根据上面的规则[1],我们拥有该x rdf:type C.但是因为CD的子类,所以我们也有x rdf:type D.由于x是任意的,因此只要我们有x p _,我们就有x rdf:type D,但这正是拥有p rdfs:domain D的含义.

Why does this lead to surprising results? Well, it means that if the domain of p is C, and if C is a subclass of D, then it's also legal to say that D is the (or a) domain of p. Why is this the case? Well, suppose that x p _, and that p rdfs:domain C, and that C rdfs:subClassOf D. Well, by rule [1] above, we have that x rdf:type C. But then because C is a subclass of D, we also have that x rdf:type D. Since the x is arbitrary, then anytime we have x p _, we also have x rdf:type D, but that's exactly what it means to have p rdfs:domain D.

这意味着,如果要检索以foaf:Person作为域的所有属性,则需要所有结果,则不仅需要SPARQL查询,还需要使用OWL推理程序.仅索要声明域为foaf:Person的内容并不一定能找到所有结果.

This means that if you're trying to retrieve all properties that have foaf:Person as a domain, then you'll need to use an OWL reasoner, not just SPARQL queries, if you want all the results. Just asking for things that have a declared domain of foaf:Person won't necessarily find all the results.

使用SPARQL查询有一个已接受的答案,但我还要注意,可以对其进行一些清理通过使用values而不是

There's an accepted answer with a SPARQL query, but I'd also note that it can be cleaned up a bit by using values instead of using

{ ?property a owl:DatatypeProperty } UNION { ?property a owl:ObjectProperty }

由于目的是?property具有作为rdf:type的两个值之一,因此我们可以将查询缩短为:

Since the intent is that ?property has one of two values as an rdf:type, we can shorten the query to be:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl:  <http://www.w3.org/2002/07/owl#>

SELECT ?property
FROM <http://xmlns.com/foaf/spec/index.rdf>
WHERE {
  values ?propertyType { owl:DatatypeProperty owl:ObjectProperty }
  ?property a ?propertyType ;
            rdfs:domain foaf:Person .
}

如上所述,您可能希望包括其声明的域为foaf:Person的子类的所有属性,尽管我们无法使用SPARQL查询来计算整个OWL类层次结构,但至少可以做一点点具有属性路径:

As described above, you may well want to include any properties whose declared domain is an subclass of foaf:Person, and while we can't compute the entire OWL class hierarchy using SPARQL queries, we can at least do a little bit with property paths:

PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl:  <http://www.w3.org/2002/07/owl#>

SELECT ?property
FROM <http://xmlns.com/foaf/spec/index.rdf>
WHERE {
  values ?propertyType { owl:DatatypeProperty owl:ObjectProperty }
  ?property a ?propertyType ;
            rdfs:domain/rdfs:subClassOf* foaf:Person .
}

这篇关于如何通过使用SPARQL获得OWL类的数据和对象属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆