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

穿精又带淫゛_ 提交于 2019-12-09 16:48:47

问题


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?


回答1:


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.




回答2:


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:

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>




回答3:


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



来源:https://stackoverflow.com/questions/16730529/restrict-xsdstring-to-a-z-for-rdfsrange

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!