1

我对所有相关文件都有一个要点:https ://gist.github.com/James-Hudson3010/2588d9b17dd33e15922122b8b5cf1bd7

如果我执行:

$ pyshacl -a -f human employees.ttl

我得到以下正确的验证报告...

Validation Report
Conforms: False
Results (3):
Constraint Violation in MaxInclusiveConstraintComponent (http://www.w3.org/ns/shacl#MaxInclusiveConstraintComponent):
    Severity: sh:Violation
    Source Shape: hr:jobGradeShape
    Focus Node: d:e4
    Value Node: Literal("8", datatype=xsd:integer)
    Result Path: hr:jobGrade
Constraint Violation in DatatypeConstraintComponent (http://www.w3.org/ns/shacl#DatatypeConstraintComponent):
    Severity: sh:Violation
    Source Shape: hr:jobGradeShape
    Focus Node: d:e3
    Value Node: Literal("3.14", datatype=xsd:decimal)
    Result Path: hr:jobGrade
Constraint Violation in MinCountConstraintComponent (http://www.w3.org/ns/shacl#MinCountConstraintComponent):
    Severity: sh:Violation
    Source Shape: hr:jobGradeShape
    Focus Node: d:e2
    Result Path: hr:jobGrade

但是,如果我将 employees.ttl 拆分为三个包含架构、形状和实例数据的文件并运行:

pyshacl -s shape.ttl -e schema.ttl -a -f human instance.ttl

结果是:

Validation Report
Conforms: True

我假设我正确地调用了 pyshacl。

4

1 回答 1

2

当您使用单个文件时,pySHACL 无法知道将 Shape 文件的hr:EmployeeNodeShape 与什么相关联。它似乎知道它何时在该单个文件中(也许它针对文件中的所有类运行??)。

所以:

  1. 重命名 Employee 形状以不重载hr:Employee类名:hr:EmployeeShape
  2. sh:targetClass指令中重新添加:
hr:EmployeeShape
   a sh:NodeShape ;
   sh:targetClass hr:Employee ;
   sh:property hr:nameShape ;
   sh:property hr:jobGradeShape .

然后多文件调用给出与单文件调用相同的结果。

您对 pySHACL 的调用是正确的!

于 2020-04-01T12:59:04.127 回答