I want to use shacl to validate if a specific relationship exist, that another relationship exists as well.
For example, given the next data with 1 person listing the other 2 as their parent, I want to verify that those parents list the the first person as their child as well. If no parents are listed, that is also a valid node.
@prefix ex: <http://www.example.com#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
ex:12345 a ex:Person ;
ex:name "Harry" ;
ex:birthDate "2023-05-26Z"^^xsd:date ;
ex:hasBiologicalParents ex:23456 ;
ex:hasBiologicalParents ex:34567 ;
.
ex:23456 a ex:Person ;
ex:name "Susan" ;
ex:birthDate "1993-05-26Z"^^xsd:date ;
ex:hasBiologicalChildren ex:12345 ;
.
ex:34567 a ex:Person ;
ex:name "Alex" ;
ex:birthDate "1994-03-26Z"^^xsd:date ;
# ex:hasBiologicalChildren ex:12345 ;
.
so far, I have the following validation shape:
ex:personshape a sh:Nodeshape ;
sh:targetClass ex:Person ;
sh:property [
sh:path ex:hasBiologicalParents ;
sh:sparql ex:DoesparentNameChild ;
]
.
ex:DoesparentNameChild a sh:SPARQLConstraint ;
sh:message "The parent of this person does not have this person listed as their child" ;
sh:prefixes ex: ;
sh:select """
SELECT $this WHERE {
$this $PATH ?parent .
$this ^ex:hasBiologicalChilren ?parent .
}
"""
.
In the data graph I commented out the triple that says Alex has Harry as a child. So my expectation/desired outcome is that Harry gives a violation and that Susan and Alex pass.
pySHACL says that the graph validates, but I cant understand why. This might have something to do with me not understanding how the sparql part of the constraint passes its result to the shacl part and how it uses the query result to determine if it matches or not.
Any help would be much appreciated!