检索OWL相交类隐含的超类 [英] Retrieving superclasses implied by OWL intersection classes

查看:71
本文介绍了检索OWL相交类隐含的超类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OWL本体可能具有A,B和C类以及公理(用DL表示法):

An OWL ontology may have classes A, B, and C, and axiom (in DL notation):

A⊑ (B⊓ C)

A ⊑ (B ⊓ C)

或近似的曼彻斯特OWL语法:

or in approximate Manchester OWL Syntax:

A subClassOf (B C)

从逻辑上讲,A是B的子类,A是C的子类,但是三元组

It is logically true that A is a subclass of B, and that A is a subclass of C, but the triples

A rdfs:subClassOf B
A rdfs:subClassOf C

OWL本体的RDF序列化中不一定存在

.例如,请考虑一下Protégé中非常简单的本体,以及RDF/XML和Turtle中的RDF序列化:

are not necessarily present in the RDF serialization of the OWL ontology. For instance, consider this very simple ontology in Protégé and its RDF serialization in RDF/XML and Turtle:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://stackoverflow.com/q/19924861/1281433/sample.owl#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl"/>
  <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#C"/>
  <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#B"/>
  <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#A">
    <rdfs:subClassOf>
      <owl:Class>
        <owl:intersectionOf rdf:parseType="Collection">
          <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#B"/>
          <owl:Class rdf:about="http://stackoverflow.com/q/19924861/1281433/sample.owl#C"/>
        </owl:intersectionOf>
      </owl:Class>
    </rdfs:subClassOf>
  </owl:Class>
</rdf:RDF>

@prefix :      <http://stackoverflow.com/q/19924861/1281433/sample.owl#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

<http://stackoverflow.com/q/19924861/1281433/sample.owl>
        a       owl:Ontology .

:B      a       owl:Class .

:C      a       owl:Class .

:A      a                owl:Class ;
        rdfs:subClassOf  [ a                   owl:Class ;
                           owl:intersectionOf  ( :B :C )
                         ] .

序列化带有rdfs:subClassOf的三元组,但是对象不是:B:C,因此查询类似

The serialization has a triple with rdfs:subClassOf, but the object isn't :B or :C, so a query like

:A rdfs:subClassOf ?superclass

不会返回:A的超类.如何编写SPARQL查询,以返回:A的那些超类?

won't return the superclasses of :A. How can I write a SPARQL query that will return those superclasses of :A?

推荐答案

听起来您有一个类,它是某个交集类的子类.例如,您可能有

It sounds like you've got a class that is a subclass of some intersection class. E.g., you might have

学生人员注册一些课程

StudentPersonenrolledIn some Course

在ProtégéOWL本体编辑器中,它看起来像:

In the Protégé OWL ontology editor, this would look like:

如果您为子类(例如

prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#>

select ?subclass ?superclass where { 
  ?subclass rdfs:subClassOf ?superclass
}

并且您没有推理器来推断其他数据,您不会在结果中看到学生作为子类,但是您可能会看到一个空白(匿名)节点:

and you don't have a reasoner inferring additional data, you won't see Student as a subclass in your results, but you might see an blank (anonymous) node:

---------------------------------------------------------
| subclass                                 | superclass |
=========================================================
| <http://www.examples.org/school#Student> | _:b0       |
---------------------------------------------------------

要了解为什么会这样,您需要查看本体的RDF序列化.在这种情况下,它(在RDF/XML中):

To understand why this is the case, you need to take a look at the RDF serialization of the ontology. In this case, it's (in RDF/XML):

<rdf:RDF
    xmlns="http://www.examples.org/school#"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://www.examples.org/school"/>
  <owl:Class rdf:about="http://www.examples.org/school#Course"/>
  <owl:Class rdf:about="http://www.examples.org/school#Person"/>
  <owl:Class rdf:about="http://www.examples.org/school#Student">
    <rdfs:subClassOf>
      <owl:Class>
        <owl:intersectionOf rdf:parseType="Collection">
          <owl:Class rdf:about="http://www.examples.org/school#Person"/>
          <owl:Restriction>
            <owl:onProperty>
              <owl:ObjectProperty rdf:about="http://www.examples.org/school#enrolledIn"/>
            </owl:onProperty>
            <owl:someValuesFrom rdf:resource="http://www.examples.org/school#Course"/>
          </owl:Restriction>
        </owl:intersectionOf>
      </owl:Class>
    </rdfs:subClassOf>
  </owl:Class>
</rdf:RDF>

或者在更具人类可读性的Turtle(也更类似于SPARQL查询语法)中:

Or in the more human-readable Turtle (which is also more like the SPARQL query syntax):

@prefix :      <http://www.examples.org/school#> .
@prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl:   <http://www.w3.org/2002/07/owl#> .
@prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
@prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .

:Student  a              owl:Class ;
        rdfs:subClassOf  [ a                   owl:Class ;
                           owl:intersectionOf  ( :Person [ a                   owl:Restriction ;
                                                           owl:onProperty      :enrolledIn ;
                                                           owl:someValuesFrom  :Course
                                                         ] )
                         ] .

:Person  a      owl:Class .

:enrolledIn  a  owl:ObjectProperty .

:Course  a      owl:Class .

<http://www.examples.org/school>
        a       owl:Ontology .

事实上,数据中有一个Student rdfs:subClassOf [ ... ]三元组,但是[ ... ]是一个空白节点;这是一个匿名owl:Class,它是其他一些类的交集.推理机可以告诉您 X ⊑ ( Y Z ),然后 X Y X Z ,但是单独执行SPARQL查询不会做到这一点.您可以像这样进行更复杂的SPARQL查询:

There is, in fact, a Student rdfs:subClassOf [ ... ] triple in the data, but the [ ... ] is a blank node; it's an anonymous owl:Class that is the intersection of some other classes. A reasoner would be able to tell you that if X ⊑ (Y and Z) then XY and XZ, but a SPARQL query on its own won't do that. You could make a more complex SPARQL query like this that would, though:

prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?subclass ?superclass where {
  { ?subclass rdfs:subClassOf ?superclass }
  union
  { ?subclass rdfs:subClassOf [ owl:intersectionOf [ rdf:rest* [ rdf:first ?superclass ] ] ] }
}

--------------------------------------------------------------------------------------
| subclass                                 | superclass                              |
======================================================================================
| <http://www.examples.org/school#Student> | _:b0                                    |
| <http://www.examples.org/school#Student> | <http://www.examples.org/school#Person> |
| <http://www.examples.org/school#Student> | _:b1                                    |
--------------------------------------------------------------------------------------

两个空白节点是匿名交集类和匿名限制类(已在某些课程中注册).如果只需要IRI结果,则可以使用filter:

The two blank nodes are the anonymous intersection class, and the anonymous restriction class (enrolledIn some Course). If you only want IRI results, you can use a filter:

prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?subclass ?superclass where {
  { ?subclass rdfs:subClassOf ?superclass }
  union
  { ?subclass rdfs:subClassOf [ owl:intersectionOf [ rdf:rest* [ rdf:first ?superclass ] ] ] }

  filter( isIRI( ?superclass ) )
}

--------------------------------------------------------------------------------------
| subclass                                 | superclass                              |
======================================================================================
| <http://www.examples.org/school#Student> | <http://www.examples.org/school#Person> |
--------------------------------------------------------------------------------------

现在,作为最后一点,如果您想使查询更小一些,因为这两个union ed模式的唯一区别是连接?subclass?superclass的路径,您实际上可以编写此代码仅具有一条属性路径. (尽管,如 Sparql查询子类或EquivalentTo 中所述,如果这样做,您可能会遇到Protégé的一些问题.)这个想法是,您可以重写它:

Now, as final touch, if you want to make your query a bit smaller, since the only difference in those two unioned patterns is the path that connects ?subclass and ?superclass, you can actually write this with just one property path. (Although, as noted in Sparql query Subclass or EquivalentTo, you might run into some issues with Protégé if you do this.) The idea is that you can rewrite this:

{ ?subclass rdfs:subClassOf ?superclass }
union
{ ?subclass rdfs:subClassOf [ owl:intersectionOf [ rdf:rest* [ rdf:first ?superclass ] ] ] }

这样,通过使用属性路径,这也消除了对空白节点的需要:

as this, by using property paths, which also removes the need for the blank nodes:

?subclass ( rdfs:subClassOf |
            ( rdfs:subClassOf / owl:intersectionOf / rdf:rest* / rdf:first ) ) ?superclass

您可以将其简化为

?subclass rdfs:subClassOf/((owl:intersectionOf/rdf:rest*/rdf:first)+) ?superclass

您甚至可以从中删除一个括号以使其成为

and you can even remove one level of parentheses from that, to make it

?subclass rdfs:subClassOf/(owl:intersectionOf/rdf:rest*/rdf:first)+ ?superclass

,但是您必须开始记住优先级规则,这没什么好玩的.该查询虽然有效:

but then you'd have to start remembering the precedence rules, and that's not much fun. The query works though:

prefix rdfs:  <http://www.w3.org/2000/01/rdf-schema#>
prefix owl:   <http://www.w3.org/2002/07/owl#>
prefix rdf:   <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

select ?subclass ?superclass where {
  ?subclass rdfs:subClassOf/(owl:intersectionOf/rdf:rest*/rdf:first)+ ?superclass
  filter( isIRI( ?superclass ) )
}

--------------------------------------------------------------------------------------
| subclass                                 | superclass                              |
======================================================================================
| <http://www.examples.org/school#Student> | <http://www.examples.org/school#Person> |
--------------------------------------------------------------------------------------

这篇关于检索OWL相交类隐含的超类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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