[英]Can a SHACL validator return subject of validated object as focus node?
我們正在嘗試驗證一些數據,但現在 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
]
] .
提前致謝!
sh:focusNode 並不完全為空。 您看到的是 Turtle 渲染,在 Turtle 中,沒有語法來表示您要引用的另一個文檔中的哪個特定空白節點。
但是,在編程方面,sh:focusNode 將指向在數據圖中也可以找到的同一(耶拿)節點。 因此,目前唯一真正的解決方案是不使用命令行工具,而是將驗證結果用作(Java)程序的一部分。 兩個圖中的空白節點 ID 將相同,然后您可以通過遍歷傳入的引用在數據圖中查找“根”主題,例如 ex:Thing_123。 這不是 TopBraid SHACL 引擎現在自動執行的任何操作,即使它會這樣做,下面也可能有多個空白節點。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.