SHACL验证器可以作为焦点节点的验证对象返回主题吗?
我们正在尝试验证一些数据,但是现在SHACL验证在三重数据的匿名对象上,因此焦点节点回到空。我们想要的是将该主题作为焦点节点。
我创建了一个小例子来说明我的问题。
我的shapes.ttl
文件:
@prefix ex: <http://example.com#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:DiameterShape
rdf:type sh:NodeShape ;
sh:property [
sh:path ex:hasValue ;
sh:datatype xsd:integer ;
sh:message "Diameter should be an integer"@en ;
] ;
sh:property [
sh:path ex:hasValue ;
sh:maxInclusive 4000 ;
sh:minInclusive 300 ;
sh:message "Diameter should be between 300 and 4000"@en ;
sh:severity sh:Warning ;
] ;
sh:targetClass ex:Diameter ;
.
ex:ThingShape
rdf:type sh:NodeShape ;
sh:property [
sh:path ex:hasAspect ;
sh:class ex:Diameter ;
] ;
sh:targetClass ex:Thing ;
.
我的data.ttl
文件:
@prefix ex: <http://example.com#> .
ex:Thing_123
a ex:Thing ;
ex:hasAspect [
a ex:Diameter ;
ex:hasValue 200 ;
] .
其中包含无效的数据。运行shaclvalidator工具...
shaclvalidate.bat -datafile data.ttl -shapesfile shapes.ttl
...返回错误,但请注意焦点节点是空的...这意味着在足够大的数据集中,无法找到错误的来源。理想情况下,我们希望将ex:thing_123
作为焦点节点。
我们只能控制形状文件,因此摆脱匿名节点不是一个选择。
[ rdf:type sh:ValidationReport ;
sh:conforms false ;
sh:result [ rdf:type sh:ValidationResult ;
sh:focusNode [] ;
sh:resultMessage "Diameter should be between 300 and 4000"@en ;
sh:resultPath ex:hasValue ;
sh:resultSeverity sh:Warning ;
sh:sourceConstraintComponent sh:MinInclusiveConstraintComponent ;
sh:sourceShape [] ;
sh:value 200
]
] .
提前致谢!
we're trying to validate some data but right now the SHACL validation is on the anonymous object of a triple so focus node comes back empty. What we want is to get the subject of that triple as focus node.
I created a small example to illustrate my problem.
My shapes.ttl
file:
@prefix ex: <http://example.com#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:DiameterShape
rdf:type sh:NodeShape ;
sh:property [
sh:path ex:hasValue ;
sh:datatype xsd:integer ;
sh:message "Diameter should be an integer"@en ;
] ;
sh:property [
sh:path ex:hasValue ;
sh:maxInclusive 4000 ;
sh:minInclusive 300 ;
sh:message "Diameter should be between 300 and 4000"@en ;
sh:severity sh:Warning ;
] ;
sh:targetClass ex:Diameter ;
.
ex:ThingShape
rdf:type sh:NodeShape ;
sh:property [
sh:path ex:hasAspect ;
sh:class ex:Diameter ;
] ;
sh:targetClass ex:Thing ;
.
My data.ttl
file:
@prefix ex: <http://example.com#> .
ex:Thing_123
a ex:Thing ;
ex:hasAspect [
a ex:Diameter ;
ex:hasValue 200 ;
] .
Which contains invalid data. Running the shaclvalidator tool...
shaclvalidate.bat -datafile data.ttl -shapesfile shapes.ttl
...returns the error but notice the focus node is empty... meaning in a large enough data set it's impossible to find where the error comes from. Ideally we want to see ex:Thing_123
as focus node.
We only have control over the shapes file so getting rid of anonymous nodes is not an option.
[ rdf:type sh:ValidationReport ;
sh:conforms false ;
sh:result [ rdf:type sh:ValidationResult ;
sh:focusNode [] ;
sh:resultMessage "Diameter should be between 300 and 4000"@en ;
sh:resultPath ex:hasValue ;
sh:resultSeverity sh:Warning ;
sh:sourceConstraintComponent sh:MinInclusiveConstraintComponent ;
sh:sourceShape [] ;
sh:value 200
]
] .
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
SH:FocusNode并不是完全空的。您看到的是乌龟渲染,在乌龟中,没有语法可以从您要引用的另一个文档中表达哪个特定空白节点。
但是,在程序化侧,sh:focusnode将指向数据图中也可以找到的相同(jena)节点。因此,目前唯一真正的解决方案是不使用命令行工具,而是将验证结果用作(Java)程序的一部分。在两个图中,空白节点ID都将相同,然后您可以通过行走传入的参考文献来查找数据图中的“ root”主题。这不是Topbraid ShaCl发动机现在自动做的任何事情,即使它可以这样做可能有多个空白节点。
The sh:focusNode is not exactly empty. What you see is the Turtle rendering, and in Turtle there is no syntax to express which particular blank node from another document you want to reference.
However, on the programmatic side, the sh:focusNode will point at the same (Jena) node that is also found in the data graph. So the only real solution right now is to not use the command line tool but instead use the validation results as part of a (Java) program. The blank node ID will be the same in both graphs and you can then look up the "root" subject like ex:Thing_123 in the data graph by walking up the incoming references. This is not anything that the TopBraid SHACL engine does automatically right now, and even if it would do that there might be multiple blank nodes underneath.