Why do we need to use rdf:parseType=“Collection” with owl:intersectionOf?

孤街醉人 提交于 2020-01-17 03:25:19

问题


Conside the following example taken from, http://www.w3.org/TR/owl-ref/#intersectionOf-def.

<owl:Class>
  <owl:intersectionOf rdf:parseType="Collection">
    <owl:Class>
      <owl:oneOf rdf:parseType="Collection">
        <owl:Thing rdf:about="#Tosca" />
        <owl:Thing rdf:about="#Salome" />
      </owl:oneOf>
    </owl:Class>
    <owl:Class>
      <owl:oneOf rdf:parseType="Collection">
        <owl:Thing rdf:about="#Turandot" />
        <owl:Thing rdf:about="#Tosca" />
      </owl:oneOf>
    </owl:Class>
  </owl:intersectionOf>
</owl:Class>

While we understand the usage of the second and third rdf:parseType="Collection", I am somewhat confused about the first usage, just after owl:intersectionOf.

In this example the value of owl:intersectionOf is a list of two class descriptions, namely two enumerations, both describing a class with two individuals. The resulting intersection is a class with one individual, namely Tosca, as this is the only individual that is common to both enumerations.

What would have happened if we left out the first rdf:parseType="Collection"?

Do we still need to use the first rdf:parseType="Collection", if the intersecting classes are not collections?


回答1:


The value of owl:intersectionOf is supposed to be an RDF list. RDF lists are linked lists, where the element of node is indicated by rdf:first and the tail of the list by rdf:rest, and the empty list is indicated by rdf:nil. As you can imagine, that quickly becomes very verbose. The serialization can be shorter by using the parseType Collection attribute. It's not a triple, it's just a shorthand in the RDF/XML serialization.

Here's a complete version of your snippet:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#">
  <owl:Class>
    <owl:intersectionOf rdf:parseType="Collection">
      <owl:Class>
        <owl:oneOf rdf:parseType="Collection">
          <owl:Thing rdf:about="urn:ex#Tosca"/>
          <owl:Thing rdf:about="urn:ex#Salome"/>
        </owl:oneOf>
      </owl:Class>
      <owl:Class>
        <owl:oneOf rdf:parseType="Collection">
          <owl:Thing rdf:about="urn:ex#Turandot"/>
          <owl:Thing rdf:about="urn:ex#Tosca"/>
        </owl:oneOf>
      </owl:Class>
    </owl:intersectionOf>
  </owl:Class>
</rdf:RDF>

You can see all the actual triples if you serialize in N-Triples:

_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffd <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffe .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffd <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff9 .
<urn:ex#Tosca> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff8 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <urn:ex#Turandot> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff8 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff7 .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffb <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <urn:ex#Salome> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffb <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffe <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffe <http://www.w3.org/2002/07/owl#oneOf> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffc .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffc <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <urn:ex#Tosca> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffc <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffb .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff9 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffa .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff9 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
<urn:ex#Turandot> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
<urn:ex#Salome> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Thing> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff7 <http://www.w3.org/1999/02/22-rdf-syntax-ns#first> <urn:ex#Tosca> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff7 <http://www.w3.org/1999/02/22-rdf-syntax-ns#rest> <http://www.w3.org/1999/02/22-rdf-syntax-ns#nil> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffa <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffa <http://www.w3.org/2002/07/owl#oneOf> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ff8 .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7fff <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2002/07/owl#Class> .
_:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7fff <http://www.w3.org/2002/07/owl#intersectionOf> _:BX2D2b2d7d1aX3A1526aea91dcX3AX2D7ffd .

That's a lot of rdf:first and rdf:rest triples. You get the same if you don't use that abbreviation in RDF/XML:

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#" > 
  <rdf:Description rdf:nodeID="A0">
    <rdf:first rdf:resource="urn:ex#Tosca"/>
    <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A1">
    <rdf:first rdf:resource="urn:ex#Turandot"/>
    <rdf:rest rdf:nodeID="A0"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A2">
    <rdf:first rdf:nodeID="A3"/>
    <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
  </rdf:Description>
  <rdf:Description rdf:about="urn:ex#Salome">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </rdf:Description>
  <rdf:Description rdf:about="urn:ex#Tosca">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </rdf:Description>
  <rdf:Description rdf:about="urn:ex#Turandot">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A3">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:oneOf rdf:nodeID="A1"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A4">
    <rdf:first rdf:resource="urn:ex#Salome"/>
    <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A5">
    <rdf:first rdf:resource="urn:ex#Tosca"/>
    <rdf:rest rdf:nodeID="A4"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A6">
    <rdf:first rdf:nodeID="A7"/>
    <rdf:rest rdf:nodeID="A2"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A7">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:oneOf rdf:nodeID="A5"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A8">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:intersectionOf rdf:nodeID="A6"/>
  </rdf:Description>
</rdf:RDF>

As a result, we use nice shorthands, RDF/XML's parseType collection, or Turtle's parentheses:

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

<urn:ex#Tosca>  a  owl:Thing .

_:b0    a          owl:Class ;
        owl:oneOf  ( <urn:ex#Tosca> <urn:ex#Salome> ) .

[ a                   owl:Class ;
  owl:intersectionOf  ( _:b0 _:b1 )
] .

_:b1    a          owl:Class ;
        owl:oneOf  ( <urn:ex#Turandot> <urn:ex#Tosca> ) .

<urn:ex#Turandot>  a  owl:Thing .

<urn:ex#Salome>  a  owl:Thing .

What happens if there's no attribute

What would have happened if we left out the first rdf:parseType="Collection"?

From the documentation on parse type collection:

RDF/XML allows an rdf:parseType="Collection" attribute on a property element to let it contain multiple node elements.

That suggests that without a parse type collection attribute, then a property element shouldn't contain more than one element. You'd want to read in 2.2 Node Elements and Property Elements to see what the typical syntax is. In general, the idea is that to represent the triples

x:s  x:p1  x:q1 .
x:s  x:p2  x:q2 .

you end up with XML like:

<rdf:Description rdf:about="...s">        <!-- a node element -->
  <x:p1>                                  <!-- a property element -->
    <rdf:Description rdf:about="...q1"/>  <!-- a node element -->
  </x:p1>
</rdf:Description>
<rdf:Description rdf:about="...s">        <!-- a node element -->
  <x:p2>                                  <!-- a property element -->
    <rdf:Description rdf:about="...q2"/>  <!-- a node element -->
  </x:p2>
</rdf:Description>

Now, there's a shorthand that lets you use multiple property elements within a node element. That's described in 2.3 Multiple Property Elements, and lets you do this instead:

<rdf:Description rdf:about="...s">        <!-- a node element -->
  <x:p1>                                  <!-- a property element -->
    <rdf:Description rdf:about="...q1"/>  <!-- a node element -->
  </x:p1>
  <x:p2>                                  <!-- a property element -->
    <rdf:Description rdf:about="...q2"/>  <!-- a node element -->
  </x:p2>
</rdf:Description>

However, there's no such shorthand to let you add multiple objects within a single property element. That is, you cannot abbreviate the triples

x:s  x:p1  x:q1 .
x:s  x:p1  x:q2 .

by

<rdf:Description rdf:about="...s">        <!-- a node element -->
  <x:p1>                                  <!-- a property element -->
    <rdf:Description rdf:about="...q1"/>  <!-- a node element -->
    <rdf:Description rdf:about="...q2"/>  <!-- a node element -->
  </x:p1>
</rdf:Description>

That's what you would end up with if you had a collection and then removed the parse type collection attribute from it. It would have been a nice feature I suppose, but maybe there's some other part of the standard that it would conflict with. Anyhow, that's why you get a warning when you try; it's not legal.

If the classes weren't intersections

Do we still need to use the first rdf:parseType="Collection", if the intersecting classes are not collections?

As I noted above, RDF/XML is a serialization of RDF, and RDF is an abstract data model (it's just triples). RDF/XML adds lots of complexity that you shouldn't have to worry about. The fact that you're working with an OWL file makes things even more complex, because OWL is another abstract representation (it's just axioms). There's a mapping from OWL to RDF, which is kind of complicated. So you're looking at something that's got two layers of encoding:

    OWL (axioms) &Rightarrow; RDF (triples) &Rightarrow; RDF/XML

OWL doesn't know anything about parse type collection and RDF/XML serialization, it just knows about OWL. There's a mapping that knows about OWL and about RDF, and that's what produces the RDF triples. RDF doesn't know anything about parse type collection. There's a mapping from RDF to XML that knows about it. Your RDF needs to be legal RDF, period.

If you're working with OWL, use OWL tools.
If you're working with RDF, use RDF tools.
If you're working with XML, use XML tools.



来源:https://stackoverflow.com/questions/34947796/why-do-we-need-to-use-rdfparsetype-collection-with-owlintersectionof

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!