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

问题描述 投票:0回答:1

我正在使用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)" ;
] .

我不确定为什么或需要做什么来解决它们。我相信所有验证错误都是相关的,因此对一个的解决方案应为其余的解决方案。

validation rdf shacl
1个回答
0
投票

sh:closed仅查看形状的直接声明的属性。因此,如果您声明,它应该可以工作

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

闭合的形状不考虑sh:或其他复杂结构,请参见以下详细信息

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

© www.soinside.com 2019 - 2024. All rights reserved.