2

For the XSD below:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified">
<xs:simpleType name="size">
  <xs:restriction base="xs:string">
    <xs:enumeration value="small" />
    <xs:enumeration value="medium" />
    <xs:enumeration value="large" />
  </xs:restriction>
</xs:simpleType>

<xs:complexType name="jeans">
  <xs:simpleContent>
    <xs:extension base="size">
      <xs:attribute name="sex">
        <xs:simpleType>
          <xs:restriction base="xs:string">
            <xs:enumeration value="male" />
            <xs:enumeration value="female" />
          </xs:restriction>
        </xs:simpleType>
      </xs:attribute>
    </xs:extension>
  </xs:simpleContent>
</xs:complexType>

</xs:schema> 

I want to convert xs:enumeration to owl. I found only one way to do it:

converting the string literal to a owl:Class:

:Class_2
      a       owl:Class ;
      rdfs:subClassOf dtype:EnumeratedValue ;
      rdfs:subClassOf
              [ a       owl:Restriction ;
                owl:maxCardinality "1"^^xsd:int ;
                owl:onProperty dtype:hasValue
              ] ;
      rdfs:subClassOf
              [ a       owl:Restriction ;
                owl:allValuesFrom xsd:string ;
                owl:onProperty dtype:hasValue
              ] ;
      owl:oneOf (:Class_2_male :Class_2_female) .

:Class_2_female
      a       :Class_2 ;
      dtype:hasValue "female"^^xsd:string .

But I don't like this way. A literal looks much like constant. A owl:Class could have many instances. Is there any way to represent a constant in OWL? The result may look like this:

<Constant rdf:abot="#female" rdf:type="http://www.w3.org/2001/XMLSchema#string">female</Constant>

The question could be rephrased: how to describe a plain string literal in OWL?

JACK M
  • 2,627
  • 3
  • 25
  • 43

2 Answers2

5

In OWL, everything is a constant really. Things (individuals) are constant IRIs, and object properties relate them to other individuals (more constant IRIs), and datatype properties relate them to literals like strings and numbers. You can create enumerations of either kind when you want to do this sort of restriction. If you want to preserve the intention of the XSD schema that you have, you'd probably want to use an enumeration of literals.

Enumeration of Literals

(I've also described this in my answer to Data range expression for an enumeration in Protégé.) In OWL, you can use enumerations of literals when you're specifying the range of a datatype property. For instance, in Protege, you can use the Manchester syntax and specify that the range of a hasSex property is {"male", "female"}:

hasSex with range {male, female}

The Turtle serialization of the RDF mapping of the ontology looks like:

@prefix :      <https://stackoverflow.com/q/36008786/1281433/> .
@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#> .

:hasSex  a          owl:DatatypeProperty ;
        rdfs:range  [ a          rdfs:Datatype ;
                      owl:oneOf  [ a          rdf:List ;
                                   rdf:first  "female" ;
                                   rdf:rest   [ a          rdf:List ;
                                                rdf:first  "male" ;
                                                rdf:rest   ()

                                              ]
                                 ]
                    ] .

Enumeration of Individuals

Of course, you may also want to use individuals as the enumeration constants. You can do that too. You have a few options in this case. In one case, you might have a class that really is a defined set of individuals, in which case you probably want something like:

enumeration of individuals

In Turtle, this looks like:

@prefix :      <https://stackoverflow.com/q/36008786/1281433/> .
@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#> .

:Medium  a      owl:NamedIndividual , :Size .

:Small  a       owl:NamedIndividual , :Size .

:Large  a       owl:NamedIndividual , :Size .

:Size   a                    owl:Class ;
        owl:equivalentClass  [ a          owl:Class ;
                               owl:oneOf  ( :Medium :Large :Small )
                             ] .

If you just want to specify the range of a property, though, you don't have to create the corresponding enumeration class. You can do the same thing that we did the literal enumeration, and just state that the range of the property is an enumeration. E.g., you could say that the range of hasModerateSize is {Small, Medium}, without having defined some class as equivalent to {Small, Medium} beforehand.

Related

Also see:

Community
  • 1
  • 1
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
2

Literals are constants in OWL. The core issue is how to convert a XML schema to OWL, and the translation isn't always straightforward. In cases where there are enumerated values, I'd suggest creating a class and and enumerated list of instances. So try the following edits to your model.:

:GenderClass
    a       owl:Class ;
    rdfs:subClassOf
          [ a       owl:Restriction ;
            owl:maxCardinality "1"^^xsd:int ;
            owl:onProperty :gender
          ] ;
    owl:oneOf (:Class_2_male :Class_2_female) .
:Class_2_male
    a       :GenderClass ;
    rdfs:label "male"^^xsd:string .
:Class_2_female ;
    a       :GenderClass ;
    rdfs:label "female"^^xsd:string .
:gender
    a       owl:ObjectProperty ;
    rdfs:range :GenderClass .

Then instances can be created using the :gender predicate:

:Person1
    a       :Person ;
    :gender :Class_2_female .
scotthenninger
  • 3,921
  • 1
  • 15
  • 24
  • If the point is to remain consistent with the original XSD, though, using the enumeration of strings would make more sense, and it's just as easy. E.g., in manchester syntax you'd declare the range of the property to be `{"male", "female"}`. – Joshua Taylor Mar 15 '16 at 21:29
  • As long as there is no need for metadata on the enumeration, then strings will work just as well. – scotthenninger Mar 15 '16 at 21:51
  • yes, that's an important point, too. I mentioned that, e.g., in [this answer](http://stackoverflow.com/a/18786984/1281433), " If you want to say anything about response types, they need to be individuals. For instance, when response types are individuals, you can give them additional types, ... You won't be able to do this if your ResponseTypes are literals, because literals can't be the subject of statements." – Joshua Taylor Mar 15 '16 at 21:54