8

How can I specify the range of a datatype property to be xsd:strings whose literal forms match [A-Z]? OWL restrictions don't do the trick for me, at least at first glance. Is there a way to do this with regular expressions and if so, where?

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
chile
  • 724
  • 1
  • 7
  • 15

3 Answers3

5

I suppose you mean "single capital letter" which is string[pattern "[A-Z]"].

If you are using Protege, enter this into the "Data range expression" tab.

HermiT 1.3.7 can check this and provide explanations about inconsistent property values.

utapyngo
  • 6,946
  • 3
  • 44
  • 65
3

Other answers have explained that this can be done using the XSD facets to restrict the string range of the property to those matching the pattern [A-Z], but none showed the resulting RDF. I created a very simple ontology in Protégé and defined a data property hasLatinInitial. As other answers described, the range was specified as string[pattern "[A-Z]"]. Then I created an individual JohnDoe and added the data property assertions that

JohnDoe hasLatinInitial "J" .
JohnDoe hasLatinInitial "D" .

and HermiT 1.3.7 indeed ran and reported no inconsistency. I then added the assertion

JohnDoe hasLatinInitial "3" .

and HermiT 1.3.7 reported an inconsistency:

enter image description here

Here's what the resulting ontology looks like in N3 and in RDF/XML:

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

<http://www.example.com/example>
      a       owl:Ontology .

example:hasLatinInitial
      a       owl:DatatypeProperty ;
      rdfs:range
              [ a       rdfs:Datatype ;
                owl:onDatatype xsd:string ;
                owl:withRestrictions
                        ([ xsd:pattern "[A-Z]"
                          ])
              ] .

example:JohnDoe
      a       owl:NamedIndividual ;
      example:hasLatinInitial
              "3" , "J" , "D" 
<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:example="http://www.example.com/example#"
    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.com/example"/>
  <owl:DatatypeProperty rdf:about="http://www.example.com/example#hasLatinInitial">
    <rdfs:range>
      <rdfs:Datatype>
        <owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
        <owl:withRestrictions rdf:parseType="Collection">
          <rdf:Description>
            <xsd:pattern>[A-Z]</xsd:pattern>
          </rdf:Description>
        </owl:withRestrictions>
      </rdfs:Datatype>
    </rdfs:range>
  </owl:DatatypeProperty>
  <owl:NamedIndividual rdf:about="http://www.example.com/example#JohnDoe">
    <example:hasLatinInitial>3</example:hasLatinInitial>
    <example:hasLatinInitial>D</example:hasLatinInitial>
    <example:hasLatinInitial>J</example:hasLatinInitial>
  </owl:NamedIndividual>
</rdf:RDF>

Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
  • this is very helpful, especially the N3 part, since I don't use Protegé – chile Jun 02 '13 at 06:50
  • @chile If this was helpful, you might want to consider [accepting it](http://meta.stackexchange.com/q/5234/225437) to let other users know that it worked for you, to reduce the number of unanswered questions, and to give both you and me a few reputation points. – Joshua Taylor Jan 20 '14 at 20:50
  • @JT well I did not had to use this restriction after all, so I did not implement it and could not say for certain which is the correct answer. Anyway, your solution looks quiet plausible to me. – chile Jan 22 '14 at 08:57
  • Is there a simple way to make it work for multiple characters in a row? So, instead of having to put `string[pattern "[A-Z][A-Z][A-Z]"]`, could I tell it to accept (min=)1 through (max=)3 (or more) characters in a row? – Daniel B. Sep 23 '20 at 09:42
1

The following expression in Manchester syntax should do the trick:

string[pattern "A-Z"]

You can put it straight as data range in Protege. I'm not sure what reasoners are implementing the construct though, I've never used it before.

More information on it: http://www.w3.org/TR/owl2-manchester-syntax/#facet

ericP
  • 1,675
  • 19
  • 21
loopasam
  • 3,027
  • 2
  • 21
  • 22