shexSpec / shex

ShEx language issues, including new features for e.g. ShEx2.1
24 stars 8 forks source link

Customize validation of some constraints #94

Open labra opened 4 years ago

labra commented 4 years ago

This feature has been requested by a simple use case. Some users want to use the same shapes to describe data which validate the same data before and after applying inference.

For example, imagine some RDF data like the following:

:alice a :Teacher ;
         schema:name "Alice" .

:Teacher rdfs:subClassOf :Person .

A possible shape for teachers before RDFS inference could be:

<TeacherShape> {
 a [ :Teacher]  ;
 schema:name xsd:string ;
}

but if we apply inference, that node would no longer conform, because the inference system would add the triple :alice a :Person.

A possible shape for teachers after inference could be:

<TeacherShape> {
 a [ :Teacher]  ;
 a [:Person ] ;
 schema:name xsd:string ;
}

But in this case, the node before inference would not conform as expected.

Although this is right, from a practical point of view, keeping two set of shapes, one for shapes of nodes before inference and another for shapes of nodes after inference can be problematic so some users (see this issue ), are requesting some solution to have a single shape file which can be used to validate both before and after inference.

One solution could be to define some annotations to disable the validation of some constraints when some conditions are met

For example, a shape for the previous case could be:

<TeacherShape> {
 a [ :Teacher]  ;
 a [:Person ] ;  // sx:applyWhen sx:RDFSEntailment 
 schema:name xsd:string ;
}

where the annotation sx:applyWhen defines that the triple constraint a [:Person] should only be applied when the validation is performed after RDFS inference.

Maybe there are other solutions or best practices that we could recommend for this use case.

ericprud commented 4 years ago

@hsolbrig had a similar issue where his data had non-redundant type arcs; when validating an instance of :Dog as :Animal, it would be nice to infer that the

<S> { a [:Animal] }

constraint was met by the data:

<n> a :Dog .

Would such inference by specified by RDFS written in another graph?