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.

merge: the rule-language front ends alongside the first-order export

FABIOTESS06d80d5915c1
diff --cc CHANGELOG.md
index 5cfd0abb,28dd6db3..51af58b1
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@@ -5,97 -5,47 +5,138 @@@ All notable changes to Open Ontologies
## [Unreleased]
### Added
+- **The refutation checker has a producer.** `lean/OOCert/Refute.lean` has
+ checked refutations since it landed and nothing in `src/` could write one: a
+ checker with no producer, which is the same shape of defect as a gate that
+ cannot fail. `reason --certificate DIR` (and `onto_reason` with
+ `certificate_dir`) now looks for a contradiction in the closure the fixpoint
+ reached and writes `refutation.tsv` beside `asserted.tsv` and
+ `derivations.tsv`, in the `oo-refute/1` format, with the minimal derivation
+ prefix that reached the clash. `lake exe oo-refute check` accepts it and
+ `oo-refute guard` refuses the derivation certificate over the same graph,
+ which is what `OOCert.a_certificate_adds_nothing_when_the_graph_is_refuted`
+ says to do.
+- **Ten of the seventeen OWL 2 RL rules that conclude `false` are detected, and
+ exactly one is certifiable.** `cax-dw`, `cls-com`, `cls-nothing2`,
+ `cls-maxc1`, `eq-diff1`, `prp-irp`, `prp-asyp`, `prp-pdw`, `prp-npa1` and
+ `prp-npa2` are looked for after the fixpoint. Only `cax-dw` gets a refutation
+ file, because `OOCert.RefuteConditions` carries a semantic condition for that
+ rule alone and `oo-refute` refuses a refutation naming any other with exit 2.
+ The other nine report `clash_found_by_this_engine` and write nothing, and the
+ seven not looked for at all (`cax-adc`, `prp-adp`, `eq-diff2`, `eq-diff3`,
+ `cls-maxqc1`, `cls-maxqc2`, `dt-not-type`) are listed in the response with the
+ reason, so a clean run is never read as a consistency result.
+- **The two verdicts are kept apart by a test.** `clash_found_by_this_engine` is
+ the engine's word and `unsatisfiable_under_disjointness` is what `oo-refute`
+ prints for an ACCEPTED refutation.
+ `tests/lean_refutation_producer_test.rs::the_engine_never_states_the_checkers_verdict`
+ walks every string in the response and fails if the engine ever states the
+ checker's verdict or names its soundness theorem, on the pattern
+ `a_user_rule_never_earns_the_absolute_verdict` set for the Horn layer.
+ `a_consistent_ontology_is_not_refuted` is the test that matters most: no
+ refutation is produced for a consistent ontology and a hand-written one over
+ it is rejected.
+- **The limit is stated and computed, not papered over.** `cax-dw` needs an
+ INDIVIDUAL in two disjoint classes, so a TBox unsatisfiable with no individual
+ asserted is invisible to the rule-based route.
+ `the_tbox_only_case_is_invisible_here_and_the_tableau_sees_it` runs one
+ ontology through both paths: `owl-rl` finds nothing and `owl-dl` reports the
+ unsatisfiable class. No refutation is emitted from the tableau, and the
+ obstruction is written down: `oo-refute/1` can express one contradiction,
+ `cax-dw`, over triples the forward-chaining prefix can reach, and a clash
+ reached through `∃`/`∀` expansion or a cardinality bound has no form in it.
+ Widening that is a change to `lean/`.
+- **First-order export, over the translation a machine-checked adequacy theorem
+ is about.** `fol --out DIR --format tptp|clif` (also `onto_fol_export` and
+ batch `fol`) writes the loaded ontology as TPTP FOF or as ISO/IEC 24707
+ Common Logic, and with `--goals FILE` one problem per conjecture, so an
+ ontology can be handed to E, Vampire or any other first-order prover. The
+ translation in `src/tptp.rs` transcribes `OwlLean/Translation.lean` from the
+ sibling `owl-lean` project, whose `OwlLean.adequacy` is machine-checked with
+ no `sorry`, no Mathlib and axioms `propext`, `Classical.choice`,
+ `Quot.sound`. Everyone else's OWL-to-FOL exporter is validated empirically
+ (FOWL, over 168 ChEBI modules) or proved on paper (Hets); LATIN's
+ `OWL2toFOL.elf` has its cardinality constructors and `objectPropertyChain`
+ commented out, and those are used by 37.2% and 45.9% of constrained real
+ ontologies. The background axioms and the individual typing axioms the
+ theorem requires are emitted, the freshness side condition is enforced at
+ every call site rather than assumed, and both have machine-checked
+ countermodels in `OwlLean/Refutations.lean` showing what goes wrong without
+ them. **The correspondence between the Rust and the Lean is pinned by
+ `tests/fol_translation_correspondence_test.rs` and is NOT itself proved**,
+ which is stated in the module docs, in the JSON report and in the header of
+ every emitted file. Constructs outside the fragment are named in the output
+ with counts and reasons through `exports_a_weaker_axiom_set` and
+ `constructs_not_exported`, the shape the description-logic layer already uses
+ for `certifies_a_weaker_axiom_set`. CLIF is a second serialiser over the one
+ translation, never a second translation, and is restricted to the
+ first-order-equivalent fragment of Common Logic: no sequence markers, fixed
+ arity, no quantification into a predicate position. See
+ docs/first-order-export.md and decision 0005.
+- **The CLIF export is gated against leaving the exactly semantically
+ conformant subdialect.** ISO/IEC 24707 first edition A.4.2 says the
+ subdialect using neither numerals nor quoted strings is exactly semantically
+ conformant, so staying inside it makes CLIF entailment and Common Logic
+ entailment coincide and the adequacy theorem needs no qualification at the
+ CLIF end. `clif_stays_in_the_exactly_conformant_subdialect` walks every
+ emitted sentence and fails on a bare decimal or a single-quoted string. The
+ scope is stated exactly: no numerals and no quoted strings IN SENTENCE
+ POSITIONS, with comment annotations the named exception.
+- **`tools/fol_differential.py`, an ATP as a differential oracle and never as
+ an authority.** It reasons with a certificate, exports one problem per
+ claimed entailment from a separate unreasoned store, and asks E or Vampire.
+ A conclusion the engine derives and the prover refutes is
+ `CLAIMED_NOT_ENTAILED` and exits 1; a prover that gives up is
+ `UNDETERMINED` and is never read as agreement. **An ATP verdict is an oracle
+ opinion, exactly like pyshacl's in `tools/shacl_differential.py`**: a
+ superposition refutation cannot be checked without a verified first-order
+ calculus with unification, which does not exist in core Lean, so a
+ disagreement is a bug in one of the two and the tool says so rather than
+ adjudicating. With no prover installed it skips loudly with the install line,
+ and `FOL_DIFF_REQUIRE_ATP=1` turns that skip into a failure. Run against E
+ 3.2.5 over FOAF it reported 58 disagreements on first use, all of them
+ defects in the new export layer, listed under Fixed below.
+ - **SWRL and RIF Core front ends, so the logic-programming family is covered in
+ fact and not only in architecture.** `lean/OOCert/Horn.lean` proves one
+ soundness theorem good for every rule table at once and decision 0003 names
+ RIF Core, Datalog and SWRL as the reason, but nothing in the repository could
+ produce a rule table from a standard rule syntax: the only format anything
+ read was `rules.tsv`, an internal encoding, and grep found no mention of SWRL
+ or RIF outside that decision record. `rules-import --from swrl|rif`
+ (`onto_rules_import` over MCP, `rules-import` in batch) closes that. SWRL is
+ read out of a loaded RDF graph through the `swrl:Imp` encoding, reusing the
+ one `rdf:first`/`rdf:rest` reader `src/tableaux.rs` already had for
+ `owl:intersectionOf`; RIF Core is read out of its normative XML syntax.
+ Datalog is deliberately not offered as a front end, because it has no single
+ standard concrete syntax and a Datalog program over triples IS a `rules.tsv`
+ table.
+
+ **Only a fragment of each language is a Horn table over triple patterns, and
+ the exact fragment is in docs/rule-syntax-front-ends.md and in every
+ response.** SWRL built-in atoms, `swrl:SameIndividualAtom`,
+ `swrl:DifferentIndividualsAtom`, `swrl:DataRangeAtom`, anonymous class
+ expressions and an empty head are refused; RIF `Equal`, `External`, `Expr`,
+ `rif:local` constants, `List` terms, `Or`/`Neg`/`Naf`, an existential
+ conclusion, an `Atom` of arity 0 or 3+, `rif:Import` and the presentation
+ syntax are refused. Every refusal is NAMED AND COUNTED, and by default one
+ refusal fails the whole import with no table written: a rule set that quietly
+ lost half its rules still reaches a fixpoint and its certificate still checks
+ green, which is a sound proof about a rule set nobody wrote.
+ `--allow-partial` imports the rest and flags the result
+ `certifies_a_weaker_rule_set`, the name the DL model-certificate block
+ already uses for the same idea.
+
+ Every rule a front end emits is named `swrl/…` or `rif/…` and no built-in
+ rule is, so an imported table can never render identically to the built-in
+ one and can never earn the absolute verdict. It always lands on
+ `entailed_under_supplied_rules` under `OOCert.horn_certificate_sound`.
+ `tests/rule_syntax_frontend_test.rs` runs a real rules file in each syntax
+ through the engine into `lake exe oo-horn check` and asserts the verdict it
+ gets back; `no_front_end_can_name_a_rule_the_way_a_built_in_is_named` pins
+ the naming with no Lean present, and `a_partial_import_can_never_be_silent`
+ pins that no combination of arguments writes a table with a refusal recorded
+ and the weaker-rule-set flag false.
+
- **Derivation certificates, checked by a proved-sound Lean checker.**
`reason --certificate DIR` (also `onto_reason`'s `certificate_dir` and batch
`reason --certificate`) writes `asserted.tsv` and `derivations.tsv`: every
diff --cc CLAUDE.md
index e9a2f262,308de597..ff5865ea
--- a/CLAUDE.md
+++ b/CLAUDE.md
@@@ -75,8 -75,9 +75,9 @@@ Claude dynamically decides the next too
| `onto_shacl` | To validate loaded data against SHACL shapes (cardinality, datatypes, classes) |
| `onto_vocab_check` | To closed-world-check generated DATA: flags any predicate/class used that is not declared in the loaded ontology (hallucinated terms). Catches what open-world SHACL silently passes. Run on LLM-generated Turtle before `onto_load` |
| `onto_defects` | BEFORE trusting any fact-level result, and on every marketplace pack before adopting it. Checks the ONTOLOGY against itself with no data present: `transitive_and_functional`, `symmetric_and_asymmetric`, `subclass_cycle`, `sub_property_cycle`, `disjoint_with_ancestor`, `inherited_disjoint`, `self_inverse`, `inverse_not_mutual`. A different question from `onto_dl_check`: a transitive functional property is satisfiable and is still a trap, because the pair manufactures contradictions the moment instances arrive. Each kind is listed at most 50 times, with the full total under `truncated` |
-| `onto_reason` | To run RDFS or OWL-RL inference, materializing inferred triples. Pass `inference_graph: true` to keep them in `https://open-ontologies.org/graph/inferred` instead of the default graph, so nothing downstream can read an inference as an assertion and `onto_save` to Turtle/RDF-XML cannot publish one. Default false (unchanged behaviour); not available for `owl-dl`. Pass `certificate_dir` to also write a derivation certificate (`asserted.tsv` + `derivations.tsv`) that the proved-sound Lean checker in `lean/` verifies; see docs/lean-certificates.md |
+| `onto_reason` | To run RDFS or OWL-RL inference, materializing inferred triples. Pass `inference_graph: true` to keep them in `https://open-ontologies.org/graph/inferred` instead of the default graph, so nothing downstream can read an inference as an assertion and `onto_save` to Turtle/RDF-XML cannot publish one. Default false (unchanged behaviour); not available for `owl-dl`. Pass `certificate_dir` to also write a derivation certificate (`asserted.tsv` + `derivations.tsv`) that the proved-sound Lean checker in `lean/` verifies, plus `refutation.tsv` when the run finds a contradiction `oo-refute` can judge. Ten of the seventeen OWL 2 RL rules that conclude `false` are detected and only `cax-dw` is certifiable, so `inconsistency.verdict` is `clash_found_by_this_engine` and NEVER the checker's `unsatisfiable_under_disjointness`; no clash found is not consistency; see docs/lean-certificates.md |
| `onto_reason_incremental` | After adding facts to an already-materialised graph. Derives the consequences of the ADDED triples only (semi-naive evaluation, joining the delta against the closure), so the cost tracks what changed rather than the size of the store: effectively instant against a 1.9M-triple store where full re-materialisation takes seconds. Refuses schema axioms (subClassOf, domain, range, inverseOf, equivalentClass) with an explanation, because those change what the whole store entails: run `onto_reason` for them |
+ | `onto_rules_import` | To read rules you wrote in a STANDARD rule syntax into the Horn rule table `onto_reason` evaluates with `rules_file`. `from: "swrl"` reads SWRL rules encoded in RDF (`swrl:Imp` with `swrl:body`/`swrl:head` as `rdf:List` atom lists) out of the loaded graph or out of `file`; `from: "rif"` reads RIF Core in its XML syntax (the presentation syntax is refused, not half-read). Only a FRAGMENT of each language is a Horn table over triple patterns: SWRL built-in atoms, same-individual and different-individual atoms, data ranges and anonymous class expressions are refused, as are RIF equality, External, Expr, `rif:local` constants, list terms, Or/Neg/Naf, an existential conclusion and an Atom of arity 0 or 3+. Every refusal is NAMED AND COUNTED and by default fails the whole import with no table written, because a rule set that quietly lost half its rules still reaches a fixpoint and still produces a certificate that checks green. `allow_partial: true` imports the rest and flags `certifies_a_weaker_rule_set`. A table from this tool can only ever earn `entailed_under_supplied_rules` |
| `onto_extend` | To run the full pipeline: ingest → SHACL validate → reason in one call |
| `onto_import_schema` | To import a PostgreSQL or DuckDB database schema as an OWL ontology (requires `postgres` and/or `duckdb` features). Auto-dispatches on connection-string scheme. |
| `onto_plan` | Before applying changes — shows added/removed classes, blast radius, risk score |
diff --cc README.md
index 85b10e71,f27c86f4..251994ca
--- a/README.md
+++ b/README.md
@@@ -1009,15 -1009,29 +1009,38 @@@ was in the engine: `cls-svf1` derived t
in [docs/lean-certificates.md](docs/lean-certificates.md) and
[decision 0002](docs/decisions/0002-an-inference-carries-a-certificate.md).
+The same run also looks for a contradiction, and writes `refutation.tsv` when it
+finds one `oo-refute` can judge. Ten of the seventeen OWL 2 RL rules that
+conclude `false` are detected; one of them, `cax-dw`, has a semantic condition
+in `lean/` and is the only one a refutation is written for. The other nine are
+reported as found by this engine and nothing more, because a file naming a rule
+the checker cannot judge would be a certificate-shaped object that certifies
+nothing. `cax-dw` needs an individual in two disjoint classes, so a TBox that is
+unsatisfiable with no individual asserted is invisible to the rule-based route:
+the `owl-dl` tableau sees that case and its answer carries no certificate.
+ ### Rules you wrote
+
+ `reason --rules TABLE --certificate DIR` evaluates a rule table you supply and
+ writes a certificate `lake exe oo-horn check` verifies against
+ `OOCert.horn_certificate_sound`, one theorem proved for every rule table at
+ once. `rules-import --from swrl` reads SWRL rules out of a loaded ontology and
+ `--from rif` reads RIF Core out of its XML syntax, so the table need not be
+ hand-written.
+
+ Only a FRAGMENT of each language is a Horn table over triple patterns. SWRL
+ built-in atoms, same-individual and different-individual atoms and data ranges
+ are refused; RIF equality, `External`, `Expr`, `rif:local` constants, list terms
+ and the presentation syntax are refused. Each refusal is named and counted, and
+ by default one refusal fails the whole import: a rule set that quietly lost half
+ its rules still reaches a fixpoint and its certificate still checks green, which
+ is a sound proof about a rule set nobody wrote.
+
+ A rule you supply is an assumption nobody checked, so a certificate over it
+ earns `entailed_under_supplied_rules` — true in every model of the asserted
+ graph **that also satisfies your rules** — and never the `entailed` that only
+ the built-in table earns. Details in
+ [docs/rule-syntax-front-ends.md](docs/rule-syntax-front-ends.md) and
+ [decision 0003](docs/decisions/0003-a-rule-is-data-and-an-assumption-is-not-a-fact.md).
### Studio
diff --cc docs/decisions/0003-a-rule-is-data-and-an-assumption-is-not-a-fact.md
index 77dcd79d,6e9c76d8..ba967701
--- a/docs/decisions/0003-a-rule-is-data-and-an-assumption-is-not-a-fact.md
+++ b/docs/decisions/0003-a-rule-is-data-and-an-assumption-is-not-a-fact.md
@@@ -60,17 -60,42 +60,52 @@@ cases. The engine's rule count has sinc
rules, 30 counting `cax-dw` in the refutation layer, and four of them stay as hand-written arms
because their premise count is the length of an RDF list.
+ ## The family is now covered in fact and not only in architecture
+
+ This decision said the logic-programming family — RIF Core, Datalog, SWRL — was the reason to make
+ rules data. For a while that was true of the checker and false of the product: the only rule syntax
+ anything here could read was `rules.tsv`, which is an internal encoding and not a language anybody
+ writes in, and grep found no mention of SWRL or RIF outside this file. A user holding a rules file
+ in a standard syntax could use none of it.
+
+ `src/rulesyntax.rs` and `rules-import` / `onto_rules_import` close that. SWRL is read out of a
+ loaded RDF graph through the `swrl:Imp` encoding, reusing the one `rdf:first`/`rdf:rest` reader the
+ DL parser already had; RIF Core is read out of its normative XML syntax. Datalog is deliberately NOT
+ offered as a front end, because it has no single standard concrete syntax and a Datalog program over
+ triples IS a `rules.tsv` table.
+
+ Three things follow from decision 4 and are not negotiable in that code:
+
+ 1. **Both front ends produce USER tables.** Every rule is named `swrl/…` or `rif/…`, no built-in
+ rule is, and `oo-horn` awards `entailed` only to a table that renders identically to the
+ built-in one. So an imported table structurally cannot earn the absolute verdict.
+ `a_swrl_rule_never_earns_the_absolute_verdict` and its RIF twin are the front ends' copies of
+ `a_user_rule_never_earns_the_absolute_verdict`, and they run the whole pipeline into `oo-horn`.
+ 2. **A rule that cannot be represented is refused by name and counted.** Both languages exceed a
+ Horn table: SWRL has built-in atoms, same- and different-individual atoms and data ranges; RIF
+ Core has equality, External, `Expr`, `rif:local` and list terms. By default ONE refusal fails the
+ whole import and no table is written, because a rule set that quietly lost half its rules still
+ reaches a fixpoint and its certificate still checks green — a sound proof about a rule set nobody
+ wrote, which is the laundering failure in its purest form. `allow_partial` is the opt-in and sets
+ `certifies_a_weaker_rule_set`, the name the DL model-certificate block already uses for the same
+ idea.
+ 3. **The supported fragment is stated, never implied.** `docs/rule-syntax-front-ends.md` and every
+ response carry it. "SWRL is supported" would be the false claim this decision exists to prevent
+ one level up.
+
## Still not done
-- Nothing in `src/` writes the refutation format, so inconsistency can be checked and not yet
- produced by this engine.
+- ~~Nothing in `src/` writes the refutation format, so inconsistency can be checked and not yet
+ produced by this engine.~~ Landed. `reason --certificate DIR` now looks for a contradiction in the
+ closure it reached and writes `refutation.tsv` for the one clash rule the checker has a semantic
+ condition for, `cax-dw`. Nine further clash rules are detected and deliberately NOT written,
+ because a file naming a rule `OOCert.RefuteConditions` has no field for is refused with exit 2 and
+ would be a certificate-shaped object that certifies nothing. See
+ [lean-certificates.md](../lean-certificates.md#refutations-certifying-that-a-graph-has-no-model).
+- The tableau's unsatisfiability findings still carry no refutation. `oo-refute/1` can express one
+ contradiction, `cax-dw`, over triples the forward-chaining prefix can reach; a clash the tableau
+ reaches through `∃`/`∀` expansion or a cardinality bound is not expressible in it, and giving it a
+ form would be a change to `lean/`. The precise obstruction is written down rather than left as
+ "future work".
+ - The RIF presentation syntax is not parsed. It is refused by name; a half-written parser for it
+ would mis-read rules rather than refuse them.
diff --cc src/batch.rs
index afee4117,a97a9bca..9493bad3
--- a/src/batch.rs
+++ b/src/batch.rs
@@@ -98,7 -98,7 +98,8 @@@ impl BatchRunner
"validate" => self.exec_validate(&cmd.args),
"lint" => self.exec_lint(&cmd.args),
"reason" => self.exec_reason(&cmd.args),
+ "fol" => self.exec_fol(&cmd.args),
+ "rules-import" | "rules_import" => self.exec_rules_import(&cmd.args),
"shacl" => self.exec_shacl(&cmd.args),
// The CLI subcommand is spelled with a hyphen and this arm accepted
// only the underscore, so every documented invocation was rejected
@@@ -275,36 -275,29 +276,59 @@@
serde_json::from_str(&result).unwrap_or(json!({"raw": result}))
}
+ /// First-order export. The store is in-memory per process, so this is the
+ /// only way to load and export in one run, exactly as for `reason
+ /// --certificate`.
+ fn exec_fol(&self, args: &[String]) -> Value {
+ let Some(out) = Self::flag_value(args, "--out") else {
+ return json!({"error": "fol requires --out DIR"});
+ };
+ let format = Self::flag_value(args, "--format").unwrap_or("tptp".to_string());
+ let dialect = Self::flag_value(args, "--clif-dialect");
+ let comments = Self::flag_value(args, "--clif-comments");
+ let syntax =
+ match crate::tptp::Syntax::parse(&format, dialect.as_deref(), comments.as_deref()) {
+ Ok(s) => s,
+ Err(e) => return json!({"error": e.to_string()}),
+ };
+ let goals = Self::flag_value(args, "--goals");
+ let skip: usize = Self::flag_value(args, "--goals-skip-columns")
+ .and_then(|v| v.parse().ok())
+ .unwrap_or(0);
+ let result = crate::tptp::export(
+ &self.graph,
+ std::path::Path::new(&out),
+ syntax,
+ goals.as_deref().map(std::path::Path::new),
+ skip,
+ )
+ .unwrap_or_else(|e| json!({"error": e.to_string()}).to_string());
+ serde_json::from_str(&result).unwrap_or(json!({"raw": result}))
+ }
+
+ /// `--from swrl` with no `--file` reads the loaded graph, which is why
+ /// this command is proxied to the daemon rather than run locally.
+ fn exec_rules_import(&self, args: &[String]) -> Value {
+ let Some(from) = Self::flag_value(args, "--from") else {
+ return json!({
+ "error": "rules-import needs --from: 'swrl' (SWRL rules encoded in RDF) or 'rif' \
+ (RIF Core, XML syntax)"
+ });
+ };
+ let file = Self::flag_value(args, "--file");
+ let out = Self::flag_value(args, "--out");
+ let allow_partial = args.iter().any(|a| a == "--allow-partial");
+ let result = crate::rulesyntax::run_import(
+ &self.graph,
+ &from,
+ file.as_deref().map(std::path::Path::new),
+ out.as_deref().map(std::path::Path::new),
+ allow_partial,
+ )
+ .unwrap_or_else(|e| json!({"error": e.to_string()}).to_string());
+ serde_json::from_str(&result).unwrap_or(json!({"raw": result}))
+ }
+
fn exec_shacl(&self, args: &[String]) -> Value {
use crate::shacl::ShaclValidator;
let shapes_path = match args.first() {
diff --cc src/main.rs
index 30e2e761,e0a9f84f..2fd097b6
--- a/src/main.rs
+++ b/src/main.rs
@@@ -448,41 -443,38 +448,74 @@@ enum Commands
#[arg(long)]
rules: Option<String>,
},
+ /// Export the loaded ontology as first-order logic, for an ATP
+ ///
+ /// The translation is the one owl-lean's machine-checked adequacy theorem
+ /// (`OwlLean.adequacy`) is about. The correspondence between this emitter
+ /// and that Lean is PINNED BY TESTS AND NOT ITSELF PROVED, and a prover's
+ /// verdict on the output is an oracle opinion, never a certificate.
+ Fol {
+ /// Output directory. `ontology.p` (or `.clif`) lands here, plus one
+ /// problem per goal under `goals/` when --goals is given.
+ #[arg(long)]
+ out: String,
+ /// `tptp` (FOF, what provers read) or `clif` (ISO/IEC 24707 Common
+ /// Logic, restricted to the first-order-equivalent fragment).
+ #[arg(long, default_value = "tptp")]
+ format: String,
+ /// With --format clif: `iso` (default, `cl:text`, what ISO/IEC 21838-2
+ /// publishes BFO in) or `colore` (`cl-text`, what COLORE and the
+ /// Macleod toolchain read; Macleod cannot read the ISO spelling).
+ #[arg(long, default_value = "iso")]
+ clif_dialect: String,
+ /// With --format clif: `standalone` (default) puts each label in its
+ /// own `(cl:comment '...')` phrase and the sentence bare, or `wrapped`
+ /// for `(cl:comment '...' SENTENCE)`, the shape BFO uses. Wrapped is
+ /// correct CLIF that both existing CLIF parsers read as EMPTY.
+ #[arg(long, default_value = "standalone")]
+ clif_comments: String,
+ /// A TSV of triples to ask as conjectures, one problem per line.
+ /// `derivations.tsv` from `reason --certificate` is the intended
+ /// input; pass --goals-skip-columns 1 for it, because its first
+ /// column is the rule name.
+ #[arg(long)]
+ goals: Option<String>,
+ #[arg(long, default_value_t = 0)]
+ goals_skip_columns: usize,
+ },
++
+ /// Read rules written in a STANDARD rule syntax into the `rules.tsv` table
+ /// `reason --rules` evaluates and `oo-horn check` verifies.
+ ///
+ /// Every rule imported is a rule you wrote, so a certificate over the table
+ /// this produces can only ever earn `entailed_under_supplied_rules`: true in
+ /// every model of the asserted graph THAT ALSO SATISFIES YOUR RULES. The
+ /// rules are assumed and never checked.
+ RulesImport {
+ /// `swrl` for SWRL rules encoded in RDF, `rif` for RIF Core in its XML
+ /// syntax. Only part of each language is representable as Horn rules
+ /// over triple patterns; the response states the exact fragment and
+ /// names every rule it refused.
+ #[arg(long)]
+ from: String,
+ /// The document to read. Required for `rif`. Optional for `swrl`:
+ /// without it the LOADED graph is read; with it the file is parsed into
+ /// a store of its own, so importing rules never changes what is loaded.
+ #[arg(long)]
+ file: Option<String>,
+ /// Where to write the table. Without it nothing is written and the
+ /// table comes back in the response under `rules_tsv`.
+ #[arg(long)]
+ out: Option<String>,
+ /// Import the rules that CAN be represented even though others cannot.
+ /// Off by default, and deliberately: a table that quietly lost a rule
+ /// still reaches a fixpoint and still produces a certificate that
+ /// checks green, which is a sound proof about a rule set nobody wrote.
+ /// With this flag the import succeeds, the result carries
+ /// `certifies_a_weaker_rule_set: true`, and every lost rule is named.
+ #[arg(long)]
+ allow_partial: bool,
+ },
/// Full pipeline: ingest → SHACL → reason
Extend {
data_path: String,
@@@ -685,25 -677,24 +718,44 @@@ impl Commands
}
cmd("reason", a)
}
+ Commands::Fol { out, format, clif_dialect, clif_comments, goals, goals_skip_columns } => {
+ let mut a = vec![
+ "--out".into(),
+ absolutize(out),
+ "--format".into(),
+ format.clone(),
+ "--clif-dialect".into(),
+ clif_dialect.clone(),
+ "--clif-comments".into(),
+ clif_comments.clone(),
+ ];
+ if let Some(g) = goals {
+ a.push("--goals".into());
+ a.push(absolutize(g));
+ a.push("--goals-skip-columns".into());
+ a.push(goals_skip_columns.to_string());
+ }
+ cmd("fol", a)
+ }
++
+ Commands::RulesImport { from, file, out, allow_partial } => {
+ // Proxied because `--from swrl` with no `--file` reads the
+ // LOADED graph, which lives in the daemon. Running it locally
+ // would read a different store and import a different rule set.
+ let mut a = vec!["--from".into(), from.clone()];
+ if let Some(f) = file {
+ a.push("--file".into());
+ a.push(absolutize(f));
+ }
+ if let Some(o) = out {
+ a.push("--out".into());
+ a.push(absolutize(o));
+ }
+ if *allow_partial {
+ a.push("--allow-partial".into());
+ }
+ cmd("rules-import", a)
+ }
Commands::Shacl { shapes } => cmd("shacl", vec![absolutize(shapes)]),
Commands::Status => cmd("status", vec![]),
Commands::Pull { url, sparql, query } => {
@@@ -2416,25 -2407,20 +2468,40 @@@ async fn async_main() -> anyhow::Result
};
output_result_checked(&result, cli.pretty);
}
+ Commands::Fol { out, format, clif_dialect, clif_comments, goals, goals_skip_columns } => {
+ let (_db, graph) = setup(&cli.data_dir)?;
+ let result = match open_ontologies::tptp::Syntax::parse(
+ &format,
+ Some(&clif_dialect),
+ Some(&clif_comments),
+ ) {
+ Ok(syntax) => open_ontologies::tptp::export(
+ &graph,
+ std::path::Path::new(&out),
+ syntax,
+ goals.as_deref().map(std::path::Path::new),
+ goals_skip_columns,
+ )
+ .unwrap_or_else(|e| serde_json::json!({"error": e.to_string()}).to_string()),
+ Err(e) => serde_json::json!({"error": e.to_string()}).to_string(),
+ };
+ output_result_checked(&result, cli.pretty);
+ }
++
+ Commands::RulesImport { from, file, out, allow_partial } => {
+ let (_db, graph) = setup(&cli.data_dir)?;
+ let result = open_ontologies::rulesyntax::run_import(
+ &graph,
+ &from,
+ file.as_deref().map(std::path::Path::new),
+ out.as_deref().map(std::path::Path::new),
+ allow_partial,
+ )
+ .unwrap_or_else(|e| serde_json::json!({"error": e.to_string()}).to_string());
+ // A refused rule puts `error` in the response, so an import that
+ // lost anything exits non-zero and a script cannot walk past it.
+ output_result_checked(&result, cli.pretty);
+ }
Commands::Extend {
data_path,
format: _format,
diff --cc src/server.rs
index a8884255,b5b80371..bcbcdd25
--- a/src/server.rs
+++ b/src/server.rs
@@@ -1922,26 -1922,18 +1922,38 @@@ impl OpenOntologiesServer
.unwrap_or_else(Self::err_json)
}
+ #[tool(name = "onto_fol_export", description = "Export the loaded ontology as first-order logic, so it can be handed to the automated-theorem-proving ecosystem. Two syntaxes over ONE translation: `tptp` (FOF, what E, Vampire and every other first-order prover read) and `clif` (ISO/IEC 24707 Common Logic Interchange Format, restricted to the first-order-equivalent fragment: no sequence markers, fixed arity, no quantification into a predicate position). The translation is the one a MACHINE-CHECKED ADEQUACY THEOREM is about: `OwlLean.adequacy` in the sibling owl-lean project, axioms propext + Classical.choice + Quot.sound, no sorry, no Mathlib. That theorem is why the emitted file means what it says. THE CORRESPONDENCE BETWEEN THIS EMITTER AND THAT LEAN IS PINNED BY TESTS AND IS NOT ITSELF PROVED. The output includes the background axioms (the two domains are disjoint, the object domain is non-empty) and the individual typing axioms `thing(a)`, whose ABSENCE REFUTES ADEQUACY OUTRIGHT (OwlLean.Refutations.adequacy_needs_ind_axioms). Constructs outside the fragment are NOT dropped silently: `exports_a_weaker_axiom_set` and `constructs_not_exported` name every one with its count and the reason, and `reduced_to_fragment` names every construct rewritten before translation. Pass `goals_file` (a TSV of triples, e.g. the `derivations.tsv` from onto_reason with certificate_dir, with goals_skip_columns=1) to also write one problem per conjecture. A PROVER'S VERDICT ON THESE FILES IS AN ORACLE OPINION AND NEVER A CERTIFICATE: checking a superposition refutation needs a verified first-order calculus with unification, which does not exist in core Lean. Use tools/fol_differential.py, which reports disagreement between this engine and an ATP and does not adjudicate it.")]
+ async fn onto_fol_export(&self, Parameters(input): Parameters<OntoFolExportInput>) -> String {
+ let syntax = match crate::tptp::Syntax::parse(
+ input.format.as_deref().unwrap_or("tptp"),
+ input.clif_dialect.as_deref(),
+ input.clif_comments.as_deref(),
+ ) {
+ Ok(s) => s,
+ Err(e) => return Self::err_json(e),
+ };
+ crate::tptp::export(
+ &self.graph,
+ std::path::Path::new(&input.out_dir),
+ syntax,
+ input.goals_file.as_deref().map(std::path::Path::new),
+ input.goals_skip_columns.unwrap_or(0),
+ )
+ .unwrap_or_else(Self::err_json)
+ }
+
+ #[tool(name = "onto_rules_import", description = "Read rules written in a STANDARD rule syntax into the Horn rule table `onto_reason` evaluates with `rules_file` and the proved-sound Lean checker verifies with `lake exe oo-horn check`. `from: \"swrl\"` reads SWRL rules encoded in RDF (swrl:Imp with swrl:body / swrl:head as rdf:List atom lists) out of the loaded graph, or out of `file` if one is given. `from: \"rif\"` reads RIF Core in its normative XML syntax from `file`; the presentation syntax is NOT parsed and is refused rather than half-read. ONLY PART OF EACH LANGUAGE IS A HORN TABLE OVER TRIPLE PATTERNS. SWRL built-in atoms (swrlb: arithmetic and string predicates), swrl:SameIndividualAtom, swrl:DifferentIndividualsAtom, swrl:DataRangeAtom and anonymous class expressions are refused; RIF equality, External functions and predicates, Expr terms, rif:local constants, List terms, Or/Neg/Naf, an existential conclusion and an Atom of arity 0 or 3+ are refused. A refused rule is NAMED AND COUNTED and by default fails the whole import with no table written, because a rule set that quietly lost half its rules still reaches a fixpoint and still produces a certificate that checks green, which is a sound proof about a rule set nobody wrote. `allow_partial: true` imports the rest anyway and flags the result `certifies_a_weaker_rule_set`. Every rule imported is a rule YOU wrote and nothing discharges it, so a certificate over the table can only ever earn `entailed_under_supplied_rules` under `OOCert.horn_certificate_sound`: true in every model of the asserted graph THAT ALSO SATISFIES YOUR RULES. This tool states no verdict; `oo-horn check` is what pronounces.")]
+ fn onto_rules_import(&self, Parameters(input): Parameters<OntoRulesImportInput>) -> String {
+ crate::rulesyntax::run_import(
+ &self.graph,
+ &input.from,
+ input.file.as_deref().map(std::path::Path::new),
+ input.out.as_deref().map(std::path::Path::new),
+ input.allow_partial.unwrap_or(false),
+ )
+ .unwrap_or_else(Self::err_json)
+ }
+
#[tool(name = "onto_dl_explain", description = "Explain why a class is unsatisfiable using DL tableaux reasoning. Returns an explanation trace showing the logical contradictions that make the class impossible to instantiate.")]
async fn onto_dl_explain(&self, Parameters(input): Parameters<OntoDlExplainInput>) -> String {
use crate::tableaux::DlReasoner;