如何解决 Predicate is not allowed (closed shape) validation error
How to resolve Predicate is not allowed (closed shape) validation error
我正在使用 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)" ;
] .
我不确定为什么或我需要做什么来解决它们。我相信所有的验证错误都是相关的,所以一个的解决方案应该为其余的提供解决方案。
我的 Shape 文件应该是什么样的?
sh:closed 只查看直接声明的形状属性。所以如果你说
它应该有效
hr:ClassShape
sh:property [
sh:path rdf:type ;
] ;
sh:closed true ;
...
闭合形状不考虑sh:or或其他复杂结构,详见
您混淆了 OR 语句,这里是 SHACL docs on sh:or
之后的工作示例
@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 ;
.
我正在使用 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)" ;
] .
我不确定为什么或我需要做什么来解决它们。我相信所有的验证错误都是相关的,所以一个的解决方案应该为其余的提供解决方案。
我的 Shape 文件应该是什么样的?
sh:closed 只查看直接声明的形状属性。所以如果你说
它应该有效hr:ClassShape
sh:property [
sh:path rdf:type ;
] ;
sh:closed true ;
...
闭合形状不考虑sh:or或其他复杂结构,详见
您混淆了 OR 语句,这里是 SHACL docs on sh:or
之后的工作示例@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 ;
.