Skip to content

Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.

Recognize explicit OWL properties in Python schema tools

Rudy Celekliaf1ce383535e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6646495d..748cafb0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -6,6 +6,8 @@ All notable changes to Open Ontologies are documented here.
### Fixed
+- Recognize explicitly declared OWL properties in Python statistics and structural lint, without counting property declarations as individuals.
+
- Keep the last active ontology intact when parsing a replacement source, cache, or refresh fails; publish successful replacements in one graph transaction.
- Bound wildcard repository filtering to pattern/filename pairs so repeated stars cannot stall `onto_repo_list`.
- Sanitize quotes and ASCII control bytes in mapped IRI components so valid structured data does not fail RDF ingestion.
diff --git a/python/src/open_ontologies_lite/engine.py b/python/src/open_ontologies_lite/engine.py
index 2711e08e..ddb4f283 100644
--- a/python/src/open_ontologies_lite/engine.py
+++ b/python/src/open_ontologies_lite/engine.py
@@ -36,6 +36,12 @@ _FORMATS = {
OWL_CLASS = "http://www.w3.org/2002/07/owl#Class"
RDFS_CLASS = "http://www.w3.org/2000/01/rdf-schema#Class"
RDF_PROPERTY = "http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"
+_PROPERTY_TYPES = (RDF_PROPERTY,) + tuple(
+ "http://www.w3.org/2002/07/owl#" + name
+ for name in ("ObjectProperty", "DatatypeProperty", "AnnotationProperty")
+)
+_PROPERTY_VALUES = " ".join(f"<{iri}>" for iri in _PROPERTY_TYPES)
+_SCHEMA_TYPES = (OWL_CLASS, RDFS_CLASS) + _PROPERTY_TYPES
def resolve_format(name: str) -> ox.RdfFormat:
@@ -112,11 +118,11 @@ class OntologyEngine:
f"VALUES ?t {{ <{OWL_CLASS}> <{RDFS_CLASS}> }} }}"
),
"properties": self._count(
- f"SELECT (COUNT(DISTINCT ?p) AS ?n) WHERE {{ ?p a <{RDF_PROPERTY}> }}"
+ f"SELECT (COUNT(DISTINCT ?p) AS ?n) WHERE {{ ?p a ?t VALUES ?t {{ {_PROPERTY_VALUES} }} }}"
),
"individuals": self._count(
"SELECT (COUNT(DISTINCT ?i) AS ?n) WHERE { ?i a ?t "
- f"FILTER(?t != <{OWL_CLASS}> && ?t != <{RDFS_CLASS}> && ?t != <{RDF_PROPERTY}>) }}"
+ "FILTER(?t NOT IN (" + ", ".join(f"<{iri}>" for iri in _SCHEMA_TYPES) + ")) }"
),
}
@@ -193,11 +199,11 @@ class OntologyEngine:
"FILTER NOT EXISTS {{ ?c <http://www.w3.org/2000/01/rdf-schema#label> ?l }} }"
)
missing_domain = self._terms(
- f"SELECT DISTINCT ?p WHERE {{ ?p a <{RDF_PROPERTY}> "
+ f"SELECT DISTINCT ?p WHERE {{ ?p a ?t VALUES ?t {{ {_PROPERTY_VALUES} }} "
"FILTER NOT EXISTS {{ ?p <http://www.w3.org/2000/01/rdf-schema#domain> ?d }} }"
)
missing_range = self._terms(
- f"SELECT DISTINCT ?p WHERE {{ ?p a <{RDF_PROPERTY}> "
+ f"SELECT DISTINCT ?p WHERE {{ ?p a ?t VALUES ?t {{ {_PROPERTY_VALUES} }} "
"FILTER NOT EXISTS {{ ?p <http://www.w3.org/2000/01/rdf-schema#range> ?r }} }"
)
issues = (
diff --git a/python/tests/test_owl_property_recognition.py b/python/tests/test_owl_property_recognition.py
new file mode 100644
index 00000000..cb973ed9
--- /dev/null
+++ b/python/tests/test_owl_property_recognition.py
@@ -0,0 +1,33 @@
+"""Explicit OWL properties participate in the lightweight schema tools."""
+import pytest
+from open_ontologies_lite import OntologyEngine
+
+PREFIX = "@prefix ex:<http://example.org/>. @prefix owl:<http://www.w3.org/2002/07/owl#>. @prefix rdf:<http://www.w3.org/1999/02/22-rdf-syntax-ns#>. @prefix rdfs:<http://www.w3.org/2000/01/rdf-schema#>. "
+
[email protected]("kind", ["owl:ObjectProperty", "owl:DatatypeProperty", "owl:AnnotationProperty", "rdf:Property"])
+def test_explicit_properties_are_schema_not_individuals(kind):
+ engine = OntologyEngine()
+ engine.load(PREFIX + f"ex:p a {kind}.")
+ assert engine.stats() == {"triples": 1, "classes": 0, "properties": 1, "individuals": 0}
+ assert {(i["rule"], i["term"]) for i in engine.lint()["issues"]} == {
+ ("missing-domain", "http://example.org/p"), ("missing-range", "http://example.org/p")}
+
[email protected]("kind", ["owl:ObjectProperty", "owl:DatatypeProperty", "owl:AnnotationProperty", "rdf:Property"])
+def test_complete_property_has_no_hygiene_issues(kind):
+ engine = OntologyEngine()
+ engine.load(PREFIX + f"ex:p a {kind}; rdfs:domain ex:C; rdfs:range ex:D.")
+ assert engine.stats()["properties"] == 1
+ assert engine.stats()["individuals"] == 0
+ assert engine.lint()["issues"] == []
+
+def test_multiple_property_declarations_are_counted_once():
+ engine = OntologyEngine()
+ engine.load(PREFIX + "ex:p a rdf:Property, owl:ObjectProperty. ex:c a owl:Class. ex:i a ex:c, owl:NamedIndividual.")
+ assert engine.stats() == {"triples": 5, "classes": 1, "properties": 1, "individuals": 1}
+ assert len(engine.lint()["issues"]) == 3
+
+def test_schema_punning_preserves_explicit_instance_type():
+ engine = OntologyEngine()
+ engine.load(PREFIX + "ex:p a owl:ObjectProperty, ex:CustomClass.")
+ assert engine.stats()["properties"] == 1
+ assert engine.stats()["individuals"] == 1