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.

feat(enforce): ies4 rule pack — 3 design-pattern checks (#24)

FABIOTESSce6ff6388c00
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ceb961f9..175b15c0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable changes to Open Ontologies are documented here.
## [Unreleased]
+### Added
+- **`ies4` enforce rule pack** (#24). New built-in design-pattern pack for the [Information Exchange Standard](https://informationexchangestandard.org/), the UK cross-sector ontology framework custodied by Department for Business and Trade since March 2025 (canonical repo `IES-Org/ont-ies`). Three rules beyond the existing `boro` pack: (1) `ies4_particular_class_overlap` (severity: error) — a class cannot subclass both `ies:Particular` and `ies:ClassOfEntity`, as that violates the type-vs-token distinction foundational to IES4's 4D mereology; (2) `ies4_state_without_subject` (severity: warning) — a class subclassing `ies:State` must declare `ies:isStateOf` via owl:Restriction or have at least one instance using it (the state pattern is meaningless without a bearer); (3) `ies4_event_without_participant` (severity: warning) — a class subclassing `ies:Event` must have a participant pattern via `ies:isParticipantIn` / `ies:involvesParticipant` / `ies:hasParticipant` (events without participants are incomplete 4D models). Invoke via `onto_enforce` MCP tool or `enforce` CLI with `rule_pack = "ies4"`. Academic grounding: FOUST 7 paper "Comparing IES and BORO" (CEUR Vol-4176, JOWO 2024). New `tests/enforce_ies4_test.rs` (5 tests covering each rule's positive and negative cases, plus the instance-level participation accept path).
+
### Fixed
- **`onto_drift` now canonicalises blank nodes via RDFC 1.0 instead of filtering them out.** Replaces the temporary `_:`-prefix filter shipped in PR #14 (Jason Smith / @rustforrecess, who originally diagnosed the bnode-instability bug and shipped the surgical fix that bought time for this proper successor). New method `GraphStore::canonicalize_blank_nodes()` uses W3C RDF Dataset Canonicalization 1.0 (SHA-256) — available built-in via Oxigraph 0.5.8 — to assign deterministic `_:c14n<n>` identifiers derived from the graph structure. `DriftDetector::detect()` canonicalises each snapshot before vocabulary extraction, so reparses of the same ontology produce identical canonical bnode IDs (the reparse-stability property PR #14 achieved by exclusion), but anonymous restriction classes / quoted axioms now PARTICIPATE in the diff with stable IDs rather than being dropped. Caveat: canonical IDs are a function of the whole graph, so a quad change can shift many bnode IDs — for typical edits the existing rename-pairing logic in `detect()` re-matches shifted bnodes via the 4-signal ensemble (label / domain-range / hierarchy / individuals), so the net result is more informative than PR #14's filter. `tests/drift_blank_node_test.rs` updated to assert the new canonical-stability contract; new test `canonical_bnode_ids_are_stable_across_independent_reparses` exercises the contract directly on two restriction shapes.
diff --git a/src/enforce.rs b/src/enforce.rs
index 1a16491d..0f8c6511 100644
--- a/src/enforce.rs
+++ b/src/enforce.rs
@@ -13,8 +13,9 @@ impl Enforcer {
Self { db, graph }
}
- /// Run enforcement for a rule pack. Built-in packs: "generic", "boro", "value_partition".
- /// Custom rules stored in SQLite are also checked for the given pack name.
+ /// Run enforcement for a rule pack. Built-in packs: "generic", "boro", "value_partition",
+ /// "hierarchy", "ies4". Custom rules stored in SQLite are also checked for the given
+ /// pack name.
pub fn enforce(&self, rule_pack: &str) -> anyhow::Result<String> {
self.enforce_with_feedback(rule_pack, None)
}
@@ -30,6 +31,7 @@ impl Enforcer {
"boro" => self.run_boro_rules(&mut violations, &mut total_rules, &mut passed_rules),
"value_partition" => self.run_value_partition_rules(&mut violations, &mut total_rules, &mut passed_rules),
"hierarchy" => self.run_hierarchy_rules(&mut violations, &mut total_rules, &mut passed_rules),
+ "ies4" => self.run_ies4_rules(&mut violations, &mut total_rules, &mut passed_rules),
_ => {}
}
@@ -199,6 +201,115 @@ impl Enforcer {
}
}
+ /// IES4 design-pattern enforcement (Information Exchange Standard, the UK
+ /// cross-sector ontology framework custodied by DBT since March 2025;
+ /// canonical home `IES-Org/ont-ies`). Three rules that go beyond the
+ /// existing BORO pack:
+ ///
+ /// 1. **4D identity uniqueness** — a class cannot be both `ies:Particular`
+ /// and `ies:ClassOfEntity` (the type-vs-token distinction is
+ /// foundational to IES's 4D mereology).
+ /// 2. **State has subject** — a class subclassing `ies:State` should
+ /// declare or appear with `ies:isStateOf` linking it to an entity
+ /// (the state pattern is meaningless without its bearer).
+ /// 3. **Event has participant pattern** — a class subclassing `ies:Event`
+ /// should appear as range of some property implementing the
+ /// participant pattern (`ies:isParticipantIn`, `ies:involves`, etc.),
+ /// OR have at least one declared subclass-of-Event participant
+ /// (events without participants are incomplete IES4 model).
+ ///
+ /// Academic grounding: FOUST 7 paper "Comparing IES and BORO"
+ /// (CEUR Vol-4176, JOWO 2024). Closes #24.
+ fn run_ies4_rules(&self, violations: &mut Vec<serde_json::Value>, total: &mut u32, passed: &mut u32) {
+ const IES_NS: &str = "http://ies.data.gov.uk/ontology/ies4#";
+
+ // Rule 1: 4D identity uniqueness — class is BOTH Particular and ClassOfEntity.
+ *total += 1;
+ let q = format!(
+ "SELECT DISTINCT ?c WHERE {{ \
+ ?c <http://www.w3.org/2000/01/rdf-schema#subClassOf> <{ies}Particular> . \
+ ?c <http://www.w3.org/2000/01/rdf-schema#subClassOf> <{ies}ClassOfEntity> . \
+ }}",
+ ies = IES_NS
+ );
+ let overlap = self.query_iris(&q, "c");
+ if overlap.is_empty() {
+ *passed += 1;
+ } else {
+ for cls in overlap {
+ violations.push(serde_json::json!({
+ "rule": "ies4_particular_class_overlap",
+ "severity": "error",
+ "entity": cls,
+ "message": "IES4 4D principle violation: class is subclass of both ies:Particular and ies:ClassOfEntity (type-vs-token clash)",
+ }));
+ }
+ }
+
+ // Rule 2: State has subject — class subclasses ies:State but no
+ // ies:isStateOf usage anywhere targets it as state-side.
+ *total += 1;
+ let q = format!(
+ "SELECT DISTINCT ?state WHERE {{ \
+ ?state <http://www.w3.org/2000/01/rdf-schema#subClassOf> <{ies}State> . \
+ FILTER NOT EXISTS {{ \
+ {{ ?state <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?r . \
+ ?r <http://www.w3.org/2002/07/owl#onProperty> <{ies}isStateOf> . }} \
+ UNION \
+ {{ ?indiv a ?state . ?indiv <{ies}isStateOf> ?bearer . }} \
+ }} \
+ }}",
+ ies = IES_NS
+ );
+ let states = self.query_iris(&q, "state");
+ if states.is_empty() {
+ *passed += 1;
+ } else {
+ for s in states {
+ violations.push(serde_json::json!({
+ "rule": "ies4_state_without_subject",
+ "severity": "warning",
+ "entity": s,
+ "message": "IES4 State subclass has no ies:isStateOf restriction or instance-level usage — the state pattern requires a bearer (Entity it is a state of)",
+ }));
+ }
+ }
+
+ // Rule 3: Event has participant pattern — class subclasses ies:Event
+ // but no restriction or instance-level usage links a participant via
+ // ies:isParticipantIn / ies:involvesParticipant.
+ *total += 1;
+ let q = format!(
+ "SELECT DISTINCT ?ev WHERE {{ \
+ ?ev <http://www.w3.org/2000/01/rdf-schema#subClassOf> <{ies}Event> . \
+ FILTER NOT EXISTS {{ \
+ {{ ?ev <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?r . \
+ ?r <http://www.w3.org/2002/07/owl#onProperty> ?prop . \
+ FILTER(?prop IN (<{ies}isParticipantIn>, <{ies}involvesParticipant>, <{ies}hasParticipant>)) }} \
+ UNION \
+ {{ ?indiv a ?ev . \
+ {{ ?indiv <{ies}isParticipantIn> ?_ }} UNION \
+ {{ ?_ <{ies}involvesParticipant> ?indiv }} UNION \
+ {{ ?_ <{ies}hasParticipant> ?indiv }} }} \
+ }} \
+ }}",
+ ies = IES_NS
+ );
+ let events = self.query_iris(&q, "ev");
+ if events.is_empty() {
+ *passed += 1;
+ } else {
+ for e in events {
+ violations.push(serde_json::json!({
+ "rule": "ies4_event_without_participant",
+ "severity": "warning",
+ "entity": e,
+ "message": "IES4 Event subclass has no participant restriction or instance — events require participants to be meaningful in the 4D model",
+ }));
+ }
+ }
+ }
+
fn run_boro_rules(&self, violations: &mut Vec<serde_json::Value>, total: &mut u32, passed: &mut u32) {
// BORO rule: entities that subclass ies:Entity must have a corresponding State class
*total += 1;
diff --git a/tests/enforce_ies4_test.rs b/tests/enforce_ies4_test.rs
new file mode 100644
index 00000000..347d6de4
--- /dev/null
+++ b/tests/enforce_ies4_test.rs
@@ -0,0 +1,219 @@
+//! Integration tests for the IES4 enforce rule pack (#24).
+//!
+//! The pack adds three checks beyond the existing `boro` pack:
+//! 1. `ies4_particular_class_overlap` — class is subclass of both
+//! `ies:Particular` and `ies:ClassOfEntity` (type-vs-token clash).
+//! 2. `ies4_state_without_subject` — `ies:State` subclass has no
+//! `ies:isStateOf` restriction or instance-level usage.
+//! 3. `ies4_event_without_participant` — `ies:Event` subclass has no
+//! participant pattern.
+
+use open_ontologies::enforce::Enforcer;
+use open_ontologies::graph::GraphStore;
+use open_ontologies::state::StateDb;
+use std::sync::Arc;
+use tempfile::NamedTempFile;
+
+fn setup() -> (StateDb, Arc<GraphStore>) {
+ let tmp = NamedTempFile::new().unwrap();
+ let path = tmp.path().to_path_buf();
+ std::mem::forget(tmp);
+ let db = StateDb::open(&path).unwrap();
+ let graph = Arc::new(GraphStore::new());
+ (db, graph)
+}
+
+fn run_ies4(graph: Arc<GraphStore>) -> serde_json::Value {
+ let (db, _) = setup();
+ let enforcer = Enforcer::new(db, graph);
+ let result = enforcer.enforce("ies4").expect("enforce");
+ serde_json::from_str(&result).expect("json")
+}
+
+#[test]
+fn ies4_compliant_minimal_ontology_passes_all_rules() {
+ // An ontology that satisfies all three IES4 rules:
+ // - no Particular/ClassOfEntity overlap
+ // - PersonState has owl:Restriction onProperty ies:isStateOf
+ // - WorkEvent has owl:Restriction onProperty ies:isParticipantIn
+ let (_db, graph) = setup();
+ let ttl = r#"
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ @prefix ies: <http://ies.data.gov.uk/ontology/ies4#> .
+ @prefix ex: <http://example.org/> .
+
+ ies:Particular a owl:Class .
+ ies:ClassOfEntity a owl:Class .
+ ies:Entity a owl:Class .
+ ies:State a owl:Class .
+ ies:Event a owl:Class .
+ ies:isStateOf a owl:ObjectProperty .
+ ies:isParticipantIn a owl:ObjectProperty .
+
+ ex:Person a owl:Class ; rdfs:subClassOf ies:Particular .
+
+ ex:PersonState a owl:Class ;
+ rdfs:subClassOf ies:State ;
+ rdfs:subClassOf [ a owl:Restriction ;
+ owl:onProperty ies:isStateOf ;
+ owl:someValuesFrom ex:Person ] .
+
+ ex:WorkEvent a owl:Class ;
+ rdfs:subClassOf ies:Event ;
+ rdfs:subClassOf [ a owl:Restriction ;
+ owl:onProperty ies:isParticipantIn ;
+ owl:someValuesFrom ex:Person ] .
+ "#;
+ graph.load_turtle(ttl, None).expect("load");
+ let report = run_ies4(graph);
+ assert_eq!(report["total_rules"].as_u64().unwrap(), 3);
+ assert_eq!(report["passed_rules"].as_u64().unwrap(), 3);
+ assert!(
+ report["violations"].as_array().unwrap().is_empty(),
+ "compliant ontology should have zero violations; got: {}",
+ report["violations"]
+ );
+}
+
+#[test]
+fn ies4_flags_particular_class_overlap() {
+ let (_db, graph) = setup();
+ let ttl = r#"
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ @prefix ies: <http://ies.data.gov.uk/ontology/ies4#> .
+ @prefix ex: <http://example.org/> .
+
+ ies:Particular a owl:Class .
+ ies:ClassOfEntity a owl:Class .
+ ies:State a owl:Class .
+ ies:Event a owl:Class .
+
+ # Violation: class is subclass of both Particular and ClassOfEntity.
+ ex:ConfusedClass a owl:Class ;
+ rdfs:subClassOf ies:Particular ;
+ rdfs:subClassOf ies:ClassOfEntity .
+ "#;
+ graph.load_turtle(ttl, None).expect("load");
+ let report = run_ies4(graph);
+ let violations = report["violations"].as_array().unwrap();
+ assert!(
+ violations.iter().any(|v| {
+ v["rule"].as_str() == Some("ies4_particular_class_overlap")
+ && v["entity"].as_str().unwrap_or("").contains("ConfusedClass")
+ }),
+ "expected ies4_particular_class_overlap violation; got: {:?}",
+ violations
+ );
+ assert_eq!(
+ violations
+ .iter()
+ .find(|v| v["rule"] == "ies4_particular_class_overlap")
+ .map(|v| v["severity"].as_str().unwrap()),
+ Some("error"),
+ "particular/class overlap is a 4D principle violation — severity must be error"
+ );
+}
+
+#[test]
+fn ies4_flags_state_without_subject() {
+ let (_db, graph) = setup();
+ let ttl = r#"
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ @prefix ies: <http://ies.data.gov.uk/ontology/ies4#> .
+ @prefix ex: <http://example.org/> .
+
+ ies:State a owl:Class .
+ ies:Event a owl:Class .
+ ies:Particular a owl:Class .
+ ies:ClassOfEntity a owl:Class .
+
+ # Violation: State subclass with no ies:isStateOf restriction
+ # or instance-level usage.
+ ex:OrphanState a owl:Class ;
+ rdfs:subClassOf ies:State .
+ "#;
+ graph.load_turtle(ttl, None).expect("load");
+ let report = run_ies4(graph);
+ let violations = report["violations"].as_array().unwrap();
+ assert!(
+ violations.iter().any(|v| {
+ v["rule"].as_str() == Some("ies4_state_without_subject")
+ && v["entity"].as_str().unwrap_or("").contains("OrphanState")
+ }),
+ "expected ies4_state_without_subject violation; got: {:?}",
+ violations
+ );
+}
+
+#[test]
+fn ies4_flags_event_without_participant() {
+ let (_db, graph) = setup();
+ let ttl = r#"
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ @prefix ies: <http://ies.data.gov.uk/ontology/ies4#> .
+ @prefix ex: <http://example.org/> .
+
+ ies:Event a owl:Class .
+ ies:State a owl:Class .
+ ies:Particular a owl:Class .
+ ies:ClassOfEntity a owl:Class .
+
+ # Violation: Event subclass with no participant pattern.
+ ex:OrphanEvent a owl:Class ;
+ rdfs:subClassOf ies:Event .
+ "#;
+ graph.load_turtle(ttl, None).expect("load");
+ let report = run_ies4(graph);
+ let violations = report["violations"].as_array().unwrap();
+ assert!(
+ violations.iter().any(|v| {
+ v["rule"].as_str() == Some("ies4_event_without_participant")
+ && v["entity"].as_str().unwrap_or("").contains("OrphanEvent")
+ }),
+ "expected ies4_event_without_participant violation; got: {:?}",
+ violations
+ );
+}
+
+#[test]
+fn ies4_event_with_instance_level_participant_passes() {
+ // An Event subclass that has no restriction BUT has at least one instance
+ // participating via ies:isParticipantIn should pass — the rule accepts
+ // either restriction-level or instance-level evidence of participants.
+ let (_db, graph) = setup();
+ let ttl = r#"
+ @prefix owl: <http://www.w3.org/2002/07/owl#> .
+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
+ @prefix ies: <http://ies.data.gov.uk/ontology/ies4#> .
+ @prefix ex: <http://example.org/> .
+
+ ies:Event a owl:Class .
+ ies:State a owl:Class .
+ ies:Particular a owl:Class .
+ ies:ClassOfEntity a owl:Class .
+ ies:isParticipantIn a owl:ObjectProperty .
+
+ ex:Meeting a owl:Class ; rdfs:subClassOf ies:Event .
+
+ # Instance-level participation — should satisfy the rule.
+ ex:meeting42 a ex:Meeting ;
+ ies:isParticipantIn ex:alice .
+ "#;
+ graph.load_turtle(ttl, None).expect("load");
+ let report = run_ies4(graph);
+ let event_violations: Vec<_> = report["violations"]
+ .as_array()
+ .unwrap()
+ .iter()
+ .filter(|v| v["rule"] == "ies4_event_without_participant")
+ .collect();
+ assert!(
+ event_violations.is_empty(),
+ "Meeting has instance-level participation; should not be flagged. Got: {:?}",
+ event_violations
+ );
+}