在 SHACL 规范中,据我所知,没有什么禁止关闭 PropertyShape。
以下是来自SHACL Playground的默认示例,已纠正默认错误,因此数据有效。
形状:
@prefix dash: <http://datashapes.org/dash#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix sh: <http://www.w3.org/ns/shacl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
schema:PersonShape
a sh:NodeShape ;
sh:targetClass schema:Person ;
sh:property [
sh:path schema:givenName ;
sh:datatype xsd:string ;
sh:name "given name" ;
] ;
sh:property [
sh:path schema:birthDate ;
sh:lessThan schema:deathDate ;
sh:maxCount 1 ;
] ;
sh:property [
sh:path schema:gender ;
sh:in ( "female" "male" ) ;
] ;
sh:property [
sh:path schema:address ;
sh:node schema:AddressShape ;
] .
schema:AddressShape
a sh:NodeShape ;
sh:closed true ;
sh:property [
sh:path schema:streetAddress ;
sh:datatype xsd:string ;
] ;
sh:property [
sh:path schema:postalCode ;
sh:or ( [ sh:datatype xsd:string ] [ sh:datatype xsd:integer ] ) ;
sh:minInclusive 10000 ;
sh:maxInclusive 99999 ;
] .
数据(有效 - 无验证结果):
@prefix ex: <http://example.org/ns#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:Bob
a schema:Person ;
schema:givenName "Robert" ;
schema:familyName "Junior" ;
schema:birthDate "1971-07-07"^^xsd:date ;
schema:deathDate "2068-09-10"^^xsd:date ;
schema:address ex:BobsAddress .
ex:BobsAddress
schema:streetAddress "1600 Amphitheatre Pkway" ;
schema:postalCode 19404
现在,当您关闭类似的sh:path schema:address
属性形状时schema:PersonShape
:
sh:property [
sh:closed true ;
sh:path schema:address ;
sh:node schema:AddressShape ;
] .
通过此更改,有验证结果:
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape _:n1121 ;
sh:focusNode <http://example.org/ns#Bob> ;
sh:resultPath schema:streetAddress ;
sh:value "1600 Amphitheatre Pkway" ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .
[
a sh:ValidationResult ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:ClosedConstraintComponent ;
sh:sourceShape _:n1121 ;
sh:focusNode <http://example.org/ns#Bob> ;
sh:resultPath schema:postalCode ;
sh:value 19404 ;
sh:resultMessage "Predicate is not allowed (closed shape)" ;
] .
sh:close的规范说:
[...] 一个名为 sh:close 的属性,可用于指定条件,即每个值节点仅具有通过 sh:property 为形状指定的属性形状显式枚举的那些属性的值。
很抱歉:我无法解释正在发生的事情以及应该发生的事情(如果两者不同)。
有人可以解释观察到/指定的行为吗?
谢谢!