文字的推理和数据类型
Reasoning and datatypes of Literals
在 Turtle-RDF 中,省略字符串文字的数据类型扩展 ^^xsd:string
很方便。但是当我尝试用 StarDog http://www.stardog.com/ 进行推理时,只有扩展名为 "green"^^xsd:string
的个体 :YYY
被发现是 :GreenButton
@prefix : < .
@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#> .
:color a owl:DatatypeProperty ;
rdfs:range xsd:string ;
rdfs:domain :Button .
:XXX :color "green" .
:YYY :color "green"^^xsd:string .
:Button a rdfs:Class .
:GreenButton a rdfs:Class ;
owl:equivalentClass [ a owl:Restriction;
owl:onProperty :color ;
owl:hasValue "green"
] .
:TestButton a :GreenButton .
推理结果:
+-------------+----------+----------------------------------------------------+
| s | p | o |
+-------------+----------+----------------------------------------------------+
| :XXX | rdf:type | :Button |
| :YYY | rdf:type | :Button |
| :YYY | rdf:type | :GreenButton |
| :TestButton | rdf:type | :GreenButton |
| :TestButton | :color | "green"^^<http://www.w3.org/2001/XMLSchema#string> |
...
最好的处理方法是什么?
根据 docs:
RDF parsing in Stardog is strict: it requires typed RDF literals to
match their explicit datatypes, URIs to be well-formed, etc. In some
cases, strict parsing isn’t ideal—it may be disabled using the
--strict-parsing=FALSE.
However, even with strict parsing disabled, Stardog’s RDF parser may
encounter parse errors from which it cannot recover. And loading data
in lax mode may lead to unexpected SPARQL query results. For example,
malformed literals ("2.5"^^xsd:int) used in filter evaluation may lead
to undesired results.
您是否尝试过禁用严格解析并查看效果如何?
p.s。请参阅约书亚在问题中的评论。我不建议关闭严格解析,但如果处理 arbitrary/external 稀疏类型的数据(假设它确实解决了问题),它可能是唯一的选择。
根据OWL语义,"green"
和"green"^^xsd:string
实际上是等价的。它们在 RDF 1.1 中也是等效的。 Stardog 尚不支持 RDF 1.1,并且如您所见,存在字符串文字推理错误。您的观察是正确的:OWL 公理中的普通文字会自动转换为 xsd:string
但实例断言中的文字不会。有一个针对此问题的开放票证 (#2340),您可以在以后查看发行说明以了解何时修复此问题。在此之前,解决方法是始终使用 xsd:string
作为实例。
在 Turtle-RDF 中,省略字符串文字的数据类型扩展 ^^xsd:string
很方便。但是当我尝试用 StarDog http://www.stardog.com/ 进行推理时,只有扩展名为 "green"^^xsd:string
的个体 :YYY
被发现是 :GreenButton
@prefix : < .
@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#> .
:color a owl:DatatypeProperty ;
rdfs:range xsd:string ;
rdfs:domain :Button .
:XXX :color "green" .
:YYY :color "green"^^xsd:string .
:Button a rdfs:Class .
:GreenButton a rdfs:Class ;
owl:equivalentClass [ a owl:Restriction;
owl:onProperty :color ;
owl:hasValue "green"
] .
:TestButton a :GreenButton .
推理结果:
+-------------+----------+----------------------------------------------------+
| s | p | o |
+-------------+----------+----------------------------------------------------+
| :XXX | rdf:type | :Button |
| :YYY | rdf:type | :Button |
| :YYY | rdf:type | :GreenButton |
| :TestButton | rdf:type | :GreenButton |
| :TestButton | :color | "green"^^<http://www.w3.org/2001/XMLSchema#string> |
...
最好的处理方法是什么?
根据 docs:
RDF parsing in Stardog is strict: it requires typed RDF literals to match their explicit datatypes, URIs to be well-formed, etc. In some cases, strict parsing isn’t ideal—it may be disabled using the --strict-parsing=FALSE.
However, even with strict parsing disabled, Stardog’s RDF parser may encounter parse errors from which it cannot recover. And loading data in lax mode may lead to unexpected SPARQL query results. For example, malformed literals ("2.5"^^xsd:int) used in filter evaluation may lead to undesired results.
您是否尝试过禁用严格解析并查看效果如何?
p.s。请参阅约书亚在问题中的评论。我不建议关闭严格解析,但如果处理 arbitrary/external 稀疏类型的数据(假设它确实解决了问题),它可能是唯一的选择。
根据OWL语义,"green"
和"green"^^xsd:string
实际上是等价的。它们在 RDF 1.1 中也是等效的。 Stardog 尚不支持 RDF 1.1,并且如您所见,存在字符串文字推理错误。您的观察是正确的:OWL 公理中的普通文字会自动转换为 xsd:string
但实例断言中的文字不会。有一个针对此问题的开放票证 (#2340),您可以在以后查看发行说明以了解何时修复此问题。在此之前,解决方法是始终使用 xsd:string
作为实例。