From 49505f58bea89d52d373a70052b4f0e6b83cf6a7 Mon Sep 17 00:00:00 2001 From: Gabe Fierro Date: Mon, 4 Mar 2024 12:59:27 -0700 Subject: [PATCH] Add rule to deal with subproperties and equivalent properties (#624) * add subproperty and fix equivalent class rule * bump brickschema --- bricksrc/rules.ttl | 36 +++++++++++++++++++++++++++++++++ requirements.txt | 2 +- support/brickpatches.ttl | 8 ++++---- tests/test_entity_properties.py | 5 ++--- 4 files changed, 43 insertions(+), 8 deletions(-) diff --git a/bricksrc/rules.ttl b/bricksrc/rules.ttl index f7d4e8c2..9a140a2b 100644 --- a/bricksrc/rules.ttl +++ b/bricksrc/rules.ttl @@ -21,6 +21,42 @@ skos:narrower rdf:type rdf:Property ; owl:inverseOf skos:broader ; . +bsh:EquivalentPropertyRule + a sh:NodeShape ; + sh:rule [ + a sh:SPARQLRule ; + sh:construct """ +CONSTRUCT { + ?s ?t2 ?o . +} WHERE { + ?s $this ?o . + { $this owl:equivalentProperty ?t2 } + UNION + { ?t2 owl:equivalentProperty $this } +}""" ; + sh:prefixes ; + ] ; + sh:targetSubjectsOf owl:equivalentProperty ; +. + + +bsh:SubPropertyOfRule + a sh:NodeShape ; + sh:rule [ + a sh:SPARQLRule ; + sh:construct """ +CONSTRUCT { + ?s ?t2 ?o . +} WHERE { + ?s $this ?o . + { $this rdfs:subPropertyOf ?t2 } +}""" ; + sh:prefixes ; + ] ; + sh:targetSubjectsOf rdfs:subPropertyOf ; +. + + bsh:InferInverseProperties a sh:NodeShape ; sh:rule [ diff --git a/requirements.txt b/requirements.txt index 43a423fd..6e8db0f6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -4,7 +4,7 @@ pytest>=7.3 tqdm>=4.0 pyshacl>=0.25 docker>=6.0 -brickschema[all]>=0.7.4a9 +brickschema[all]>=0.7.5 black==23.3.0 pre-commit>=3.2 flake8>=6.0 diff --git a/support/brickpatches.ttl b/support/brickpatches.ttl index a77fd86b..263b416a 100644 --- a/support/brickpatches.ttl +++ b/support/brickpatches.ttl @@ -1131,8 +1131,8 @@ brick:hasLocation brick:isLocationOf owl:equivalentProperty rec:isLocationOf ; . -brick:hasPart - owl:equivalentProperty rec:hasPart ; +rec:hasPart + rdfs:subPropertyOf brick:hasPart ; . brick:hasPoint owl:equivalentProperty rec:hasPoint ; @@ -1140,8 +1140,8 @@ brick:hasPoint brick:isFedBy owl:equivalentProperty rec:isFedBy ; . -brick:isPartOf - owl:equivalentProperty rec:isPartOf ; +rec:isPartOf + rdfs:subPropertyOf brick:isPartOf ; . brick:isPointOf owl:equivalentProperty rec:isPointOf ; diff --git a/tests/test_entity_properties.py b/tests/test_entity_properties.py index 08e5b5c1..d87f0307 100644 --- a/tests/test_entity_properties.py +++ b/tests/test_entity_properties.py @@ -1,6 +1,5 @@ -from rdflib import Namespace, Literal -from brickschema.namespaces import BRICK, A, REF, XSD -import os +from rdflib import Namespace, Literal, XSD +from brickschema.namespaces import BRICK, A, REF EX = Namespace("urn:ex#")