OWL:将属性值限制为数字字符串

发布于 2024-09-29 17:24:14 字数 92 浏览 0 评论 0 原文

在我的数据库中,我有一些带有字符串属性的东西。某些属性值与数字字符串匹配(仅包含数字)。我想给这些东西一个特殊的类型(它们本身的子类型)。在OWL中这样的事情可能发生吗?

In my database I have things with string properties. Some of the property values match numeric strings (only contain digits). I'd like to give these things a special type (a subtype of what they are). Is such a thing possible in OWL?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故事还在继续 2024-10-06 17:24:14

我认为您需要将数据类型限制xsd:pattern结合使用。

以下公理来自 OWL 2 Primer ...

:Teenager  rdfs:subClassOf
       [ rdf:type             owl:Restriction ;
         owl:onProperty       :hasAge ;
         owl:someValuesFrom   
          [ rdf:type             rdfs:Datatype ;
            owl:onDatatype       xsd:integer ;
            owl:withRestrictions (  [ xsd:minExclusive     "12"^^xsd:integer ]
                                    [ xsd:maxInclusive     "19"^^xsd:integer ]
            )
          ]
       ] .

...如果您转变使用xsd:pattern我们可以得到类似的东西...

:YourClass  rdfs:subClassOf
       [ rdf:type             owl:Restriction ;
         owl:onProperty       :yourHasNumericProperty ;
         owl:someValuesFrom   
          [ rdf:type             rdfs:Datatype ;
            owl:onDatatype       xsd:integer ;
            owl:withRestrictions  ([xsd:pattern "E[1-9][0-9]*"])
          ]
       ] .

使用xsd:pattern你可以基于正则表达式进行数据类型限制。

我希望这能给你一些指导。

I think that you need are Datatype Restrictions in combination with xsd:pattern.

The following axiom is from OWL 2 Primer ...

:Teenager  rdfs:subClassOf
       [ rdf:type             owl:Restriction ;
         owl:onProperty       :hasAge ;
         owl:someValuesFrom   
          [ rdf:type             rdfs:Datatype ;
            owl:onDatatype       xsd:integer ;
            owl:withRestrictions (  [ xsd:minExclusive     "12"^^xsd:integer ]
                                    [ xsd:maxInclusive     "19"^^xsd:integer ]
            )
          ]
       ] .

... and if you shift it a bit with xsd:pattern we can have something like ...

:YourClass  rdfs:subClassOf
       [ rdf:type             owl:Restriction ;
         owl:onProperty       :yourHasNumericProperty ;
         owl:someValuesFrom   
          [ rdf:type             rdfs:Datatype ;
            owl:onDatatype       xsd:integer ;
            owl:withRestrictions  ([xsd:pattern "E[1-9][0-9]*"])
          ]
       ] .

With xsd:pattern you can do Datatype Restriction based on regular expressions.

I hope this gives you some directions.

天涯沦落人 2024-10-06 17:24:14

实际上你可以在 RDF 中做一些事情。对于 RDF 中的任何文字,您可以使用类似的方式指定类型(在turtle/RDF 中)...

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
:x :myDataTypeProperty "123"^^xsd:integer .
:y :myDataTypeProperty "some string"^^xsd:string .
:z :myDataTypeProperty "2004-12-06"^^xsd:date .

RDF/XML 中的相同示例

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns="http://www.foo.bar.com#">
  <rdf:Description rdf:about="http://www.foo.bar.com#x">
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">123</myDataTypeProperty>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.foo.bar.com#y">
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#string">some string</myDataTypeProperty>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.foo.bar.com#z">
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2004-12-06</myDataTypeProperty>
  </rdf:Description>
</rdf:RDF>

XMLSchema (XSD) 规范您可以找到所有支持的数据类型。 只使用 SPARQL 规范 中提到的那些

但请确保您 如果您想要并且有类似的内容,请创建您自己的数据类型:

:x :myDataTypeProperty "123"^^ns:MyClassificationScheme .

您可以进一步说...

ns:MyClassificationScheme rdfs:subClassOf xsd:integer .

当您对数据发出 SPARQL 查询时,您可以在发出应用过滤器时指定类型,如下所示:

SELECT * WHERE { 
   ?person :born ?birthDate .
   FILTER ( ?birthDate > "2005-02-28"^^xsd:date ) .
}

我希望这回答了您的问题问题。

已编辑

正如panzi提到的,​​我的答案走错了方向。无论如何我还是离开了。

Is actually something you can do in RDF. For any literal in RDF you can specify the type with something like this (in turtle/RDF) ...

@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
:x :myDataTypeProperty "123"^^xsd:integer .
:y :myDataTypeProperty "some string"^^xsd:string .
:z :myDataTypeProperty "2004-12-06"^^xsd:date .

Same example in RDF/XML

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" xmlns="http://www.foo.bar.com#">
  <rdf:Description rdf:about="http://www.foo.bar.com#x">
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#integer">123</myDataTypeProperty>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.foo.bar.com#y">
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#string">some string</myDataTypeProperty>
  </rdf:Description>
  <rdf:Description rdf:about="http://www.foo.bar.com#z">
    <myDataTypeProperty rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2004-12-06</myDataTypeProperty>
  </rdf:Description>
</rdf:RDF>

In the XMLSchema (XSD) spec you can find out all the supported datatypes. But be sure that you only use the ones mentioned in the SPARQL spec

You could mint your own data types if you wanted and have something like:

:x :myDataTypeProperty "123"^^ns:MyClassificationScheme .

And you could go further and say that ...

ns:MyClassificationScheme rdfs:subClassOf xsd:integer .

When you issue SPARQL query against data you can specify the type when you issue apply filters, like this:

SELECT * WHERE { 
   ?person :born ?birthDate .
   FILTER ( ?birthDate > "2005-02-28"^^xsd:date ) .
}

I hope this answered your question.

Edited

As panzi mentioned my answer was going in the wrong direcction. I leave it anyway.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文