uml Composition relationships to RDF and OWL

2019-07-19 10:16发布

问题:

I'm beginner in RDF and OWL ontologies.

I'm trying to transform this diagram into OWL syntax.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:dc="http://purl.org/dc/elements/1.1/"
        >

    <!-- OWL Class Definition - Robot Position -->
    <owl:Class rdf:ID="house" />
            <owl:Class rdf:ID="room" />
            <owl:Class rdf:ID="kitchen" />
            <owl:Class rdf:ID="garden" />
            <owl:Class rdf:ID="table" />
            <owl:Class rdf:ID="chair" />

    <owl:ObjectProperty rdf:ID="composedBy">
        <rdfs:domain rdf:resource="#house"/>
        <rdfs:rang rdf:resource="#room" >
    </owl:ObjectProperty>              
</rdf:RDF>

I don't know how to do to make the composed by relation used many times. I'm thinking to make the range to take in a collection type with

(house)---composedBy---(room, kitchen, garden)

but, I want to use the same relation with

(kitchen)---comoposedBy---(table, chair)

The validator is making an error because I used composedBy as an ID twice. (I removed it now)

How can I do to translate this diagram correctly.

:))

回答1:

If you're trying to say that a House must have a (or at least one) Kitchen, and must have a (or at least one) Room, and must have a (or at least one) Garden, then unionOf isn't really solving the issue here. Rather than worrying about the range of the composition property, I think it might be more helpful if you have a more generic component property, and express the different relationships that must hold by using existential restrictions. E.g., you could say that

House ⊑ =1 hasPart.Kitchen
House ⊑ ≥2 hasPart.Room
House ⊑ ∃hasPart.Garden

to say that a House has exactly one Kitchen, at least two Room, and at least one Garden. Similarly, you could say that has a table and a chair with

Kitchen ⊑ ∃hasPart.Chair
Kitchen ⊑ ∃hasPart.Table

In Protégé, this would look like:

The RDF serialization in Turtle and RDF/XML are:

@prefix :      <http://www.example.org/houses#> .
@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://www.example.org/houses>
        a       owl:Ontology .

:hasPart  a     owl:ObjectProperty .

:Table  a       owl:Class .
:Room   a       owl:Class .
:Garden  a      owl:Class .
:Chair  a       owl:Class .

:House  a                owl:Class ;
        rdfs:subClassOf  [ a                            owl:Restriction ;
                           owl:minQualifiedCardinality  "2"^^xsd:nonNegativeInteger ;
                           owl:onClass                  :Room ;
                           owl:onProperty               :hasPart
                         ] ;
        rdfs:subClassOf  [ a                   owl:Restriction ;
                           owl:onProperty      :hasPart ;
                           owl:someValuesFrom  :Garden
                         ] ;
        rdfs:subClassOf  [ a                         owl:Restriction ;
                           owl:onClass               :Kitchen ;
                           owl:onProperty            :hasPart ;
                           owl:qualifiedCardinality  "1"^^xsd:nonNegativeInteger
                         ] .


:Kitchen  a              owl:Class ;
        rdfs:subClassOf  [ a                   owl:Restriction ;
                           owl:onProperty      :hasPart ;
                           owl:someValuesFrom  :Table
                         ] ;
        rdfs:subClassOf  [ a                   owl:Restriction ;
                           owl:onProperty      :hasPart ;
                           owl:someValuesFrom  :Chair
                         ] .
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns="http://www.example.org/houses#"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
  <owl:Ontology rdf:about="http://www.example.org/houses"/>
  <owl:Class rdf:about="http://www.example.org/houses#Room"/>
  <owl:Class rdf:about="http://www.example.org/houses#House">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty>
          <owl:ObjectProperty rdf:about="http://www.example.org/houses#hasPart"/>
        </owl:onProperty>
        <owl:onClass rdf:resource="http://www.example.org/houses#Room"/>
        <owl:minQualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
        >2</owl:minQualifiedCardinality>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://www.example.org/houses#hasPart"/>
        <owl:someValuesFrom>
          <owl:Class rdf:about="http://www.example.org/houses#Garden"/>
        </owl:someValuesFrom>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://www.example.org/houses#hasPart"/>
        <owl:onClass>
          <owl:Class rdf:about="http://www.example.org/houses#Kitchen"/>
        </owl:onClass>
        <owl:qualifiedCardinality rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger"
        >1</owl:qualifiedCardinality>
      </owl:Restriction>
    </rdfs:subClassOf>
  </owl:Class>
  <owl:Class rdf:about="http://www.example.org/houses#Chair"/>
  <owl:Class rdf:about="http://www.example.org/houses#Table"/>
  <owl:Class rdf:about="http://www.example.org/houses#Kitchen">
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://www.example.org/houses#hasPart"/>
        <owl:someValuesFrom rdf:resource="http://www.example.org/houses#Table"/>
      </owl:Restriction>
    </rdfs:subClassOf>
    <rdfs:subClassOf>
      <owl:Restriction>
        <owl:onProperty rdf:resource="http://www.example.org/houses#hasPart"/>
        <owl:someValuesFrom rdf:resource="http://www.example.org/houses#Chair"/>
      </owl:Restriction>
    </rdfs:subClassOf>
  </owl:Class>
</rdf:RDF>


回答2:

Indeed the range of such a composedBy property should be a union.

Since you have two different compositions in the UML class model, you may have to define two different OWL properties, like houseComposedBy and kitchenComposedBy.

As you have suggested in your comment, in principle, it's also an option to use XML namespaces for getting different names for these different composedBy OWL properties (like the qualified names house:composedBy and kitchen:composedBy). In fact this corresponds to UML properties, which are always in the namespace defined by their (domain) class. So you would have to declare as many namespaces as you have classes that are the domain of a composedBy property.

Edit: I'll try to wrap up the two answers of Joshua Taylor and myself.

  1. UML does not have a generic composition relationship, but rather class-specific isComposedOf (or hasPart) properties, which are defined in the namespace provided by their (domain) class. Therefore, it's an option to translate such UML properties into corresponding OWL properties, which encode their namespace either implicitly in the property name, or explicitly with an XML namespace.
  2. A second approach, pointed out in the answer by Joshua Taylor is based on the fact that OWL properties are generic (not restricted to a specific domain class) by default. This allows to define a generic hasPart property. However, for obtaining the same range constraints that we have in our UML class model, we have to define corresponding allValuesFrom restrictions on our generic hasPart property. In addition to these allValuesFrom restrictions, which are essential for the translation, we could also define cardinality restrictions corresponding to the multiplicity constraints defined in our UML class model (if there are any).


标签: uml rdf owl