简体   繁体   中英

Create instances of unionOf with OWL/RDF/XML

I have this example of OWL below and I want to know how to start and create an instance (individuals) for "unionOf"

I want to know how to made instance of this

<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#" >

<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:about="house_composedBy">
    <rdfs:domain rdf:resource="#house"/>
    <rdfs:range>
        <owl:Class>
            <owl:unionOf rdf:parseType="Collection">
                <owl:Class rdf:about="room" />
                <owl:Class rdf:about="kitchen" />
                <owl:Class rdf:about="garden" />
            </owl:unionOf>
        </owl:Class>
    </rdfs:range>
</owl:ObjectProperty>

I started like this but I stopped because I don't know which object i'm adding if I don't know the type of.

Example,

<u:house rdf:ID="p_house01">
    <u:house_composedBy about="room01" />
    <u:house_composedBy about="room02" />
    <u:house_composedBy about="kitchen" />
    <u:house_composedBy about="garden" />
</u:house> 

I don't know now how to distinguish between individuals, is it the right way to do this with unionOf ??

Regards.

Why do you need instances of a union class?

While the rest of my answer will address how you can create instances of a union class, I do think that you should consider the reason that you're doing this. If this is related to your earlier question, uml Composition relationships to RDF and OWL , which seems likely, and you're trying to say that the range of a property is a union class, eg,

hasComponent rdfs:range (TypeA or TypeB)

you don't need to declare that some individual x is of type (TypeA or TypeB) in order to use it as the object of a hasComponent statement. On the contrary. All the rdfs:range declaration does here is gives you the ability to observe a statement

y hasComponent x

and to infer from it that

x rdf:type (TypeA or TypeB)

You don't need to declare any type on x in advance. Domain and range declarations allow you to infer the types of things based on how they're used in assertions; they don't provide any sort of consistency enforcement or integrity constraints.

How you can create them

I'm not sure what exactly you're asking (whether you're trying to generate the RDF/XML serialization of some axioms, or what), but I think we can find a solution. Wsing Protégé, it's easy to create an individual and declare that it has as a type some union class. Eg, we can assert that

x : A or B or C

in Protégé:

unionOf示例

We can take a look at the RDF serialization of this OWL ontology. The Turtle serialization is the easiest to read, and the easiest to write, if you need to write this by hand for some reason:

@prefix :      <http://www.example.org/unionof-example#> .
@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#> .

## Ontology declaration
<http://www.example.org/unionof-example>
        a       owl:Ontology .

## Three classes
:A      a       owl:Class .
:B      a       owl:Class .
:C      a       owl:Class .

## x is a thing, a named individual, and 
## an (A or B or C).
:x      a       owl:Thing , owl:NamedIndividual ;
        a       [ a            owl:Class ;
                  owl:unionOf  ( :A :B :C )
                ] .

If you really need this in RDF/XML, that's just another serialization of the RDF graph:

<rdf:RDF
    xmlns="http://www.example.org/unionof-example#"
    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.example.org/unionof-example"/>
  <owl:Class rdf:about="http://www.example.org/unionof-example#A"/>
  <owl:Class rdf:about="http://www.example.org/unionof-example#B"/>
  <owl:Class rdf:about="http://www.example.org/unionof-example#C"/>
  <owl:Thing rdf:about="http://www.example.org/unionof-example#x">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
    <rdf:type>
      <owl:Class>
        <owl:unionOf rdf:parseType="Collection">
          <owl:Class rdf:about="http://www.example.org/unionof-example#A"/>
          <owl:Class rdf:about="http://www.example.org/unionof-example#B"/>
          <owl:Class rdf:about="http://www.example.org/unionof-example#C"/>
        </owl:unionOf>
      </owl:Class>
    </rdf:type>
  </owl:Thing>
</rdf:RDF>

You might also be interested in the non abbreviated serialization of that. It's more verbose, and less human readable, but it might be a bit easier to write by hand, if that's what you're doing:

<rdf:RDF
    xmlns="http://www.example.org/unionof-example#"
    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#" > 
  <rdf:Description rdf:about="http://www.example.org/unionof-example#A">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A0">
    <rdf:first rdf:resource="http://www.example.org/unionof-example#B"/>
    <rdf:rest rdf:nodeID="A1"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.example.org/unionof-example#B">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A2">
    <rdf:first rdf:resource="http://www.example.org/unionof-example#A"/>
    <rdf:rest rdf:nodeID="A0"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.example.org/unionof-example#C">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A3">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Class"/>
    <owl:unionOf rdf:nodeID="A2"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A1">
    <rdf:first rdf:resource="http://www.example.org/unionof-example#C"/>
    <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.example.org/unionof-example">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Ontology"/>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.example.org/unionof-example#x">
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#Thing"/>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#NamedIndividual"/>
    <rdf:type rdf:nodeID="A3"/>
  </rdf:Description>
</rdf:RDF>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM