我正在尝试在任何推理系统或三重存储提供的加载时验证之外设置一些轻量级的按需数据验证 . 我正在使用GraphDB 8.3 .
假设我使用生物医学调查的本体论(OBI)加载以下三元组,http://purl.obolibrary.org/obo/obi.owl:
PREFIX : <http://example.com/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
insert data {
graph :data
{
:measurement1 a <http://purl.obolibrary.org/obo/IAO_0000032> ;
<http://purl.obolibrary.org/obo/IAO_0000004> "100.1"^^xsd:double .
:measurement2 a <http://purl.obolibrary.org/obo/IAO_0000032> ;
<http://purl.obolibrary.org/obo/IAO_0000004> "100"^^xsd:int .
}
}
这表示 :measurement1
和 :measurement2
具有测量值 . <http://purl.obolibrary.org/obo/IAO_0000004>
的范围是 xsd:double
. 我知道我可以使用类似下面的查询来检查与指定范围不完全相同的数据类型 .
正如您在查询中嵌入的注释中所看到的,我想说 :measurement2
的 "100"^^xsd:int
的值是可接受的,因为所有整数都包含在双精度浮点数集中 . (对?)
Is there an existing ontology that says that xsd:int is a sub-something of xsd:double?
PREFIX : <http://example.com/>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX obo: <http://purl.obolibrary.org/obo/>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
# loaded obi into http://example.com/ontology
select distinct ?stype ?p ?ptype ?propdom ?proprange ?otype ?odatatype where {
{
graph :data
{
?s ?p ?o .
bind (datatype(?o) as ?odatatype)
}
optional {
graph <http://example.com/ontology> {
values ?ptype {
owl:ObjectProperty owl:DatatypeProperty
}
?p a ?ptype
}
}
optional {
?o a ?otype
}
optional {
?s a ?stype
}
optional {
{
graph <http://example.com/ontology> {
?p rdfs:domain ?propdom
}
}
}
optional {
{
graph <http://example.com/ontology> {
?p rdfs:range ?proprange
}
}
}
}
minus
{
?s rdf:type ?o
}
# minus
# {
# ?odatatype rdfs:subClassOf+ ?proprange
# }
filter ( ?odatatype != ?proprange )
}
4 回答
XSD数据类型没有子类 . 有派生类型:
xsd:int
是xsd:integer
的派生类型;它是XSD定义的功能 .xsd:int
不是xsd:double
的派生类型 .数据类型中重要的是值:
"100"^^xsd:int
和"100"^^xsd:double
是相同的值 . SHACL可以表达这一点 .见https://www.w3.org/TR/xpath-datamodel-3/#types-hierarchy中的"Atomic Types"
回答你的问题:
错误!如你所说,
xsd:double
包含一组双精度浮点数,它不包含格雷厄姆数和其他大整数等数字 .如果有(我怀疑有),它与XSD的规格不一致(见上面的评论) .
对此,我应该补充一个事实,即XSD将
xsd:decimal
的值空间定义为与xsd:double
的值不相交 . 这意味着xsd:int
的值空间也与xsd:double
的值空间不相交 .一般情况下,我建议您尽可能使用
xsd:decimal
而不是xsd:double
.xsd:double
表明使用您的数据或本体的系统永远不可能处理更好的精度或更大的数量_1141140_ .如果有任何这样的本体,它们肯定是自定义用户设计的 . 我不知道有任何W3C标准 . 这个(https://www.w3.org/TR/xmlschema-2/#built-in-datatypes)图表显示整数是从十进制的"derived",但我不知道它可以在多大程度上用作ersatz subClassOf或任何类型 .
在某种程度上,规范就是这样做的 . 参见例如:https://www.w3.org/TR/swbp-xsch-datatypes/#sec-values
但是,如果没有任何推理器,您将不得不在多个数据类型共有的时间间隔和值上复制数据类型推理 .