Search code examples
rdfsemantic-webowlontologyprotege

Constrain value of property to a single value?


I would like to have a date property that can have any individual as is subject (i.e., there is no restriction on the domain), but can only have the value 1 (double) as a value. Is there a restriction suitable for this use case? Perhaps exact or value? I am using Protege.


Solution

  • You can just specify the range of the property as an enumerated class. In Protege, you'd write it as:

        { 1.0 }

    property with range restricted to a single value

    The resulting ontology, in Turtle and RDF/XML:

    @prefix :      <http://example.org/> .
    @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#> .
    
    :p      a           owl:DatatypeProperty ;
            rdfs:range  [ a          rdfs:Datatype ;
                          owl:oneOf  [ a          rdf:List ;
                                       rdf:first  1.0 ;
                                       rdf:rest   ()
    
                                     ]
                        ] .
    
    :       a       owl:Ontology .
    
    <rdf:RDF
        xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
        xmlns="http://example.org/"
        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:Ontology rdf:about="http://example.org/"/>
      <owl:DatatypeProperty rdf:about="http://example.org/p">
        <rdfs:range>
          <rdfs:Datatype>
            <owl:oneOf>
              <rdf:List>
                <rdf:first rdf:datatype="http://www.w3.org/2001/XMLSchema#decimal"
                >1.0</rdf:first>
                <rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
              </rdf:List>
            </owl:oneOf>
          </rdfs:Datatype>
        </rdfs:range>
      </owl:DatatypeProperty>
    </rdf:RDF>
    

    If you want the datatype to be xsd:double rather than xsd:decimal, you just specify the range as {"1.0"^^double} instead:

    similar, but with a different datatype