如何解决不允许的谓词(闭合形状)验证错误



我正在使用https://shacl.org/playground/

我有以下形状图:

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix d:  <http://learningsparql.com/ns/data#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
hr:ClassShape
a sh:NodeShape ;
sh:targetSubjectsOf rdf:type;
sh:or (
[                
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:hasValue rdfs:Class;
]
[                
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:hasValue rdf:Property;
]
);
sh:closed true ;
.

我有以下数据图

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix d:  <http://learningsparql.com/ns/data#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
#### Regular RDFS modeling ####
hr:Employee a rdfs:Class .
hr:Another a rdfs:Class .
hr:name
rdf:type rdf:Property ; .
hr:hireDate
rdf:type rdf:Property ; .
hr:jobGrade
rdf:type rdf:Property ; .

我想验证每个声明rdf:type的节点都有一个值rdfs:Class或rdf:Property。

我得到以下验证错误:

[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape hr:ClassShape ;
sh:focusNode hr:Employee ;
sh:resultPath rdf:type ;
sh:value rdfs:Class ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape hr:ClassShape ;
sh:focusNode hr:Another ;
sh:resultPath rdf:type ;
sh:value rdfs:Class ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape hr:ClassShape ;
sh:focusNode hr:name ;
sh:resultPath rdf:type ;
sh:value rdf:Property ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape hr:ClassShape ;
sh:focusNode hr:hireDate ;
sh:resultPath rdf:type ;
sh:value rdf:Property ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape hr:ClassShape ;
sh:focusNode hr:jobGrade ;
sh:resultPath rdf:type ;
sh:value rdf:Property ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .

我不知道为什么,也不知道我需要做些什么来解决这些问题。我相信所有的验证错误都是相关的,所以一个的解决方案应该提供其他的解决方案

我的形状文件应该是什么样子?

您混淆了OR语句,下面是关于sh:或的SHACL文档的一个工作示例

@prefix hr: <http://learningsparql.com/ns/humanResources#> .
@prefix d:  <http://learningsparql.com/ns/data#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
hr:ClassShape
a sh:NodeShape ;
sh:targetSubjectsOf rdf:type;
sh:property [
sh:path rdf:type ;
sh:nodeKind sh:IRI ;
sh:or (
[sh:hasValue rdfs:Class;]
[sh:hasValue rdf:Property;]
)
]; 
sh:closed true ;
.

sh:closed只查看直接声明的形状属性。因此,如果你声明,它应该会起作用

hr:ClassShape
sh:property [
sh:path rdf:type ;
] ;
sh:closed true ;
...

闭合形状不考虑sh:或其他复杂结构,详见

https://www.w3.org/TR/shacl/#ClosedConstraintComponent

相关内容

  • 没有找到相关文章

最新更新