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(tableaux): parse owl:qualifiedCardinality; stop counting undetermined as satisfiable
FABIOTESS8d4ddf286a8a
diff --git a/src/tableaux.rs b/src/tableaux.rsindex a72f07b1..b90f11f7 100644--- a/src/tableaux.rs+++ b/src/tableaux.rs@@ -70,6 +70,7 @@ const OWL_NAMED_INDIVIDUAL: &str = "<http://www.w3.org/2002/07/owl#NamedIndividuconst OWL_MIN_CARD: &str = "<http://www.w3.org/2002/07/owl#minCardinality>";const OWL_MAX_CARD: &str = "<http://www.w3.org/2002/07/owl#maxCardinality>";const OWL_EXACT_CARD: &str = "<http://www.w3.org/2002/07/owl#cardinality>";+const OWL_EXACT_QCARD: &str = "<http://www.w3.org/2002/07/owl#qualifiedCardinality>";const OWL_MIN_QCARD: &str = "<http://www.w3.org/2002/07/owl#minQualifiedCardinality>";const OWL_MAX_QCARD: &str = "<http://www.w3.org/2002/07/owl#maxQualifiedCardinality>";const OWL_ON_CLASS: &str = "<http://www.w3.org/2002/07/owl#onClass>";@@ -770,8 +771,18 @@ impl OwlParser {&& let Some(n) = parse_card_value(&val) {return RawConcept::MaxCard(prop, n, Box::new(filler));}- // exactCardinality → ≥n R.C ⊓ ≤n R.C- if let Some(val) = self.index.object(node, OWL_EXACT_CARD)+ // qualifiedCardinality / cardinality → ≥n R.C ⊓ ≤n R.C+ //+ // The qualified form was missing while min and max both had it, so an+ // `owl:qualifiedCardinality` restriction fell through to Top: no+ // successor was ever generated and nothing downstream of it could+ // clash. That is how hqdm.owl's `defined_relationship` reads as+ // satisfiable — its =1 member_of_kind successor, which rdfs:range and+ // owl:onClass place in two disjoint classes, was never created.+ if let Some(val) = self+ .index+ .object(node, OWL_EXACT_QCARD)+ .or_else(|| self.index.object(node, OWL_EXACT_CARD))&& let Some(n) = parse_card_value(&val) {return RawConcept::And(vec![RawConcept::MinCard(prop, n, Box::new(filler.clone())),@@ -1972,6 +1983,17 @@ impl DlReasoner {.filter(|(_, v)| !v.is_unsat()).map(|(c, _)| *c).collect();+ // Reported separately from `satisfiable`. That vector deliberately carries+ // the undetermined classes so they stay in the hierarchy for the+ // subsumption sweep, but counting them as "satisfiable_found" in the+ // output claims a proof that was never constructed. On a 234-class+ // ontology where every class is undetermined, the old field read+ // "satisfiable_found: 234", which is indistinguishable from a coherent+ // result.+ let proven_satisfiable = sat_results+ .iter()+ .filter(|(_, v)| matches!(v, Verdict::Satisfiable))+ .count();let unsatisfiable: Vec<u32> = sat_results.iter().filter(|(_, v)| v.is_unsat())@@ -2054,7 +2076,7 @@ impl DlReasoner {agents: AgentMetrics {satisfiability: AgentTaskMetrics {tasks: classes.len(),- results: satisfiable.len(),+ results: proven_satisfiable,time_ms: sat_time.as_millis() as u64,},subsumption: AgentTaskMetrics {@@ -2460,6 +2482,7 @@ impl DlReasoner {"satisfiability_agent": {"classes_checked": result.agents.satisfiability.tasks,"satisfiable_found": result.agents.satisfiability.results,+ "undetermined": result.undetermined.len(),"time_ms": result.agents.satisfiability.time_ms,},"subsumption_agent": {diff --git a/tests/tableaux_test.rs b/tests/tableaux_test.rsindex 80813d60..32cd3f89 100644--- a/tests/tableaux_test.rs+++ b/tests/tableaux_test.rs@@ -1147,3 +1147,61 @@ fn test_dl_cardinality_subsumption_no_false_positive() {);assert!(unsat.is_empty(), "must not fire on the reversed subsumption, got {unsat:?}");}++#[test]+fn test_dl_qualified_exact_cardinality_is_parsed() {+ // owl:qualifiedCardinality had no branch: min and max both fell back from+ // the qualified to the unqualified form, the exact case only ever checked+ // owl:cardinality. An =1 R.C restriction therefore parsed as Top, no+ // successor was generated, and nothing downstream could clash. This is the+ // shape of hqdm.owl's defined_relationship: its =1 member_of_kind successor+ // is placed in two disjoint classes, one by owl:onClass and one by+ // rdfs:range.+ let unsat = unsat_names(+ r#"+ @prefix owl: <http://www.w3.org/2002/07/owl#> .+ @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .+ @prefix xsd: <http://www.w3.org/2001/XMLSchema#> .+ @prefix ex: <http://example.org/> .+ ex:A a owl:Class ; rdfs:subClassOf+ [ a owl:Restriction ; owl:onProperty ex:p ;+ owl:qualifiedCardinality "1"^^xsd:nonNegativeInteger ; owl:onClass ex:C ] .+ ex:p a owl:ObjectProperty ; rdfs:range ex:K .+ ex:C rdfs:subClassOf ex:CR .+ ex:K rdfs:subClassOf ex:CC .+ ex:CC owl:disjointWith ex:CR .+ "#,+ );+ assert!(+ unsat.iter().any(|u| u.ends_with("/A>")),+ "owl:qualifiedCardinality must generate a successor, got {unsat:?}"+ );+}++#[test]+fn test_dl_satisfiable_count_is_proven_only() {+ // `satisfiable_found` must count PROVEN satisfiable classes. Undetermined+ // ones are carried in the internal satisfiable vector so they stay in the+ // hierarchy for the subsumption sweep, but reporting them as satisfiable+ // makes an incomplete run indistinguishable from a coherent one.+ let store = Arc::new(GraphStore::new());+ store+ .load_turtle(+ r#"+ @prefix owl: <http://www.w3.org/2002/07/owl#> .+ @prefix ex: <http://example.org/> .+ ex:A a owl:Class . ex:B a owl:Class .+ "#,+ None,+ )+ .unwrap();+ let result = Reasoner::run(&store, "owl-dl", false).unwrap();+ let p: serde_json::Value = serde_json::from_str(&result).unwrap();+ let agent = &p["agents"]["satisfiability_agent"];+ assert_eq!(p["complete"], true, "this tiny ontology must complete");+ assert_eq!(agent["undetermined"], 0);+ assert_eq!(+ agent["satisfiable_found"], agent["classes_checked"],+ "a complete run must prove every class satisfiable"+ );+}