restrict xsd:string to [A-Z] for rdfs:range
Asked Answered
W

3

9

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?

Wakerobin answered 24/5, 2013 at 8:19 Comment(0)
K
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.

Katabolism answered 24/5, 2013 at 8:58 Comment(0)
F
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>

Ferminafermion answered 24/5, 2013 at 14:48 Comment(4)
this is very helpful, especially the N3 part, since I don't use ProtegéWakerobin
@Wakerobin If this was helpful, you might want to consider accepting it 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.Ferminafermion
@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.Wakerobin
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?Questionable
P
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

Picaresque answered 24/5, 2013 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.