【问题标题】:Constrain value of property to a single value?将属性值限制为单个值?
【发布时间】:2016-02-22 16:11:43
【问题描述】:

我想要一个日期属性,它可以有任何个人作为主题(即,对域没有限制),但只能将值 1(双精度)作为值。是否有适合此用例的限制?也许是精确价值?我正在使用 Protege。

【问题讨论】:

    标签: rdf semantic-web owl ontology protege


    【解决方案1】:

    您可以将属性的范围指定为枚举类。在 Protege 中,你可以这样写:

        { 1.0 }

    生成的本体,在 Turtle 和 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>
    

    如果您希望数据类型为 xsd:double 而不是 xsd:decimal,您只需将范围指定为 {"1.0"^^double} 改为:

    【讨论】:

      猜你喜欢
      • 2014-12-26
      • 2012-08-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-17
      • 2020-09-14
      相关资源
      最近更新 更多