unicode-logic-kit 0.31.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- unicode_logic_kit/__init__.py +385 -0
- unicode_logic_kit/__main__.py +520 -0
- unicode_logic_kit/_deadline.py +219 -0
- unicode_logic_kit/ace/__init__.py +126 -0
- unicode_logic_kit/ace/_align.py +135 -0
- unicode_logic_kit/ace/chem_lexicon.py +128 -0
- unicode_logic_kit/ace/drs_reader.py +570 -0
- unicode_logic_kit/ace/mapping.py +666 -0
- unicode_logic_kit/ace/reverse_modal.py +138 -0
- unicode_logic_kit/ace/runner.py +551 -0
- unicode_logic_kit/ace/translate.py +452 -0
- unicode_logic_kit/ace/verbalize.py +1070 -0
- unicode_logic_kit/api.py +1284 -0
- unicode_logic_kit/atp/__init__.py +177 -0
- unicode_logic_kit/atp/_ascii_names.py +113 -0
- unicode_logic_kit/atp/_html.py +72 -0
- unicode_logic_kit/atp/_substructural_input.py +228 -0
- unicode_logic_kit/atp/_tff_problem.py +715 -0
- unicode_logic_kit/atp/_tptp_problem.py +1111 -0
- unicode_logic_kit/atp/_writer_support.py +289 -0
- unicode_logic_kit/atp/clingo_backend.py +1180 -0
- unicode_logic_kit/atp/cvc5_backend.py +1385 -0
- unicode_logic_kit/atp/eprover_backend.py +732 -0
- unicode_logic_kit/atp/finite_domain.py +1055 -0
- unicode_logic_kit/atp/fitch.py +1547 -0
- unicode_logic_kit/atp/fitch_search.py +551 -0
- unicode_logic_kit/atp/hets_backend.py +339 -0
- unicode_logic_kit/atp/hybrid_down.py +120 -0
- unicode_logic_kit/atp/incremental.py +250 -0
- unicode_logic_kit/atp/kripke_enum.py +741 -0
- unicode_logic_kit/atp/lambek.py +436 -0
- unicode_logic_kit/atp/leo3_backend.py +332 -0
- unicode_logic_kit/atp/linear.py +738 -0
- unicode_logic_kit/atp/lj.py +705 -0
- unicode_logic_kit/atp/logic_backends.py +566 -0
- unicode_logic_kit/atp/ltl_tableau.py +1084 -0
- unicode_logic_kit/atp/minizinc_backend.py +1402 -0
- unicode_logic_kit/atp/modal_tableau.py +1382 -0
- unicode_logic_kit/atp/nanocop_backend.py +410 -0
- unicode_logic_kit/atp/portfolio.py +489 -0
- unicode_logic_kit/atp/protocol.py +1803 -0
- unicode_logic_kit/atp/prover9_entailment.py +1153 -0
- unicode_logic_kit/atp/resolution.py +1376 -0
- unicode_logic_kit/atp/resolution_check.py +1114 -0
- unicode_logic_kit/atp/sequent.py +1050 -0
- unicode_logic_kit/atp/tableau.py +921 -0
- unicode_logic_kit/atp/tableau_check.py +543 -0
- unicode_logic_kit/atp/tptp_ncl.py +811 -0
- unicode_logic_kit/atp/tptp_tff.py +1546 -0
- unicode_logic_kit/atp/tstp.py +1333 -0
- unicode_logic_kit/atp/tstp_check.py +1096 -0
- unicode_logic_kit/atp/twee_backend.py +236 -0
- unicode_logic_kit/atp/twee_check.py +711 -0
- unicode_logic_kit/atp/twee_entailment.py +953 -0
- unicode_logic_kit/atp/vampire_entailment.py +540 -0
- unicode_logic_kit/atp/z3_arith.py +470 -0
- unicode_logic_kit/atp/z3_equivalence.py +36 -0
- unicode_logic_kit/atp/z3_fuzzy.py +362 -0
- unicode_logic_kit/atp/z3_input.py +500 -0
- unicode_logic_kit/atp/z3_models.py +208 -0
- unicode_logic_kit/chem/__init__.py +88 -0
- unicode_logic_kit/chem/_naming.py +284 -0
- unicode_logic_kit/chem/cache.py +185 -0
- unicode_logic_kit/chem/interop.py +244 -0
- unicode_logic_kit/chem/mol.py +525 -0
- unicode_logic_kit/chem/signature.py +112 -0
- unicode_logic_kit/comorphism.py +497 -0
- unicode_logic_kit/dl/__init__.py +384 -0
- unicode_logic_kit/dl/classification.py +227 -0
- unicode_logic_kit/dl/concepts.py +632 -0
- unicode_logic_kit/dl/datatypes.py +818 -0
- unicode_logic_kit/dl/owl_functional.py +2433 -0
- unicode_logic_kit/dl/owl_manchester.py +1637 -0
- unicode_logic_kit/dl/owl_reasoner.py +790 -0
- unicode_logic_kit/dl/parser.py +391 -0
- unicode_logic_kit/dl/tableau.py +4048 -0
- unicode_logic_kit/dl/translate.py +2704 -0
- unicode_logic_kit/drt/__init__.py +94 -0
- unicode_logic_kit/drt/export.py +179 -0
- unicode_logic_kit/drt/nodes.py +506 -0
- unicode_logic_kit/drt/parser.py +965 -0
- unicode_logic_kit/drt/resolve.py +195 -0
- unicode_logic_kit/drt/reverse.py +175 -0
- unicode_logic_kit/eval/__init__.py +106 -0
- unicode_logic_kit/eval/batch.py +382 -0
- unicode_logic_kit/eval/canonical.py +663 -0
- unicode_logic_kit/eval/chem_batch.py +606 -0
- unicode_logic_kit/eval/converses.py +200 -0
- unicode_logic_kit/eval/datasets/__init__.py +136 -0
- unicode_logic_kit/eval/datasets/_base.py +263 -0
- unicode_logic_kit/eval/datasets/_proofwriter_proof.py +422 -0
- unicode_logic_kit/eval/datasets/c3po.py +678 -0
- unicode_logic_kit/eval/datasets/folio.py +158 -0
- unicode_logic_kit/eval/datasets/fracas.py +418 -0
- unicode_logic_kit/eval/datasets/groves.py +191 -0
- unicode_logic_kit/eval/datasets/logicbench.py +467 -0
- unicode_logic_kit/eval/datasets/logicnli.py +303 -0
- unicode_logic_kit/eval/datasets/malls.py +133 -0
- unicode_logic_kit/eval/datasets/pfolio.py +594 -0
- unicode_logic_kit/eval/datasets/pmb.py +242 -0
- unicode_logic_kit/eval/datasets/prontoqa.py +611 -0
- unicode_logic_kit/eval/datasets/proofwriter.py +1431 -0
- unicode_logic_kit/eval/datasets/proverqa.py +674 -0
- unicode_logic_kit/eval/datasets/willow.py +478 -0
- unicode_logic_kit/eval/equivalence.py +466 -0
- unicode_logic_kit/eval/exercise_gen.py +533 -0
- unicode_logic_kit/eval/explain.py +791 -0
- unicode_logic_kit/eval/generality.py +750 -0
- unicode_logic_kit/eval/metric_hf.py +458 -0
- unicode_logic_kit/eval/predicate_match.py +343 -0
- unicode_logic_kit/eval/theory_check.py +1170 -0
- unicode_logic_kit/eval/validate.py +306 -0
- unicode_logic_kit/fol/__init__.py +177 -0
- unicode_logic_kit/fol/_atom_keys.py +510 -0
- unicode_logic_kit/fol/_fol_nodes.py +3586 -0
- unicode_logic_kit/fol/_free_parameters.py +105 -0
- unicode_logic_kit/fol/_ho_nodes.py +448 -0
- unicode_logic_kit/fol/_hybrid_nodes.py +308 -0
- unicode_logic_kit/fol/_identifiers.py +1091 -0
- unicode_logic_kit/fol/_lambek_nodes.py +112 -0
- unicode_logic_kit/fol/_linear_nodes.py +352 -0
- unicode_logic_kit/fol/_modal_nodes.py +1467 -0
- unicode_logic_kit/fol/_msfl_nodes.py +2196 -0
- unicode_logic_kit/fol/_numeral_symbols.py +231 -0
- unicode_logic_kit/fol/_so_nodes.py +200 -0
- unicode_logic_kit/fol/_symbol_names.py +81 -0
- unicode_logic_kit/fol/_team_nodes.py +181 -0
- unicode_logic_kit/fol/_tptp_symbols.py +551 -0
- unicode_logic_kit/fol/_truth_constants.py +117 -0
- unicode_logic_kit/fol/casl_export.py +1135 -0
- unicode_logic_kit/fol/casl_import.py +929 -0
- unicode_logic_kit/fol/derivation.py +367 -0
- unicode_logic_kit/fol/dialect_detect.py +70 -0
- unicode_logic_kit/fol/dialect_repair.py +537 -0
- unicode_logic_kit/fol/frames.py +637 -0
- unicode_logic_kit/fol/grammars/terminals.lark +31 -0
- unicode_logic_kit/fol/lambda_tools.py +297 -0
- unicode_logic_kit/fol/latex_input.py +429 -0
- unicode_logic_kit/fol/modal_translation.py +944 -0
- unicode_logic_kit/fol/msflparser.py +1033 -0
- unicode_logic_kit/fol/naming.py +422 -0
- unicode_logic_kit/fol/nodes.py +241 -0
- unicode_logic_kit/fol/normalforms.py +492 -0
- unicode_logic_kit/fol/pal.py +287 -0
- unicode_logic_kit/fol/prolog_export.py +566 -0
- unicode_logic_kit/fol/prolog_input.py +505 -0
- unicode_logic_kit/fol/prover9_input.py +1325 -0
- unicode_logic_kit/fol/qml.py +1760 -0
- unicode_logic_kit/fol/qmltp_input.py +525 -0
- unicode_logic_kit/fol/sanitize.py +221 -0
- unicode_logic_kit/fol/serialize.py +79 -0
- unicode_logic_kit/fol/signature.py +1290 -0
- unicode_logic_kit/fol/simplify_check.py +544 -0
- unicode_logic_kit/fol/spans.py +594 -0
- unicode_logic_kit/fol/tptp_input.py +1503 -0
- unicode_logic_kit/fol/tptp_repair.py +941 -0
- unicode_logic_kit/fol/unification.py +157 -0
- unicode_logic_kit/fol/verbalize.py +263 -0
- unicode_logic_kit/hets/__init__.py +163 -0
- unicode_logic_kit/hets/bridge.py +142 -0
- unicode_logic_kit/hets/client.py +748 -0
- unicode_logic_kit/hets/docker.py +420 -0
- unicode_logic_kit/hets/dol.py +712 -0
- unicode_logic_kit/hets/haskell_json.py +355 -0
- unicode_logic_kit/hets/owl_backend.py +794 -0
- unicode_logic_kit/hets/owl_cli.py +598 -0
- unicode_logic_kit/hets/symbols.py +512 -0
- unicode_logic_kit/hol/__init__.py +140 -0
- unicode_logic_kit/hol/_ho_common.py +323 -0
- unicode_logic_kit/hol/_isabelle_binders.py +125 -0
- unicode_logic_kit/hol/classical.py +812 -0
- unicode_logic_kit/hol/deepshallow/__init__.py +45 -0
- unicode_logic_kit/hol/deepshallow/_common.py +177 -0
- unicode_logic_kit/hol/deepshallow/conditional.py +225 -0
- unicode_logic_kit/hol/deepshallow/intuitionistic.py +181 -0
- unicode_logic_kit/hol/deepshallow/modal.py +217 -0
- unicode_logic_kit/hol/deepshallow/qml.py +406 -0
- unicode_logic_kit/hol/deepshallow/relevant.py +206 -0
- unicode_logic_kit/hol/free.py +753 -0
- unicode_logic_kit/hol/goedel.py +336 -0
- unicode_logic_kit/hol/ho_modal.py +1743 -0
- unicode_logic_kit/hol/intuitionistic.py +403 -0
- unicode_logic_kit/hol/isabelle_conditional.py +593 -0
- unicode_logic_kit/hol/isabelle_modal.py +1908 -0
- unicode_logic_kit/hol/isabelle_relevant.py +412 -0
- unicode_logic_kit/hol/isabelle_runner.py +1147 -0
- unicode_logic_kit/hol/isabelle_substructural.py +884 -0
- unicode_logic_kit/hol/lean.py +1018 -0
- unicode_logic_kit/hol/manyvalued.py +921 -0
- unicode_logic_kit/hol/secondorder.py +687 -0
- unicode_logic_kit/hol/thf_modal.py +941 -0
- unicode_logic_kit/hol/thirdorder.py +397 -0
- unicode_logic_kit/ilp/__init__.py +89 -0
- unicode_logic_kit/ilp/readback.py +389 -0
- unicode_logic_kit/ilp/separation.py +153 -0
- unicode_logic_kit/ilp/task.py +730 -0
- unicode_logic_kit/logic.py +163 -0
- unicode_logic_kit/mcp/__init__.py +28 -0
- unicode_logic_kit/mcp/__main__.py +5 -0
- unicode_logic_kit/mcp/chem_tools.py +1031 -0
- unicode_logic_kit/mcp/server.py +2453 -0
- unicode_logic_kit/mcp/syntax_spec.py +681 -0
- unicode_logic_kit/prob/__init__.py +53 -0
- unicode_logic_kit/prob/_bdd.py +225 -0
- unicode_logic_kit/prob/_column_gen.py +668 -0
- unicode_logic_kit/prob/distribution.py +686 -0
- unicode_logic_kit/prob/nilsson.py +470 -0
- unicode_logic_kit/py.typed +0 -0
- unicode_logic_kit/semantics/__init__.py +137 -0
- unicode_logic_kit/semantics/_modal_reject.py +156 -0
- unicode_logic_kit/semantics/action_models.py +466 -0
- unicode_logic_kit/semantics/asp_models.py +1200 -0
- unicode_logic_kit/semantics/conditional.py +580 -0
- unicode_logic_kit/semantics/dynamic_epistemic.py +95 -0
- unicode_logic_kit/semantics/free_logic.py +913 -0
- unicode_logic_kit/semantics/fuzzy.py +384 -0
- unicode_logic_kit/semantics/fuzzy_kripke.py +442 -0
- unicode_logic_kit/semantics/intuitionistic.py +581 -0
- unicode_logic_kit/semantics/kripke.py +1139 -0
- unicode_logic_kit/semantics/manyvalued.py +580 -0
- unicode_logic_kit/semantics/matrix.py +342 -0
- unicode_logic_kit/semantics/model_eval.py +1135 -0
- unicode_logic_kit/semantics/modelfinder.py +1036 -0
- unicode_logic_kit/semantics/nonmonotonic.py +372 -0
- unicode_logic_kit/semantics/relevant.py +331 -0
- unicode_logic_kit/semantics/secondorder.py +657 -0
- unicode_logic_kit/semantics/structures.py +352 -0
- unicode_logic_kit/semantics/tarski.py +975 -0
- unicode_logic_kit/semantics/team.py +315 -0
- unicode_logic_kit/semantics/team_translation.py +416 -0
- unicode_logic_kit/semantics/thirdorder.py +358 -0
- unicode_logic_kit/semantics/tnorm.py +85 -0
- unicode_logic_kit/semantics/truthtable.py +201 -0
- unicode_logic_kit-0.31.0.dist-info/METADATA +333 -0
- unicode_logic_kit-0.31.0.dist-info/RECORD +237 -0
- unicode_logic_kit-0.31.0.dist-info/WHEEL +4 -0
- unicode_logic_kit-0.31.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
r"""Joining HETS' TPTP symbols back onto the OWL entities they came from.
|
|
2
|
+
|
|
3
|
+
What this module is for
|
|
4
|
+
-----------------------
|
|
5
|
+
HETS' ``OWL22CASL:CASL2TPTP_FOF`` route renders an OWL entity as a mangled
|
|
6
|
+
TPTP symbol::
|
|
7
|
+
|
|
8
|
+
pred_https_u_u_uopenenergyplatform_uorg_uontology_uoeo_uOEO_00000072
|
|
9
|
+
|
|
10
|
+
and :func:`unicode_logic_kit.fol.tptp_input.parse_tptp` reads that back as the
|
|
11
|
+
kit predicate ``Pred_https_u_u_u...``. Neither form says which class that is,
|
|
12
|
+
so a disagreement between the HETS route and this kit's own
|
|
13
|
+
:mod:`unicode_logic_kit.dl` route cannot be reported in terms anyone can check.
|
|
14
|
+
This module builds the join: one row per declared entity, carrying HETS'
|
|
15
|
+
printed name, the full IRI, the TPTP symbol, the kit symbol, whether the
|
|
16
|
+
symbol occurs in the TPTP at all, and the entity's ``rdfs:label``\ s.
|
|
17
|
+
|
|
18
|
+
Everything here is a PURE function over a ``/dg`` dict and a TPTP string —
|
|
19
|
+
no network, no Docker, no subprocess. That is deliberate: it is what lets
|
|
20
|
+
every number below be asserted on a machine with no HETS at all. The
|
|
21
|
+
Docker/command-line half lives in :mod:`~unicode_logic_kit.hets.owl_cli`.
|
|
22
|
+
|
|
23
|
+
The mangling is a computation, not a guess
|
|
24
|
+
------------------------------------------
|
|
25
|
+
``/dg``'s ``Declarations[i]`` carries ``{kind, name, iri, Symbol}``, where
|
|
26
|
+
``iri`` is HETS' PRINTED form — a CURIE when the ontology declared a prefix
|
|
27
|
+
(``obo:BFO_0000001``) and the full IRI otherwise. That printed form is
|
|
28
|
+
exactly the mangling INPUT:
|
|
29
|
+
|
|
30
|
+
* replace every character outside ``[A-Za-z0-9_]`` with ``_u``;
|
|
31
|
+
* prefix ``op_`` for an ``Individual``, ``sort_`` for a ``Datatype``,
|
|
32
|
+
``pred_`` for everything else.
|
|
33
|
+
|
|
34
|
+
Measured on the real OEO pair (2099 declarations, 1667 printed as full IRIs
|
|
35
|
+
and 432 as CURIEs over 10 prefixes): this reproduces 2026 names that actually
|
|
36
|
+
occur in the TPTP text, with 0 collisions. So no prefix-map reconstruction is
|
|
37
|
+
needed for the forward direction. The prefix map is still read — by
|
|
38
|
+
:func:`hets_prefixes`, from HETS' own ``Prefix: p: <iri>`` output — but only
|
|
39
|
+
to EXPAND a CURIE to a full IRI, so the table can be joined with the OWL file
|
|
40
|
+
and with the ``dl`` route.
|
|
41
|
+
|
|
42
|
+
The mangling is not invertible (a printed form containing a literal ``_u`` is
|
|
43
|
+
indistinguishable from a mangled separator), so this module never inverts it:
|
|
44
|
+
the reverse indexes are built FROM the forward map, and
|
|
45
|
+
:class:`HetsSymbolCollisionError` is raised at build time if two printed forms
|
|
46
|
+
mangle to the same symbol, rather than silently keeping whichever came last.
|
|
47
|
+
|
|
48
|
+
The 73 declarations with no TPTP symbol are a FACT, not an error
|
|
49
|
+
----------------------------------------------------------------
|
|
50
|
+
On OEO: 68 ``AnnotationProperty`` (annotation properties carry no logical
|
|
51
|
+
content under OWL 2's direct semantics, so a comorphism legitimately never
|
|
52
|
+
emits them) and 5 ``ObjectProperty`` declared but used in no logical axiom.
|
|
53
|
+
They are reported as ``in_tptp=False`` rows, never dropped. The 21 TPTP
|
|
54
|
+
symbols with no declaration — CASL numerals ``op_0``..``op_9``, OWL built-ins
|
|
55
|
+
``pred_Thing``/``pred_Nothing``, HETS' sort predicates ``sort_DATA``/
|
|
56
|
+
``sort_Thing``/``sort_xsd_u*`` and the collapsed facet predicate
|
|
57
|
+
``pred_____`` — are reported as :attr:`HetsSymbolTable.unmapped_tptp`.
|
|
58
|
+
|
|
59
|
+
The omitted axioms are derivable exactly
|
|
60
|
+
----------------------------------------
|
|
61
|
+
HETS names every translated axiom ``ax_ax<N>`` where ``<N>`` is the index of
|
|
62
|
+
``/dg``'s axiom item ``Ax<N>``, so ``{Ax<N> in /dg} \ {N with an ax_ax<N>
|
|
63
|
+
formula}`` is computable — see :func:`untranslated_axioms`. On the real pair
|
|
64
|
+
that difference is 8997 axioms, of which 8991 are ``AnnotationAssertion`` and
|
|
65
|
+
4 are ``SubAnnotationPropertyOf`` (both annotation axiom kinds, which OWL 2's
|
|
66
|
+
direct semantics gives no consequence, hence excluded by default) and exactly
|
|
67
|
+
2 are ``DataPropertyRange`` — ``OEO_00390094`` and ``OEO_00390098``, the two
|
|
68
|
+
axioms the lossy ``-Y`` translation drops. That agrees with the requesting
|
|
69
|
+
project's own count, reached by a completely different method (diffing against
|
|
70
|
+
a hand-reduced ontology), which is what makes the 2 trustworthy.
|
|
71
|
+
|
|
72
|
+
Two routes, and why this module exists at all
|
|
73
|
+
---------------------------------------------
|
|
74
|
+
No ``dl`` file is touched and no construct reaches the description-logic
|
|
75
|
+
tableau. The two-route rule applies at the level the whole OEO request is
|
|
76
|
+
about: the HETS translation is the SECOND FOL image of an ontology, to be
|
|
77
|
+
compared against :func:`unicode_logic_kit.dl.tbox_to_fol` /
|
|
78
|
+
:func:`unicode_logic_kit.dl.kb_to_fol` plus :func:`unicode_logic_kit.api.prove`.
|
|
79
|
+
A comparison is only worth anything if neither side is presented as more
|
|
80
|
+
complete than it is, which is what ``in_tptp``, ``unmapped_tptp`` and
|
|
81
|
+
:func:`untranslated_axioms` are for.
|
|
82
|
+
|
|
83
|
+
HETS' own translation defects, measured on the real pair, so a disagreement is
|
|
84
|
+
attributable rather than blamed on this kit:
|
|
85
|
+
|
|
86
|
+
* an n-ary ``DifferentIndividuals`` is expanded to FEWER than all pairs
|
|
87
|
+
(strictly weaker than OWL 2 requires; 2 axioms in OEO);
|
|
88
|
+
* ``DataPropertyRange(d xsd:string)`` renders as
|
|
89
|
+
``forall x. exists y:DATA. (d(x,y) => y in xsd:string)`` — the existential
|
|
90
|
+
OVER the implication, which is near-vacuous (3 axioms);
|
|
91
|
+
* both facets of a ``DatatypeRestriction`` collapse to the same predicate
|
|
92
|
+
``pred_____`` (the 7 ``idrange`` datatype definitions);
|
|
93
|
+
* 19 ``ax_ax<N>`` formula names are DUPLICATED, so a caller must not key
|
|
94
|
+
formulas by name. :func:`untranslated_axioms` is duplicate-safe by
|
|
95
|
+
construction: it works from the SET of indices present.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
from __future__ import annotations
|
|
99
|
+
|
|
100
|
+
import collections
|
|
101
|
+
import re
|
|
102
|
+
from dataclasses import dataclass
|
|
103
|
+
from typing import Dict, Mapping, Optional, Tuple
|
|
104
|
+
|
|
105
|
+
# Imported rather than re-implemented ON PURPOSE: ``kit_name`` has to be what
|
|
106
|
+
# tptp_input's reader actually produces for a TPTP predicate, so if that
|
|
107
|
+
# convention ever changes this table changes with it instead of silently
|
|
108
|
+
# desynchronising.
|
|
109
|
+
from ..fol.tptp_input import _cap
|
|
110
|
+
|
|
111
|
+
__all__ = [
|
|
112
|
+
"HetsSymbol",
|
|
113
|
+
"HetsSymbolTable",
|
|
114
|
+
"HetsSymbolCollisionError",
|
|
115
|
+
"UntranslatedAxiom",
|
|
116
|
+
"hets_symbol_table",
|
|
117
|
+
"untranslated_axioms",
|
|
118
|
+
"hets_prefixes",
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
#: HETS prefixes a TPTP symbol by the entity's role. ``Individual`` becomes a
|
|
122
|
+
#: CASL operation (a constant), ``Datatype`` a sort, and every class or
|
|
123
|
+
#: property a predicate.
|
|
124
|
+
_KIND_PREFIX = {"Individual": "op_", "Datatype": "sort_"}
|
|
125
|
+
_DEFAULT_PREFIX = "pred_"
|
|
126
|
+
|
|
127
|
+
#: Every character outside this set becomes ``_u`` in a HETS TPTP symbol.
|
|
128
|
+
_NON_SYMBOL_CHAR = re.compile(r"[^A-Za-z0-9_]")
|
|
129
|
+
|
|
130
|
+
#: A TPTP symbol HETS could have produced, for the ``unmapped_tptp`` census.
|
|
131
|
+
_TPTP_SYMBOL = re.compile(r"\b(?:pred|op|sort)_[A-Za-z0-9_]*")
|
|
132
|
+
|
|
133
|
+
#: ``fof(ax_ax4027, axiom, ...)`` -> the axiom index 4027.
|
|
134
|
+
_AX_FORMULA = re.compile(r"\b(?:fof|cnf|tff)\(\s*ax_ax(\d+)\s*,")
|
|
135
|
+
|
|
136
|
+
#: ``/dg``'s axiom item name, ``Ax4027``.
|
|
137
|
+
_AX_ITEM = re.compile(r"^Ax(\d+)$")
|
|
138
|
+
|
|
139
|
+
#: ``AnnotationAssertion( rdfs:label <subject> "text"@lang )``, with the
|
|
140
|
+
#: language tag optional. The literal body allows backslash escapes because
|
|
141
|
+
#: HETS prints OWL literals with them.
|
|
142
|
+
_LABEL_AXIOM = re.compile(
|
|
143
|
+
r'^AnnotationAssertion\(\s*rdfs:label\s+(\S+)\s+'
|
|
144
|
+
r'"((?:[^"\\]|\\.)*)"(?:@([A-Za-z0-9-]+))?\s*\)$')
|
|
145
|
+
|
|
146
|
+
#: ``Prefix: obo: <http://purl.obolibrary.org/obo/>``, as HETS writes it into
|
|
147
|
+
#: a ``pp.dol`` or ``/theory`` rendering. The prefix NAME may be empty.
|
|
148
|
+
_PREFIX_LINE = re.compile(
|
|
149
|
+
r"^[ \t]*Prefix:[ \t]*([A-Za-z0-9_.-]*):[ \t]*<([^>]*)>", re.MULTILINE)
|
|
150
|
+
|
|
151
|
+
#: The five OWL 2 axiom kinds whose direct semantics is empty, so a
|
|
152
|
+
#: comorphism that drops them loses nothing. Excluded from
|
|
153
|
+
#: :func:`untranslated_axioms` by default — justified by the OWL 2
|
|
154
|
+
#: specification, not by a heuristic about what HETS happens to do.
|
|
155
|
+
_ANNOTATION_KINDS = frozenset({
|
|
156
|
+
"AnnotationAssertion",
|
|
157
|
+
"SubAnnotationPropertyOf",
|
|
158
|
+
"AnnotationPropertyDomain",
|
|
159
|
+
"AnnotationPropertyRange",
|
|
160
|
+
"Declaration",
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
_LEADING_FUNCTOR = re.compile(r"\s*([A-Za-z][A-Za-z0-9]*)")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class HetsSymbolCollisionError(RuntimeError):
|
|
167
|
+
"""Two declared entities mangle to the same HETS TPTP symbol.
|
|
168
|
+
|
|
169
|
+
Raised when the table is BUILT, not when it is queried, and it names both
|
|
170
|
+
IRIs. The mangling ``[^A-Za-z0-9_] -> "_u"`` is not injective, so a
|
|
171
|
+
collision is possible in principle (it does not occur in OEO). Keeping
|
|
172
|
+
whichever declaration came last would make every later lookup for the
|
|
173
|
+
other entity silently answer about the wrong one — which is the kind of
|
|
174
|
+
quiet wrong answer this kit refuses.
|
|
175
|
+
"""
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@dataclass(frozen=True)
|
|
179
|
+
class HetsSymbol:
|
|
180
|
+
"""One declared OWL entity and its images on the HETS TPTP route.
|
|
181
|
+
|
|
182
|
+
Fields:
|
|
183
|
+
|
|
184
|
+
* ``printed`` — HETS' printed name, exactly as ``/dg`` gives it, and the
|
|
185
|
+
INPUT to the mangling (``"obo:BFO_0000001"``, or a full IRI when
|
|
186
|
+
no prefix was declared for it).
|
|
187
|
+
* ``iri`` — the full IRI — :attr:`printed` with its CURIE prefix expanded
|
|
188
|
+
through the prefix map. Equal to :attr:`printed` when it was
|
|
189
|
+
already a full IRI or the prefix is unknown.
|
|
190
|
+
* ``name`` — the entity name as ``/dg`` reports it.
|
|
191
|
+
* ``kind`` — ``Class`` | ``ObjectProperty`` | ``DataProperty`` |
|
|
192
|
+
``AnnotationProperty`` | ``Individual`` | ``Datatype``.
|
|
193
|
+
* ``tptp_name`` — the symbol in HETS' TPTP text
|
|
194
|
+
(``"pred_obo_uBFO_0000001"``).
|
|
195
|
+
* ``kit_name`` — the symbol as :func:`unicode_logic_kit.fol.tptp_input.parse_tptp`
|
|
196
|
+
reads it back (``"Pred_obo_uBFO_0000001"``).
|
|
197
|
+
* ``in_tptp`` — whether :attr:`tptp_name` actually occurs in the TPTP text.
|
|
198
|
+
``False`` is a reported fact, not an error — see the module
|
|
199
|
+
docstring on the 73 OEO declarations with no symbol.
|
|
200
|
+
* ``labels`` — ``(label, language-tag)`` pairs from this entity's
|
|
201
|
+
``rdfs:label`` annotation assertions; the tag is ``""`` when the
|
|
202
|
+
literal carried none.
|
|
203
|
+
"""
|
|
204
|
+
|
|
205
|
+
printed: str
|
|
206
|
+
iri: str
|
|
207
|
+
name: str
|
|
208
|
+
kind: str
|
|
209
|
+
tptp_name: str
|
|
210
|
+
kit_name: str
|
|
211
|
+
in_tptp: bool
|
|
212
|
+
labels: Tuple[Tuple[str, str], ...] = ()
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
@dataclass(frozen=True)
|
|
216
|
+
class HetsSymbolTable:
|
|
217
|
+
"""Every declared entity of one development-graph node, joined to its TPTP symbols.
|
|
218
|
+
|
|
219
|
+
Fields:
|
|
220
|
+
|
|
221
|
+
* ``symbols`` — one :class:`HetsSymbol` per ``/dg`` declaration, in
|
|
222
|
+
declaration order.
|
|
223
|
+
* ``prefixes`` — the prefix map used to expand CURIEs (possibly empty).
|
|
224
|
+
* ``unmapped_tptp`` — sorted TPTP symbols that occur in the text with no
|
|
225
|
+
declaration behind them — CASL numerals, OWL built-ins and HETS'
|
|
226
|
+
own sort predicates. Reported rather than hidden, because a
|
|
227
|
+
formula over one of these is a formula this table cannot explain.
|
|
228
|
+
* ``unexpanded_prefixes`` — sorted CURIE prefixes that appear in a
|
|
229
|
+
declaration but are absent from :attr:`prefixes`, so those rows'
|
|
230
|
+
:attr:`HetsSymbol.iri` is still the CURIE. Reported for the same
|
|
231
|
+
reason as the two fields above: an empty or wrong prefix map
|
|
232
|
+
otherwise degrades the table silently, and a CURIE cannot be
|
|
233
|
+
joined with the OWL file or with the ``dl`` route. Empty means
|
|
234
|
+
every declaration's IRI is a full IRI.
|
|
235
|
+
"""
|
|
236
|
+
|
|
237
|
+
symbols: Tuple[HetsSymbol, ...]
|
|
238
|
+
prefixes: Mapping[str, str]
|
|
239
|
+
unmapped_tptp: Tuple[str, ...]
|
|
240
|
+
unexpanded_prefixes: Tuple[str, ...] = ()
|
|
241
|
+
|
|
242
|
+
def by_iri(self, iri: str) -> Optional[HetsSymbol]:
|
|
243
|
+
"""The entity with this full IRI, or ``None``."""
|
|
244
|
+
return self._index("iri").get(iri)
|
|
245
|
+
|
|
246
|
+
def by_printed(self, printed: str) -> Optional[HetsSymbol]:
|
|
247
|
+
"""The entity with this printed (possibly CURIE) name, or ``None``."""
|
|
248
|
+
return self._index("printed").get(printed)
|
|
249
|
+
|
|
250
|
+
def by_tptp_name(self, name: str) -> Optional[HetsSymbol]:
|
|
251
|
+
"""The entity behind this HETS TPTP symbol, or ``None``."""
|
|
252
|
+
return self._index("tptp_name").get(name)
|
|
253
|
+
|
|
254
|
+
def by_kit_name(self, name: str) -> Optional[HetsSymbol]:
|
|
255
|
+
"""The entity behind this kit predicate/function name, or ``None``."""
|
|
256
|
+
return self._index("kit_name").get(name)
|
|
257
|
+
|
|
258
|
+
def by_label(self, label: str, *, lang: str = "en") -> Tuple[HetsSymbol, ...]:
|
|
259
|
+
"""Every entity carrying this ``rdfs:label`` in this language.
|
|
260
|
+
|
|
261
|
+
A TUPLE, even though no OEO label is shared by two subjects:
|
|
262
|
+
``rdfs:label`` is not required to be unique in OWL 2, so a function
|
|
263
|
+
that returned one symbol would be silently picking for the caller on
|
|
264
|
+
the next ontology. Pass ``lang=""`` for the untagged literals.
|
|
265
|
+
"""
|
|
266
|
+
return tuple(symbol for symbol in self.symbols
|
|
267
|
+
if (label, lang) in symbol.labels)
|
|
268
|
+
|
|
269
|
+
def _index(self, field: str) -> Dict[str, HetsSymbol]:
|
|
270
|
+
# Built lazily from the forward map and cached on the (frozen)
|
|
271
|
+
# instance via object.__setattr__ -- never by inverting the mangling,
|
|
272
|
+
# which is not injective.
|
|
273
|
+
cache = getattr(self, "_indexes", None)
|
|
274
|
+
if cache is None:
|
|
275
|
+
cache = {}
|
|
276
|
+
object.__setattr__(self, "_indexes", cache)
|
|
277
|
+
if field not in cache:
|
|
278
|
+
cache[field] = {getattr(s, field): s for s in self.symbols}
|
|
279
|
+
return cache[field]
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@dataclass(frozen=True)
|
|
283
|
+
class UntranslatedAxiom:
|
|
284
|
+
"""One ``/dg`` axiom with no formula in the TPTP translation.
|
|
285
|
+
|
|
286
|
+
Fields:
|
|
287
|
+
|
|
288
|
+
* ``name`` — the ``/dg`` axiom item name, ``"Ax4027"``.
|
|
289
|
+
* ``owl`` — the axiom's OWL functional-syntax text, verbatim.
|
|
290
|
+
* ``kind`` — its leading functor, ``"DataPropertyRange"``.
|
|
291
|
+
"""
|
|
292
|
+
|
|
293
|
+
name: str
|
|
294
|
+
owl: str
|
|
295
|
+
kind: str
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
def hets_prefixes(theory_text: str) -> Dict[str, str]:
|
|
299
|
+
"""Read HETS' own ``Prefix: p: <iri>`` lines out of a rendering.
|
|
300
|
+
|
|
301
|
+
Works on anything HETS prints with a prefix block — a ``pp.dol`` file or
|
|
302
|
+
the native ``/theory`` text. The empty prefix (``Prefix: : <...>``) comes
|
|
303
|
+
back under the key ``""``. A repeated prefix keeps the LAST binding, which
|
|
304
|
+
is what a reader of the document would see.
|
|
305
|
+
|
|
306
|
+
Args:
|
|
307
|
+
theory_text: HETS output containing a prefix block (or not).
|
|
308
|
+
|
|
309
|
+
Returns:
|
|
310
|
+
``{prefix-name: namespace-iri}``; empty when there is no block.
|
|
311
|
+
|
|
312
|
+
Example:
|
|
313
|
+
>>> hets_prefixes(" Prefix: obo: <http://purl.obolibrary.org/obo/>")
|
|
314
|
+
{'obo': 'http://purl.obolibrary.org/obo/'}
|
|
315
|
+
"""
|
|
316
|
+
return {match.group(1): match.group(2)
|
|
317
|
+
for match in _PREFIX_LINE.finditer(theory_text)}
|
|
318
|
+
|
|
319
|
+
|
|
320
|
+
def _mangle(printed: str, kind: str) -> str:
|
|
321
|
+
"""HETS' printed name -> its TPTP symbol (the rule the module docstring states)."""
|
|
322
|
+
prefix = _KIND_PREFIX.get(kind, _DEFAULT_PREFIX)
|
|
323
|
+
return prefix + _NON_SYMBOL_CHAR.sub("_u", printed)
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
def _expand(printed: str, prefixes: Mapping[str, str]):
|
|
327
|
+
"""Expand a CURIE through the prefix map.
|
|
328
|
+
|
|
329
|
+
A full IRI is recognised by its scheme separator ``://``, so
|
|
330
|
+
``https://example.org/x`` is never mistaken for the CURIE prefix
|
|
331
|
+
``https``.
|
|
332
|
+
|
|
333
|
+
Returns:
|
|
334
|
+
``(iri, unexpanded_prefix)``. The second element is the CURIE prefix
|
|
335
|
+
that could NOT be expanded, or ``None``; the caller collects those so
|
|
336
|
+
an absent prefix map is reported instead of quietly leaving CURIEs in
|
|
337
|
+
the table.
|
|
338
|
+
"""
|
|
339
|
+
head, sep, tail = printed.partition(":")
|
|
340
|
+
if not sep or tail.startswith("//"):
|
|
341
|
+
return printed, None
|
|
342
|
+
namespace = prefixes.get(head)
|
|
343
|
+
if namespace is None:
|
|
344
|
+
return printed, head
|
|
345
|
+
return namespace + tail, None
|
|
346
|
+
|
|
347
|
+
|
|
348
|
+
def _pick_node(dg: Mapping, node: Optional[str]) -> Mapping:
|
|
349
|
+
"""The one ``DGNode`` to read, by name or by being the only one.
|
|
350
|
+
|
|
351
|
+
Raises:
|
|
352
|
+
ValueError: the graph has no node, or several and ``node`` was not
|
|
353
|
+
given (or names one that is not there). Never picks for the
|
|
354
|
+
caller: which node a symbol table is about changes every answer
|
|
355
|
+
drawn from it.
|
|
356
|
+
"""
|
|
357
|
+
graph = dg.get("DGraph") or {}
|
|
358
|
+
nodes = graph.get("DGNode") or []
|
|
359
|
+
if isinstance(nodes, dict):
|
|
360
|
+
nodes = [nodes]
|
|
361
|
+
if not nodes:
|
|
362
|
+
raise ValueError(
|
|
363
|
+
"hets: this development graph has no DGNode, so there are no "
|
|
364
|
+
"declarations to build a symbol table from. If the response came "
|
|
365
|
+
"from HetsClient.dg, check that the upload succeeded.")
|
|
366
|
+
if node is not None:
|
|
367
|
+
for candidate in nodes:
|
|
368
|
+
if candidate.get("name") == node:
|
|
369
|
+
return candidate
|
|
370
|
+
raise ValueError(
|
|
371
|
+
f"hets: no development-graph node named {node!r}; this graph has "
|
|
372
|
+
f"{[n.get('name') for n in nodes]!r}.")
|
|
373
|
+
if len(nodes) != 1:
|
|
374
|
+
raise ValueError(
|
|
375
|
+
"hets: this development graph has "
|
|
376
|
+
f"{len(nodes)} nodes ({[n.get('name') for n in nodes]!r}) — pass "
|
|
377
|
+
"node=<name> to say which one the symbol table is about. Guessing "
|
|
378
|
+
"would make every lookup answer about an arbitrary ontology.")
|
|
379
|
+
return nodes[0]
|
|
380
|
+
|
|
381
|
+
|
|
382
|
+
def _labels_by_subject(axioms) -> Dict[str, Tuple[Tuple[str, str], ...]]:
|
|
383
|
+
"""Collect ``rdfs:label`` assertions, keyed by HETS' printed subject name."""
|
|
384
|
+
found = collections.defaultdict(list)
|
|
385
|
+
for axiom in axioms:
|
|
386
|
+
match = _LABEL_AXIOM.match(axiom.get("Axiom", "").strip())
|
|
387
|
+
if match:
|
|
388
|
+
subject, label, lang = match.groups()
|
|
389
|
+
found[subject].append((label, lang or ""))
|
|
390
|
+
return {subject: tuple(pairs) for subject, pairs in found.items()}
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
def hets_symbol_table(dg: Mapping, tptp: str, *,
|
|
394
|
+
prefixes: Optional[Mapping[str, str]] = None,
|
|
395
|
+
node: Optional[str] = None) -> HetsSymbolTable:
|
|
396
|
+
"""Join one ``/dg`` node's declarations onto the symbols of a TPTP translation.
|
|
397
|
+
|
|
398
|
+
Args:
|
|
399
|
+
dg: a development-graph dict, as
|
|
400
|
+
:meth:`unicode_logic_kit.hets.client.HetsClient.dg` returns it.
|
|
401
|
+
tptp: the TPTP text HETS produced for that node.
|
|
402
|
+
prefixes: a prefix map for expanding CURIEs to full IRIs, e.g. from
|
|
403
|
+
:func:`hets_prefixes`. Without it, :attr:`HetsSymbol.iri` equals
|
|
404
|
+
:attr:`HetsSymbol.printed` for every CURIE — the table still
|
|
405
|
+
works, the IRIs are just not expanded.
|
|
406
|
+
node: which development-graph node. Required when the graph has more
|
|
407
|
+
than one.
|
|
408
|
+
|
|
409
|
+
Returns:
|
|
410
|
+
A :class:`HetsSymbolTable`.
|
|
411
|
+
|
|
412
|
+
Raises:
|
|
413
|
+
HetsSymbolCollisionError: two declarations mangle to one symbol.
|
|
414
|
+
ValueError: the node cannot be identified.
|
|
415
|
+
"""
|
|
416
|
+
prefixes = dict(prefixes or {})
|
|
417
|
+
chosen = _pick_node(dg, node)
|
|
418
|
+
declarations = chosen.get("Declarations") or []
|
|
419
|
+
axioms = chosen.get("Axioms") or []
|
|
420
|
+
labels = _labels_by_subject(axioms)
|
|
421
|
+
present = set(_TPTP_SYMBOL.findall(tptp))
|
|
422
|
+
|
|
423
|
+
by_tptp_name = collections.defaultdict(list)
|
|
424
|
+
unexpanded = set()
|
|
425
|
+
symbols = []
|
|
426
|
+
for declaration in declarations:
|
|
427
|
+
printed = declaration.get("iri") or declaration.get("name") or ""
|
|
428
|
+
kind = declaration.get("kind") or ""
|
|
429
|
+
tptp_name = _mangle(printed, kind)
|
|
430
|
+
by_tptp_name[tptp_name].append(printed)
|
|
431
|
+
iri, missing_prefix = _expand(printed, prefixes)
|
|
432
|
+
if missing_prefix is not None:
|
|
433
|
+
unexpanded.add(missing_prefix)
|
|
434
|
+
symbols.append(HetsSymbol(
|
|
435
|
+
printed=printed,
|
|
436
|
+
iri=iri,
|
|
437
|
+
name=declaration.get("name") or printed,
|
|
438
|
+
kind=kind,
|
|
439
|
+
tptp_name=tptp_name,
|
|
440
|
+
kit_name=_cap(tptp_name),
|
|
441
|
+
in_tptp=tptp_name in present,
|
|
442
|
+
labels=labels.get(printed, ()),
|
|
443
|
+
))
|
|
444
|
+
|
|
445
|
+
clashes = {name: sorted(set(owners))
|
|
446
|
+
for name, owners in by_tptp_name.items()
|
|
447
|
+
if len(set(owners)) > 1}
|
|
448
|
+
if clashes:
|
|
449
|
+
detail = "; ".join(
|
|
450
|
+
f"{name} <- {', '.join(owners)}" for name, owners in sorted(clashes.items()))
|
|
451
|
+
raise HetsSymbolCollisionError(
|
|
452
|
+
f"hets: {len(clashes)} HETS TPTP symbol(s) are claimed by more "
|
|
453
|
+
f"than one declared entity: {detail}. HETS' mangling "
|
|
454
|
+
"([^A-Za-z0-9_] -> '_u') is not injective, so this table cannot "
|
|
455
|
+
"say which entity a formula over such a symbol is about. It "
|
|
456
|
+
"refuses to build rather than keep whichever declaration came "
|
|
457
|
+
"last and answer every later lookup about the wrong entity.")
|
|
458
|
+
|
|
459
|
+
return HetsSymbolTable(
|
|
460
|
+
symbols=tuple(symbols),
|
|
461
|
+
prefixes=prefixes,
|
|
462
|
+
unmapped_tptp=tuple(sorted(present - set(by_tptp_name))),
|
|
463
|
+
unexpanded_prefixes=tuple(sorted(unexpanded)),
|
|
464
|
+
)
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def untranslated_axioms(dg: Mapping, tptp: str, *, node: Optional[str] = None,
|
|
468
|
+
include_annotations: bool = False
|
|
469
|
+
) -> Tuple[UntranslatedAxiom, ...]:
|
|
470
|
+
r"""The ``/dg`` axioms with no formula in the TPTP translation.
|
|
471
|
+
|
|
472
|
+
HETS names a translated axiom ``ax_ax<N>`` after the ``/dg`` axiom item
|
|
473
|
+
``Ax<N>``, so the difference is computable. Duplicate formula names (19 of
|
|
474
|
+
them in the real file — a HETS defect) cannot affect the result: the
|
|
475
|
+
comparison is between SETS of indices.
|
|
476
|
+
|
|
477
|
+
Args:
|
|
478
|
+
dg: the development-graph dict.
|
|
479
|
+
tptp: the TPTP text to compare against.
|
|
480
|
+
node: which development-graph node; required when there is more
|
|
481
|
+
than one.
|
|
482
|
+
include_annotations: also report the OWL 2 annotation axiom kinds
|
|
483
|
+
(``AnnotationAssertion``, ``SubAnnotationPropertyOf``,
|
|
484
|
+
``AnnotationPropertyDomain``, ``AnnotationPropertyRange``,
|
|
485
|
+
``Declaration``). They are excluded by default because OWL 2's
|
|
486
|
+
direct semantics gives them no consequence, so a comorphism that
|
|
487
|
+
drops them loses nothing — that exclusion is a SPEC fact, not a
|
|
488
|
+
guess about this translation.
|
|
489
|
+
|
|
490
|
+
Returns:
|
|
491
|
+
One :class:`UntranslatedAxiom` per axiom with no image, in ``/dg``
|
|
492
|
+
order. An EMPTY tuple means "computed, and nothing was omitted" — it
|
|
493
|
+
never means "not computed".
|
|
494
|
+
|
|
495
|
+
Raises:
|
|
496
|
+
ValueError: the node cannot be identified.
|
|
497
|
+
"""
|
|
498
|
+
chosen = _pick_node(dg, node)
|
|
499
|
+
present = {int(index) for index in _AX_FORMULA.findall(tptp)}
|
|
500
|
+
omitted = []
|
|
501
|
+
for axiom in chosen.get("Axioms") or []:
|
|
502
|
+
name = axiom.get("name") or ""
|
|
503
|
+
item = _AX_ITEM.match(name)
|
|
504
|
+
if not item or int(item.group(1)) in present:
|
|
505
|
+
continue
|
|
506
|
+
text = axiom.get("Axiom") or ""
|
|
507
|
+
functor = _LEADING_FUNCTOR.match(text)
|
|
508
|
+
kind = functor.group(1) if functor else ""
|
|
509
|
+
if not include_annotations and kind in _ANNOTATION_KINDS:
|
|
510
|
+
continue
|
|
511
|
+
omitted.append(UntranslatedAxiom(name=name, owl=text, kind=kind))
|
|
512
|
+
return tuple(omitted)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"""Higher-order / Isabelle / THF exporters: shallow semantical embeddings (SSE).
|
|
2
|
+
|
|
3
|
+
This subpackage *emits* Benzmüller-style shallow embeddings of the toolkit's non-fuzzy
|
|
4
|
+
logics into higher-order logic — as complete, self-contained problem files for an
|
|
5
|
+
external prover (Leo-III / Satallax on TPTP **THF**, or Isabelle/HOL theories for
|
|
6
|
+
Sledgehammer). The exporters only emit; a successful emission means "here is a sound
|
|
7
|
+
problem an external prover *may* discharge", never "decided" — first-order modal logic,
|
|
8
|
+
FOL and SOL are all undecidable (FOL and the standard first-order modal logics are still
|
|
9
|
+
semi-decidable — validity is recursively enumerable — whereas full second-order validity
|
|
10
|
+
is not even semi-decidable).
|
|
11
|
+
|
|
12
|
+
The optional :mod:`~unicode_logic_kit.hol.isabelle_runner` is the other half: if a local
|
|
13
|
+
Isabelle/HOL is installed, it actually *runs* it on the emitted modal theories
|
|
14
|
+
(prove-battery + nitpick) and reads a VALID / INVALID / UNKNOWN verdict off the build —
|
|
15
|
+
turning "emit" into "proven / refuted". It is sound (Isabelle's kernel certifies the
|
|
16
|
+
proof; nitpick reports only genuine counter-models) and, necessarily, incomplete.
|
|
17
|
+
|
|
18
|
+
Modules:
|
|
19
|
+
|
|
20
|
+
- :mod:`~unicode_logic_kit.hol.isabelle_modal` — a real, loadable Isabelle/HOL theory for
|
|
21
|
+
the **full modal family** (alethic, epistemic/doxastic over *agent-indexed* relations,
|
|
22
|
+
deontic, temporal), with all lifted operators, frame + domain axioms, the lifted
|
|
23
|
+
formula, and a real ``lemma``. Replaces the old alethic-only skeleton.
|
|
24
|
+
- :mod:`~unicode_logic_kit.hol.thf_modal` — the full-modal-family TPTP **THF** export
|
|
25
|
+
(agent-indexed epistemic/doxastic, deontic, temporal), extending the alethic-only
|
|
26
|
+
``qml.to_thf_modal``.
|
|
27
|
+
- :mod:`~unicode_logic_kit.hol.classical` — FOL and MSFOL → THF / Isabelle.
|
|
28
|
+
- :mod:`~unicode_logic_kit.hol.free` — free logic (negative/positive policies;
|
|
29
|
+
supervaluation explicitly refused) → THF / Isabelle, via two uninterpreted
|
|
30
|
+
guard predicates ``D`` (denotes) / ``E!`` (exists) over a single flat
|
|
31
|
+
individual type, plus the runner's ``isabelle_decide_free``.
|
|
32
|
+
- :mod:`~unicode_logic_kit.hol.isabelle_relevant` — relevant logic B (Routley–Meyer
|
|
33
|
+
shallow embedding, frame conditions as lemma premises) → Isabelle
|
|
34
|
+
(``to_isabelle_relevant``) / THF (``to_thf_relevant``), plus the runner's
|
|
35
|
+
``isabelle_decide_relevant``.
|
|
36
|
+
- :mod:`~unicode_logic_kit.hol.isabelle_conditional` — the Lewis counterfactuals
|
|
37
|
+
``□→``/``◇→`` (sphere-system shallow embedding, ``nested``/centering as lemma
|
|
38
|
+
premises) → Isabelle (``to_isabelle_conditional``, ``isabelle_conditional_theory``)
|
|
39
|
+
/ THF (``to_thf_conditional``), plus the runner's ``isabelle_decide_counterfactual``.
|
|
40
|
+
- :mod:`~unicode_logic_kit.hol.isabelle_substructural` — ILL / Lambek **derivation
|
|
41
|
+
replay**: the sequent rules as an ``inductive`` derivability predicate and the
|
|
42
|
+
concrete Python-found derivation replayed as a machine-checked lemma.
|
|
43
|
+
- :mod:`~unicode_logic_kit.hol.manyvalued` — three-valued K3 / LP → THF / Isabelle,
|
|
44
|
+
generalised to ANY finite :class:`~unicode_logic_kit.semantics.matrix.TruthMatrix`
|
|
45
|
+
(including Belnap–Dunn FDE) via ``to_thf_matrix`` / ``to_isabelle_matrix``.
|
|
46
|
+
- :mod:`~unicode_logic_kit.hol.secondorder` — second-order logic → THF / Isabelle
|
|
47
|
+
(native higher-order predicate quantification; standard semantics).
|
|
48
|
+
- :mod:`~unicode_logic_kit.hol.thirdorder` — CLASSICAL third-order logic → THF /
|
|
49
|
+
Isabelle: a predicate whose argument is a property (``Positive(G)``), typed by
|
|
50
|
+
inferring each argument slot from the formulas together.
|
|
51
|
+
- :mod:`~unicode_logic_kit.hol.ho_modal` — third-order MODAL logic, via the shallow
|
|
52
|
+
embedding (propositions as functions from worlds), which is the setting Gödel's
|
|
53
|
+
ontological argument is stated in.
|
|
54
|
+
- :mod:`~unicode_logic_kit.hol.goedel` — that argument as the third-order machinery's
|
|
55
|
+
proving ground: Scott's version (whose conclusions AND modal collapse are proved,
|
|
56
|
+
with a Nitpick model for consistency) and Gödel's own (which proves falsity).
|
|
57
|
+
- :mod:`~unicode_logic_kit.hol.intuitionistic` — intuitionistic propositional logic → HOL
|
|
58
|
+
via the Gödel–McKinsey–Tarski translation into S4 then the alethic SSE.
|
|
59
|
+
- :mod:`~unicode_logic_kit.hol.deepshallow` — the **deep + maximal-shallow +
|
|
60
|
+
minimal-shallow** embeddings of a non-classical logic *with machine-checked
|
|
61
|
+
faithfulness proofs* between them (Benzmüller, arXiv:2502.19311). Unlike the
|
|
62
|
+
emit-only SSE above, these theories are verified end to end by the Isabelle runner.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
from .isabelle_modal import (
|
|
66
|
+
to_isabelle_modal, isabelle_modal_theory, ISABELLE_TACTICS, modal_axiom_names,
|
|
67
|
+
BRIDGES,
|
|
68
|
+
)
|
|
69
|
+
from .isabelle_runner import (
|
|
70
|
+
find_isabelle, isabelle_available, isabelle_decide_modal, isabelle_decide_fol,
|
|
71
|
+
isabelle_decide_counterfactual, isabelle_decide_relevant, isabelle_decide_free,
|
|
72
|
+
check_theory, IsabelleInstall, IsabelleNotAvailable, BuildResult,
|
|
73
|
+
ModalVerdict, FolVerdict, DEFAULT_METHODS,
|
|
74
|
+
)
|
|
75
|
+
from .isabelle_relevant import to_isabelle_relevant, to_thf_relevant
|
|
76
|
+
from .isabelle_conditional import (
|
|
77
|
+
to_isabelle_conditional, isabelle_conditional_theory, to_thf_conditional,
|
|
78
|
+
)
|
|
79
|
+
from .isabelle_substructural import (
|
|
80
|
+
to_isabelle_ill, ill_derivation_theory,
|
|
81
|
+
to_isabelle_lambek, lambek_derivation_theory,
|
|
82
|
+
)
|
|
83
|
+
from .thf_modal import to_thf_modal_full, thf_full_definitions, thf_full_frame_axioms
|
|
84
|
+
from .classical import to_thf_fol, to_isabelle_fol, to_thf_msfol, to_isabelle_msfol
|
|
85
|
+
from .free import to_thf_free, to_isabelle_free, free_theory
|
|
86
|
+
from .manyvalued import (
|
|
87
|
+
to_thf_k3lp, to_isabelle_k3lp,
|
|
88
|
+
to_thf_k3lp_entailment, to_isabelle_k3lp_entailment, SYSTEMS,
|
|
89
|
+
to_thf_matrix, to_isabelle_matrix,
|
|
90
|
+
to_thf_matrix_entailment, to_isabelle_matrix_entailment,
|
|
91
|
+
)
|
|
92
|
+
from .secondorder import to_thf_so, to_isabelle_so
|
|
93
|
+
from .thirdorder import to_thf_to, to_isabelle_to
|
|
94
|
+
from .ho_modal import (
|
|
95
|
+
to_thf_ho_modal, to_isabelle_ho_modal, isabelle_ho_modal_theory,
|
|
96
|
+
ho_modal_definitions, HoAxiom, HoGoal, UnsupportedHigherOrderNode,
|
|
97
|
+
)
|
|
98
|
+
from .intuitionistic import (
|
|
99
|
+
gmt_translate, to_thf_intuitionistic, to_isabelle_intuitionistic,
|
|
100
|
+
gmt_is_s4_valid, gmt_validity_matches_int_valid,
|
|
101
|
+
)
|
|
102
|
+
from .deepshallow import (
|
|
103
|
+
modal_faithfulness_theory, modal_to_deep,
|
|
104
|
+
intuitionistic_faithfulness_theory, int_to_deep,
|
|
105
|
+
conditional_faithfulness_theory, counterfactual_to_deep,
|
|
106
|
+
relevant_faithfulness_theory, rel_to_deep,
|
|
107
|
+
qml_deep_faithfulness_theory, qml_to_deep,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
__all__ = [
|
|
111
|
+
"to_isabelle_modal", "isabelle_modal_theory", "ISABELLE_TACTICS",
|
|
112
|
+
"modal_axiom_names", "BRIDGES",
|
|
113
|
+
"find_isabelle", "isabelle_available", "isabelle_decide_modal",
|
|
114
|
+
"isabelle_decide_fol", "isabelle_decide_counterfactual",
|
|
115
|
+
"isabelle_decide_relevant", "isabelle_decide_free", "check_theory",
|
|
116
|
+
"IsabelleInstall", "IsabelleNotAvailable", "BuildResult",
|
|
117
|
+
"ModalVerdict", "FolVerdict", "DEFAULT_METHODS",
|
|
118
|
+
"to_isabelle_relevant", "to_thf_relevant",
|
|
119
|
+
"to_isabelle_conditional", "isabelle_conditional_theory", "to_thf_conditional",
|
|
120
|
+
"to_isabelle_ill", "ill_derivation_theory",
|
|
121
|
+
"to_isabelle_lambek", "lambek_derivation_theory",
|
|
122
|
+
"to_thf_modal_full", "thf_full_definitions", "thf_full_frame_axioms",
|
|
123
|
+
"to_thf_fol", "to_isabelle_fol", "to_thf_msfol", "to_isabelle_msfol",
|
|
124
|
+
"to_thf_free", "to_isabelle_free", "free_theory",
|
|
125
|
+
"to_thf_k3lp", "to_isabelle_k3lp",
|
|
126
|
+
"to_thf_k3lp_entailment", "to_isabelle_k3lp_entailment", "SYSTEMS",
|
|
127
|
+
"to_thf_matrix", "to_isabelle_matrix",
|
|
128
|
+
"to_thf_matrix_entailment", "to_isabelle_matrix_entailment",
|
|
129
|
+
"to_thf_so", "to_isabelle_so",
|
|
130
|
+
"to_thf_to", "to_isabelle_to",
|
|
131
|
+
"to_thf_ho_modal", "to_isabelle_ho_modal", "isabelle_ho_modal_theory",
|
|
132
|
+
"ho_modal_definitions", "HoAxiom", "HoGoal", "UnsupportedHigherOrderNode",
|
|
133
|
+
"gmt_translate", "to_thf_intuitionistic", "to_isabelle_intuitionistic",
|
|
134
|
+
"gmt_is_s4_valid", "gmt_validity_matches_int_valid",
|
|
135
|
+
"modal_faithfulness_theory", "modal_to_deep",
|
|
136
|
+
"intuitionistic_faithfulness_theory", "int_to_deep",
|
|
137
|
+
"conditional_faithfulness_theory", "counterfactual_to_deep",
|
|
138
|
+
"relevant_faithfulness_theory", "rel_to_deep",
|
|
139
|
+
"qml_deep_faithfulness_theory", "qml_to_deep",
|
|
140
|
+
]
|