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
feat(ingest): optional PROV-O provenance emission
FABIOTESSb34bb1220c51
diff --git a/src/inputs.rs b/src/inputs.rsindex 968d9818..9b81ffb7 100644--- a/src/inputs.rs+++ b/src/inputs.rs@@ -199,6 +199,11 @@ pub struct OntoIngestInput {pub inline_mapping: Option<bool>,/// Base IRI for generated instances (default: http://example.org/data/)pub base_iri: Option<String>,+ /// Emit PROV-O provenance: each generated subject gets+ /// prov:wasDerivedFrom the source file, with a prov:Entity for the file+ /// carrying its path and ingestion timestamp. Interoperates with+ /// platforms that expect PROV-O (Semantica, TrustGraph). Default false.+ pub provenance: Option<bool>,}#[derive(Deserialize, JsonSchema)]diff --git a/src/server.rs b/src/server.rsindex 5af16847..c6b91c53 100644--- a/src/server.rs+++ b/src/server.rs@@ -833,7 +833,42 @@ impl OpenOntologiesServer {};// Convert to N-Triples and load- let ntriples = mapping.rows_to_ntriples(&rows);+ let mut ntriples = mapping.rows_to_ntriples(&rows);++ // PROV-O: where did each of these subjects come from. Every fact+ // carrying its source is what makes a graph auditable later, and it+ // is the interop shape other platforms expect.+ let mut prov_triples = 0usize;+ if input.provenance.unwrap_or(false) {+ if !ntriples.is_empty() && !ntriples.ends_with('\n') {+ ntriples.push('\n');+ }+ const PROV_DERIVED: &str = "<http://www.w3.org/ns/prov#wasDerivedFrom>";+ let source_iri = format!("{}source/{}", base_iri,+ std::path::Path::new(&input.path)+ .file_name().and_then(|n| n.to_str()).unwrap_or("data")+ .replace(|c: char| !c.is_alphanumeric() && c != '.' && c != '-' && c != '_', "_"));+ let mut extra = String::new();+ extra.push_str(&format!(+ "<{source_iri}> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/ns/prov#Entity> .\n"));+ extra.push_str(&format!(+ "<{source_iri}> <http://www.w3.org/2000/01/rdf-schema#label> {} .\n",+ serde_json::to_string(&input.path).unwrap_or_else(|_| "\"source\"".into())));+ extra.push_str(&format!(+ "<{source_iri}> <http://www.w3.org/ns/prov#generatedAtTime> \"{}\"^^<http://www.w3.org/2001/XMLSchema#dateTime> .\n",+ chrono::Utc::now().to_rfc3339()));+ let mut seen = std::collections::HashSet::new();+ for line in ntriples.lines() {+ if let Some(subject) = line.split_whitespace().next() {+ if subject.starts_with('<') && seen.insert(subject.to_string()) {+ extra.push_str(&format!("{subject} {PROV_DERIVED} <{source_iri}> .\n"));+ }+ }+ }+ prov_triples = extra.lines().count();+ ntriples.push_str(&extra);+ }+match self.graph.load_ntriples(&ntriples) {Ok(count) => {serde_json::json!({@@ -841,6 +876,7 @@ impl OpenOntologiesServer {"triples_loaded": count,"rows_processed": rows.len(),"mapping_fields": mapping.mappings.len(),+ "provenance_triples": prov_triples,}).to_string()}Err(e) => format!(r#"{{"error":"Failed to load triples: {}"}}"#, e),