Как решить Предикат не допускается (закрытая форма) ошибка проверки - PullRequest
0 голосов
/ 02 апреля 2020

Я использую 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: имеет значение 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?

Ответы [ 2 ]

1 голос
/ 15 апреля 2020

Вы перепутали оператор OR, вот рабочий пример после SHACL документов на sh: или

@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 ;
.
0 голосов
/ 03 апреля 2020

sh: закрыто только при просмотре непосредственно объявленных свойств фигуры. Так что это должно работать, если вы укажете

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

Закрытые фигуры не учитывают sh: или другие сложные структуры, см. Подробности в

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

...