SHACL Shape definition for including and excluding parent types

I have a couple of scenarios that involve restrictions on classes.  Most of
them I can get working, but a couple I'm finding a bit difficult to figure
out.  To make it simple, I'll start with the parent type restriction I'm
trying to express.

The following would be a valid shape as it targets ex:Cls1, specifies a
parent with ex:parent, and the parent has one of the types ex:P_cls{1, 2,
3}.  (In all of these cases the targetClass is ex:Cls1).
   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
..
   ex:Parent1
      a ex:Pcls1 ;
..

This would be an invalid shape because ex:Pcls{1,2,3} types must be defined
for the parent:
   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
..
   ex:Parent1
      a ex:P_clsInvalid_a ;
..

This one is valid because it includes one of ex:Pcls{1,2,3}:
   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
   .
   ex:Parent1
      a ex:P_cls2, ex:P_clsInvalid_a ;
   .

The fourth is invalid because only one of ex:Pcls{1, 2, 3} is allowed:
   ex:Child1
      a ex:Cls1 ;
      ex:parent ex:Parent1 ;
..
   ex:Parent1
      a ex:P_cls1, ex:P_cls2;
..

If I could live with a list of disallowed types (for the sake of
maintenance I'd rather say allow only ex:P_cls{1, 2, 3}) then the following
seems to work:
   my_sh:ParentTypeRestriction
         a sh:NodeShape ;
        sh:targetClass ex:Cls1 ;
        sh:property[
         s h: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:message "parent type for ex:Cls1 is not in x:P_cls{1, 2, 3}" ;
] ;
..

...where I include an exhaustive list for sh:not.  As stated before, this
isn't the best when the model changes and I need to find all the places
where it needs to be excluded.

So any ideas on how to 1) improve this shape, or 2) future-proof it for
future additions to the rsf:type list?

Thanks a bunch for taking a look.
-- Scott

Scott Henninger
scotthenninger@gmail.com

Received on Tuesday, 14 September 2021 18:14:38 UTC