#!/usr/bin/env python3 """`python oracle7.py kernel ...` - the 11.5 kernel at its newest admitted version (v9). kernel "question" quantities through the kernel's parts (formula parts + learned specialist faces) kernel --head "question" the head as one of the kernel's parts too: any question the head answers, under both laws kernel faces what the kernel can read and give kernel --json ... the full reply with its receipts""" from __future__ import annotations import json import sys from pathlib import Path HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE)) def _head(): import importlib.util root = HERE.parents[1] spec = importlib.util.spec_from_file_location("o7", str(root / "oracle7.py")) o7 = importlib.util.module_from_spec(spec) argv, sys.argv = sys.argv, ["oracle7.py"] spec.loader.exec_module(o7) sys.argv = argv eng = o7.Engine() return lambda q, s: eng.chat(q, s) def cli(rest): as_json, use_head = "--json" in rest, "--head" in rest rest = [x for x in rest if x not in ("--json", "--head")] if not rest: print(__doc__) return 0 from kernel_v9 import Kernel9 k = Kernel9(head_chat=_head() if use_head else (lambda q, s: {"status": "declined"})) if rest[:1] == ["faces"]: print("declared faces (formula parts): %d over %d (quantity, dimension) keys" % (len(k.declared.parts), len(k.declared.keys))) print("induced faces (specialists, learned from their own worked examples): %d" % len(k.induced.faces)) return 0 r = k.solve(" ".join(rest)) if as_json: print(json.dumps(r, indent=1, default=str)) return 0 if r.get("status") == "answered": print(r["answer"]) path = r.get("path") or [t.get("node") for t in r.get("trace", []) if t.get("node")] print(" [answered, %s reading] path: %s" % (r.get("reading", "induced"), " -> ".join(map(str, path)) or "core arithmetic")) else: print("I can't answer that with a checked path: %s" % (r.get("reason") or "no path")) return 0 if __name__ == "__main__": sys.exit(cli(sys.argv[1:]))