diff --git a/whyis/namespace.py b/whyis/namespace.py index 38dda9dda..19f1f3f49 100644 --- a/whyis/namespace.py +++ b/whyis/namespace.py @@ -51,6 +51,7 @@ class NamespaceContainer(object): sdd = rdflib.Namespace("http://purl.org/twc/sdd/") csvw = rdflib.Namespace("http://www.w3.org/ns/csvw#") text = rdflib.Namespace("http://jena.apache.org/fulltext#") + sh = rdflib.Namespace("http://www.w3.org/ns/shacl#") @property def prefixes(self): diff --git a/whyis/templates/incoming_class.json b/whyis/templates/incoming_class.json index 229927077..7da7f6c0f 100644 --- a/whyis/templates/incoming_class.json +++ b/whyis/templates/incoming_class.json @@ -1,8 +1,23 @@ {{'''graph ?assertion { { + # Original class hierarchy relationships ?source rdfs:subClassOf|owl:equivalentClass ?target. ?source ?link_type ?target. } + UNION { + # SHACL property shapes: PropertyShape with sh:class/sh:node pointing to target + ?nodeshape sh:property ?source. + ?source sh:class|sh:node ?target. + ?source ?link_type ?target. + } + UNION { + # Classes used directly as NodeShapes with property shapes + ?source rdf:type sh:NodeShape. + ?source sh:property ?propshape. + ?propshape sh:class|sh:node ?target. + ?propshape ?link_type ?target. + bind(?source as ?source) + } } bind(1 as ?probability) bind(?assertion as ?link) diff --git a/whyis/templates/outgoing_class.json b/whyis/templates/outgoing_class.json index 9f5df2e70..cce8bab7d 100644 --- a/whyis/templates/outgoing_class.json +++ b/whyis/templates/outgoing_class.json @@ -1,8 +1,34 @@ {{'''graph ?assertion { { + # Original class hierarchy relationships ?source rdfs:subClassOf ?target. ?source ?link_type ?target. } + UNION { + # SHACL NodeShape: current class targets other classes + ?source sh:targetClass ?target. + ?source ?link_type ?target. + } + UNION { + # SHACL PropertyShape: current class has property shapes pointing to other classes + ?source sh:property ?propshape. + ?propshape sh:class|sh:node ?target. + ?propshape ?link_type ?target. + } + UNION { + # Current class used as NodeShape with property shapes pointing to other classes + ?source rdf:type sh:NodeShape. + ?source sh:property ?propshape. + ?propshape sh:class|sh:node ?target. + ?propshape ?link_type ?target. + } + UNION { + # Property shapes where current class is referenced via sh:class/sh:node + ?nodeshape sh:property ?propshape. + ?propshape sh:class|sh:node ?source. + ?nodeshape sh:targetClass ?target. + ?nodeshape ?link_type ?target. + } } bind(1 as ?probability) bind(?assertion as ?link)