Python OwlReady2:如何使用ConstrainedDatatype正确约束DataProperty的范围
我正在阅读并遵循owlready2文档,我已经在ConstrainedDatatype上了。例如:Python OwlReady2:如何使用ConstrainedDatatype正确约束DataProperty的范围,python,owlready,Python,Owlready,我正在阅读并遵循owlready2文档,我已经在ConstrainedDatatype上了。例如: ConstrainedDatatype(int, min_inclusive = 0, max_inclusive = 20) ConstrainedDatatype(str, max_length = 100) 这很简单,但是没有关于如何在上下文中使用它的更多示例。所以我在DataProperty中使用它的实验: with onto: class Drug(Thing0: pass
ConstrainedDatatype(int, min_inclusive = 0, max_inclusive = 20)
ConstrainedDatatype(str, max_length = 100)
这很简单,但是没有关于如何在上下文中使用它的更多示例。所以我在DataProperty中使用它的实验:
with onto:
class Drug(Thing0: pass
class x(DataProperty, FunctionalProperty):
domain = [Drug]
range = ConstrainedDatatype(str, max_length = 3)
现在我保存了owl文件,看看这是否能够正确实现/编写。下面是保存的XML的片段:
<owl:DatatypeProperty rdf:about="#x">
<rdf:type
rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
<rdfs:domain rdf:resource="#Drug"/>
<rdfs:range>
<rdfs:Datatype>
<owl:onDatatype rdf:resource="http://www.w3.org/2001/XMLSchema#string"/>
<owl:withRestrictions>
<rdf:Description>
<rdf:first>
<rdf:Description>
<xsd:maxLength rdf:datatype="http://www.w3.org/2001/XMLSchema#nonNegativeInteger">3</xsd:maxLength>
</rdf:Description>
</rdf:first>
<rdf:rest rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#nil"/>
</rdf:Description>
</owl:withRestrictions>
</rdfs:Datatype>
</rdfs:range>
</owl:DatatypeProperty>
这就是我困惑和疑问的地方。。。由于我试图存储的字符串长度大于3,这不应该引发异常/错误吗?或者我应该使用Imp()类并设置一个规则,以便数据类型限制在单独创建期间生效
提前谢谢 调用
sync\u reasoner()
函数,然后应该引发owlReadyConsistentOnLogyerRor
。非常感谢@StanislavKralin。。。我确实这样做了,但HerniT reasoner没有数据类型推断,所以我使用了Pellet。但是,我的java版本是jdk11(macOS),我有一个java.lang.NoClassDefFoundError:javax/xml/bind/DatatypeConverter。搜索时,它是由Java11中删除的JAXB API引起的。关于如何使用owlready2使用小球有什么想法/经验吗?没有降级到旧版本的java?再次感谢!调用sync\u reasoner()
函数,然后应该引发owlReadyConsistentOnLogyerRor
。非常感谢@StanislavKralin。。。我确实这样做了,但HerniT reasoner没有数据类型推断,所以我使用了Pellet。但是,我的java版本是jdk11(macOS),我有一个java.lang.NoClassDefFoundError:javax/xml/bind/DatatypeConverter。搜索时,它是由Java11中删除的JAXB API引起的。关于如何使用owlready2使用小球有什么想法/经验吗?没有降级到旧版本的java?再次感谢!
y = Drug()
y.x = "this is just an example"