首页 > 解决方案 > 包含和排除父类型的 SHACL 形状定义

问题描述

我有几个涉及类限制的场景。他们中的大多数我都可以开始工作,但有几个我发现有点难以弄清楚。为简单起见,我将从我试图表达的父类型限制开始。

以下将是有效形状,因为它以 ex:Cls1 为目标,使用 ex:parent 指定父级,并且父级具有 ex:P_cls{1, 2, 3} 类型之一。(在所有这些情况下,targetClass 都是 ex:Cls1)。

   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
.
   ex:Parent1
      a ex:Pcls1 ;
.

这将是一个无效的形状,因为必须为父级定义 ex:Pcls{1,2,3} 类型:

   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
.
   ex:Parent1
      a ex:P_clsInvalid_a ;
.

这个是有效的,因为它包括 ex:Pcls{1,2,3} 之一:

   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
   .
   ex:Parent1
      a ex:P_cls2, ex:P_clsInvalid_a ;
   .

第四个是无效的,因为只允许 ex:Pcls{1, 2, 3} 之一:

   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
.
   ex:Parent1
      a ex:P_cls1, ex:P_cls2;
.

如果我可以接受不允许的类型列表(为了维护,我宁愿声明只允许 ex:P_cls{1, 2, 3})然后以下部分有效,因为它不包括第三次使用案子:

   my_sh:ParentTypeRestriction
        a sh:NodeShape ;
        sh:targetClass ex:Cls1 ;
        sh:property[
         sh:path ex:parent ;
         sh:or (
            [ sh:class  ex:P_cls1 ]
            [ sh:class  ex:P_cls2 ]
            [ sh:class  ex:P_cls3 ]
            [ sh:not [ sh:class ex:P_clsInvalid_a ] ]
        ) ;
     sh:maxCount 1 ;
     sh:message "parent type for ex:Cls1 is not in ex:P_cls{1, 2, 3}" ;
] ;
.

..我在其中列出了 sh:not 的详尽列表。如前所述,当模型发生变化时,这并不是最好的,我需要找到所有需要排除它的地方。

那么关于如何 1) 改进这种形状,或 2) 为未来添加到 rdf:type 列表中的任何想法?

非常感谢您的观看。

——斯科特

标签: rdfsubclassshacl

解决方案


推荐阅读