简体   繁体   中英

SHACL shapes for sub-graph validation

I want to validate the order of predicates in a sub-graph using SHACL. Theoretically, I think I would have to use SHACL shapes for each of the predicates, which are linked together, and then define a conditional statement that checks if the first predicate is present, then keep traversing the graph for the next predicate.

For example:

<bob> foaf:knows <emma>.
<emma> ontology1:gender <woman>.
<woman> ontology1:species <human>.
<human> ontology2:category <earth>.

In this, I would like to check that the sequence of the predicates:-

foaf:knows -> ontology1:gender -> ontology1:species -> ontology2:category

I've poured through loads of documentation, but yet to find an example for this. Any idea how to do this with SHACL core features? Or even with SHACL-SPARQL?

If ontology1:gender and ontology1:species can't have more than one value, then use objects-of targets and sequence paths . Like this:

:FellowShape
   sh:targetObjectsOf foaf:knows ;
   sh:property [
      sh:path (ontology1:gender ontology1:species ontology2:category) ;
      sh:message "Property chain is broken" ;
      sh:minCount 1
   ] .

Playground .

Just as an alternative, the important point is that the target needs to be part of the triple that starts the property chain. In this case that is the object of foaf:knows. There are a few ways of doing this, including:

:FellowShape
   sh:targetNode :emma ;
   sh:property [
      sh:path (ontology1:gender ontology1:species ontology2:category) ;
      sh:message "Property chain is broken" ;
      sh:minCount 1
   ] .

Note that sh:targetNode :emma is used instead of sh:targetObjectsOf foaf:knows , both of which tell the Shape specification to start with foaf:knows :emma .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM