0

我正在使用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 文件应该是什么样的?

4

2 回答 2

1

您混淆了 OR 语句,这是sh:or 上的 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 ;
.
于 2020-04-15T10:57:25.513 回答
0

sh:close 只查看直接声明的形状属性。所以如果你说它应该工作

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

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

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

于 2020-04-03T05:18:18.343 回答