【问题标题】:restrict xsd:string to [A-Z] for rdfs:range对于 rdfs:range 将 xsd:string 限制为 [A-Z]
【发布时间】:2013-05-24 08:19:03
【问题描述】:

如何将数据类型属性的范围指定为 xsd:strings,其文字形式与 [A-Z] 匹配?至少乍一看,OWL 限制对我没有用。有没有办法用正则表达式做到这一点,如果有,在哪里?

【问题讨论】:

    标签: rdf owl rdfs


    【解决方案1】:

    我想你的意思是“单个大写字母”,即string[pattern "[A-Z]"]

    如果您使用 Protege,请将其输入“数据范围表达式”选项卡。

    HermiT 1.3.7 可以检查这一点并提供关于不一致属性值的解释。

    【讨论】:

      【解决方案2】:

      其他答案解释说,这可以使用 XSD 方面将属性的字符串范围限制为与模式 [A-Z] 匹配的字符串范围,但没有显示结果 RDF。我在 Protégé 中创建了一个非常简单的本体,并定义了一个数据属性hasLatinInitial。正如其他答案所述,范围指定为string[pattern "[A-Z]"]。然后我创建了一个单独的JohnDoe 并添加了

      的数据属性断言
      JohnDoe hasLatinInitial "J" .
      JohnDoe hasLatinInitial "D" .
      

      HermiT 1.3.7 确实运行并且报告没有不一致。然后我添加了断言

      JohnDoe hasLatinInitial "3" .
      

      和 HermiT 1.3.7 报告不一致:

      这是生成的本体在 N3 和 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>
      

      【讨论】:

      • 这很有帮助,尤其是 N3 部分,因为我不使用 Protegé
      • @chile 如果这有帮助,您可能需要考虑 accepting it 让其他用户知道它对您有用,减少未回答问题的数量,并给您和我一个很少的声望点。
      • @JT 好吧,毕竟我不必使用这个限制,所以我没有实施它,也不能确定哪个是正确的答案。无论如何,您的解决方案对我来说似乎很合理。
      • 有没有一种简单的方法可以让它连续处理多个字符?那么,我可以告诉它连续接受 (min=)1 到 (max=)3(或更多)个字符,而不是输入 string[pattern "[A-Z][A-Z][A-Z]"] 吗?
      【解决方案3】:

      曼彻斯特语法中的以下表达式应该可以解决问题:

      string[pattern "A-Z"]

      您可以直接将其作为 Protege 中的数据范围。不过,我不确定是什么推理者在实现该构造,我以前从未使用过它。

      更多信息:http://www.w3.org/TR/owl2-manchester-syntax/#facet

      【讨论】:

        猜你喜欢
        • 2015-04-29
        • 2017-01-22
        • 2014-02-09
        • 2013-08-30
        • 2010-12-27
        • 1970-01-01
        • 1970-01-01
        • 2016-02-26
        • 1970-01-01
        相关资源
        最近更新 更多