Plan, apply and roll back changes to a production ontology, with a blast radius report and a proof an auditor can re-check.
Rust ai-nativedescription-logicsformal-verificationinfrastructure-as-codeisabelle-languageknowledge-graphleanlean4mcpmcp-serverontologyowlowl2reasoningrustshaclsparqltheorem-proving
fix(load): all-or-nothing loads; feat(enforce): competing modelling pattern rule
FABIOTESS4d4280ecbaa6
diff --git a/src/enforce.rs b/src/enforce.rsindex 0f8c6511..e54c4c64 100644--- a/src/enforce.rs+++ b/src/enforce.rs@@ -106,6 +106,50 @@ impl Enforcer {self.check_missing_range(violations, total, passed);// Rule: missing labelself.check_missing_label(violations, total, passed);+ // Rule: competing modelling patterns (issue #94)+ self.check_competing_patterns(violations, total, passed);+ }++ /// A subclass partition and an attribute class for the same notion can+ /// coexist after a merge of independently authored vocabularies:+ /// `:AdherentX`/`:SuspensionX` under `:X` with disjointness, AND a+ /// competing `:XType`. Both parse and lint clean, but an extractor+ /// constrained to the merged vocabulary reliably picks the attribute+ /// class, the one form disjointness cannot reach, so contradiction+ /// detection is silently disabled. Status/State suffixes are exempt:+ /// a status is a property of a thing over time, not a kind of thing.+ fn check_competing_patterns(&self, violations: &mut Vec<serde_json::Value>, total: &mut u32, passed: &mut u32) {+ *total += 1;+ const KIND_SUFFIXES: [&str; 5] = ["Type", "Kind", "Category", "Mode", "Variant"];++ // Parents with two or more subclasses of which at least one pair is+ // declared disjoint: a real partition, not merely a hierarchy.+ let query = "SELECT DISTINCT ?parent WHERE { ?a <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?parent . ?b <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?parent . FILTER(?a != ?b) { ?a <http://www.w3.org/2002/07/owl#disjointWith> ?b } UNION { ?b <http://www.w3.org/2002/07/owl#disjointWith> ?a } }";+ let parents = self.query_iris(query, "parent");++ let class_query = "SELECT DISTINCT ?c WHERE { { ?c a <http://www.w3.org/2002/07/owl#Class> } UNION { ?c <http://www.w3.org/2000/01/rdf-schema#subClassOf> ?x } }";+ let classes: std::collections::HashSet<String> =+ self.query_iris(class_query, "c").into_iter().collect();++ let mut found = false;+ for parent in parents {+ for suffix in KIND_SUFFIXES {+ let candidate = format!("{parent}{suffix}");+ if classes.contains(&candidate) {+ found = true;+ violations.push(serde_json::json!({+ "rule": "competing_modelling_pattern",+ "severity": "warning",+ "entity": candidate,+ "message": format!(+ "Attribute class competes with the disjoint subclass partition under <{parent}>: extraction will use the attribute class, which disjointness cannot reach, silently disabling contradiction detection. Keep the partition; drop or merge the attribute class."),+ }));+ }+ }+ }+ if !found {+ *passed += 1;+ }}fn check_orphan_classes(&self, violations: &mut Vec<serde_json::Value>, total: &mut u32, passed: &mut u32) {diff --git a/src/graph.rs b/src/graph.rsindex 4c2c023f..3e055c71 100644--- a/src/graph.rs+++ b/src/graph.rs@@ -103,13 +103,17 @@ impl GraphStore {if let Some(base) = base_iri {parser = parser.with_base_iri(base)?;}- let quads_iter = parser.for_reader(reader);- let mut count = 0;- for quad in quads_iter {- store.insert(&quad?)?;- count += 1;+ // Parse the whole document BEFORE touching the store. Streaming+ // inserts left every quad before the first syntax error in place, so+ // a failed load produced a silently partial graph that looked exactly+ // like a small one (issue #93). All or nothing.+ let quads: Vec<_> = parser+ .for_reader(reader)+ .collect::<Result<_, _>>()?;+ for quad in &quads {+ store.insert(quad)?;}- Ok(count)+ Ok(quads.len())}/// Load RDF content in a specified format (Turtle, RDF/XML, etc.)@@ -125,13 +129,14 @@ impl GraphStore {if let Some(base) = base_iri {parser = parser.with_base_iri(base)?;}- let parser = parser.for_reader(reader);- let mut count = 0;- for quad in parser {- store.insert(&quad?)?;- count += 1;+ // All or nothing: see load_turtle (issue #93).+ let quads: Vec<_> = parser+ .for_reader(reader)+ .collect::<Result<_, _>>()?;+ for quad in &quads {+ store.insert(quad)?;}- Ok(count)+ Ok(quads.len())}pub fn load_file(&self, path: &str) -> anyhow::Result<usize> {@@ -139,13 +144,14 @@ impl GraphStore {let format = Self::detect_format_sniffed(path, &content);let store = self.store.lock().unwrap();let reader = Cursor::new(content.as_bytes());- let parser = RdfParser::from_format(format).for_reader(reader);- let mut count = 0;- for quad in parser {- store.insert(&quad?)?;- count += 1;+ // All or nothing: see load_turtle (issue #93).+ let quads: Vec<_> = RdfParser::from_format(format)+ .for_reader(reader)+ .collect::<Result<_, _>>()?;+ for quad in &quads {+ store.insert(quad)?;}- Ok(count)+ Ok(quads.len())}pub fn save_file(&self, path: &str, format: &str) -> anyhow::Result<()> {