feat(zoology): upgrade to v1.3.0 with tri-modal --quant-mode {off,spoken,digit,dual}, --scan-harvest sidecar, and quant_free_lexical_equations

This commit is contained in:
Hermes Agent committed 2026-11-28 21:03:01 +00:00
1 parent 568dfb3dec
commit 7b4e2f8647
2 files changed
+260 -3

No files matched your search

+220 -2
View File
@@ -569,6 +569,7 @@ def revise_economic_anchor(
"entity": target_anchor["entity"],
"metric": target_anchor["metric"],
"source_dossier": target_anchor["source_dossier"],
"quant_free_lexical_equations": target_anchor.get("quant_free_lexical_equations", []),
"path_c_dual_mode_comparison": {
"digit_mode": {
"q_old": old_digit,
@@ -615,9 +616,190 @@ DEFAULT_CORPUS = [
]
_ONES = [
"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine",
"ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen",
"seventeen", "eighteen", "nineteen",
]
_TENS = ["", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
_UNIT_WORDS = {
"tn": "trillion", "trillion": "trillion",
"bn": "billion", "b": "billion", "billion": "billion",
"m": "million", "mn": "million", "million": "million",
"k": "thousand", "thousand": "thousand",
"%": "percent",
}
def _int_to_words(n: int) -> str:
if n < 0:
return "minus " + _int_to_words(-n)
if n < 20:
return _ONES[n]
if n < 100:
t, r = divmod(n, 10)
return _TENS[t] + ("" if r == 0 else " " + _ONES[r])
if n < 1000:
h, r = divmod(n, 100)
return _ONES[h] + " hundred" + ("" if r == 0 else " " + _int_to_words(r))
for scale_val, scale_name in ((1_000_000_000_000, "trillion"), (1_000_000_000, "billion"), (1_000_000, "million"), (1000, "thousand")):
if n >= scale_val:
q, r = divmod(n, scale_val)
return _int_to_words(q) + " " + scale_name + ("" if r == 0 else " " + _int_to_words(r))
return str(n)
def token_to_spoken_english(raw_tok: str) -> str:
import re
s = raw_tok.strip()
m = re.match(r"^([$€£])?(\d[\d,]*)(?:\.(\d+))?([a-zA-Z%]+)?$", s)
if not m:
return s.lower()
_curr, int_part, dec_part, unit_part = m.groups()
int_val = int(int_part.replace(",", ""))
words = [_int_to_words(int_val)]
if dec_part:
words.append("point")
for ch in dec_part:
words.append(_ONES[int(ch)])
if unit_part:
u_low = unit_part.lower()
if u_low in _UNIT_WORDS:
words.append(_UNIT_WORDS[u_low])
else:
words.append(u_low)
return " ".join(words)
def scan_harvest_for_revisions(
harvest_path: str,
anchors_path: str,
base_report: dict[str, Any],
quant_mode: str = "dual",
workdir: str = "/workspace/ingglish-hyperdope-gematria",
) -> dict[str, Any]:
"""
Non-destructively scan a `news-aq-harvest-*.json` file:
- If `quant_mode == 'off'`, returns only the pure lexical classification of the harvest's `entities`.
- Otherwise, extracts quantitative figures from `quantitative_anchors` (or directly from `headlines`
if `quantitative_anchors` is absent in older harvest files), compares them against tracked
entities in `quantitative-economic-anchors.json`, and automatically fires `revise_economic_anchor()`
whenever a figure has mutated.
"""
import re
harvest = json.loads(Path(harvest_path).read_text(encoding="utf-8"))
anchors_data = json.loads(Path(anchors_path).read_text(encoding="utf-8"))
tracked_anchors = anchors_data.get("anchors", [])
if quant_mode == "off":
return {
"quant_mode": "off",
"note": "Quantitative stream disabled (--quant-mode off); returning pure lexical entity classification only.",
"lexical_entity_count": len(harvest.get("entities", [])),
}
quant_items = harvest.get("quantitative_anchors")
if quant_items is None:
quant_items = []
quant_re = re.compile(r"(?<![a-zA-Z0-9])([$€£]?\d[\d,]*(?:\.\d+)?(?:tn|bn|mn|b|m|k|%)?)\b", re.I)
for idx, h in enumerate(harvest.get("headlines", [])):
hl = h.get("headline_eng", "")
for qm in quant_re.finditer(hl):
q_tok = qm.group(1)
if q_tok in {"2025", "2026", "2027"}:
continue
sp_eng = token_to_spoken_english(q_tok)
quant_items.append(
{
"story": f"H{idx+1:02d}:{h.get('source', '')}",
"entity_context": hl[:40],
"q_digit": q_tok,
"q_spoken_eng": sp_eng,
"headline": hl,
}
)
unchanged_matches = []
detected_revisions = []
new_candidate_anchors = []
for qi in quant_items:
hl_low = qi.get("headline", "").lower()
q_dig = qi["q_digit"]
q_sp_eng = qi["q_spoken_eng"]
matched_tracked = None
for ta in tracked_anchors:
kws = ta.get("entity_match_keywords", [ta["entity"].lower()])
if any(kw in hl_low for kw in kws):
matched_tracked = ta
break
if matched_tracked:
if q_dig.lower() == matched_tracked["q_digit"].lower():
unchanged_matches.append(
{
"anchor_id": matched_tracked["anchor_id"],
"entity": matched_tracked["entity"],
"q_digit": q_dig,
"status": "unchanged",
"headline": qi.get("headline"),
}
)
else:
rev = revise_economic_anchor(
anchor_id=matched_tracked["anchor_id"],
new_digit=q_dig,
new_spoken_eng=q_sp_eng,
anchors_path=anchors_path,
base_report=base_report,
workdir=workdir,
)
rev["trigger_headline"] = qi.get("headline")
detected_revisions.append(rev)
else:
# Check if headline touches any S1-S6 technocapital keyword
matched_classes = []
for cid, cinfo in TAXONOMY_CLASSES.items():
if any(kw in hl_low for kw in cinfo["keywords"]):
matched_classes.append(cid)
if matched_classes:
new_candidate_anchors.append(
{
"story": qi.get("story"),
"q_digit": q_dig,
"q_digit_aq": compute_aq(q_dig),
"q_spoken_eng": q_sp_eng,
"taxonomy_classes": matched_classes,
"headline": qi.get("headline"),
}
)
return {
"quant_mode": quant_mode,
"harvest_file": harvest_path,
"target_date_utc": harvest.get("temporal_metadata", {}).get("target_date_utc"),
"counts": {
"quantitative_tokens_scanned": len(quant_items),
"tracked_anchors_unchanged": len(unchanged_matches),
"tracked_anchors_revised": len(detected_revisions),
"new_technocapital_quant_candidates": len(new_candidate_anchors),
},
"unchanged_tracked_anchors": unchanged_matches,
"detected_revisions": detected_revisions,
"new_technocapital_quant_candidates": new_candidate_anchors[:15],
}
def main() -> int:
import re
ap = argparse.ArgumentParser(description="Identify, taxonomize, and revise Landian-Deleuzean technocapital singularities (S1-S6).")
ap.add_argument("--terms", nargs="*", help="Custom list of terms to analyze (defaults to canonical S1-S6 corpus).")
ap.add_argument(
"--quant-mode",
choices=["off", "spoken", "digit", "dual"],
default="off",
help="Tri-modal quantitative handling: 'off' (default pure lexical), 'spoken' (numbers translated to Ingglish words), 'digit' (literal 0-9), 'dual' (both).",
)
ap.add_argument("--workdir", default="/workspace/ingglish-hyperdope-gematria", help="Path to repo containing node_modules/ingglish.")
ap.add_argument(
"--anchors-file",
@@ -630,11 +812,37 @@ def main() -> int:
metavar=("ANCHOR_ID", "NEW_DIGIT", "NEW_SPOKEN_ENG"),
help="Evaluate a quantitative economic anchor revision and surface alternative 333/666/777 equations.",
)
ap.add_argument(
"--scan-harvest",
default=None,
help="Optional path to news-aq-harvest-latest.json to scan for quantitative revisions and new S1-S6 anchors.",
)
ap.add_argument("--out", default=None, help="Optional JSON output file path.")
args = ap.parse_args()
terms = args.terms if args.terms else DEFAULT_CORPUS
report = analyze_terms(terms, workdir=args.workdir)
raw_terms = args.terms if args.terms else DEFAULT_CORPUS
processed_terms = []
for t in raw_terms:
if args.quant_mode == "off":
# Strip full quantitative tokens (including attached units like $6B, $1.5tn, 481) in pure lexical mode
clean_t = re.sub(r"(?<![a-zA-Z0-9])[$€£]?\d[\d,]*(?:\.\d+)?(?:tn|bn|mn|b|m|k|%)?\b", "", t, flags=re.I)
clean_t = re.sub(r"\s+", " ", clean_t).strip()
if clean_t:
processed_terms.append(clean_t)
elif args.quant_mode == "spoken":
# Convert any numeric tokens to spoken English words before Ingglish translation
converted = re.sub(
r"(?<![a-zA-Z0-9])([$€£]?\d[\d,]*(?:\.\d+)?(?:tn|bn|mn|b|m|k|%)?)\b",
lambda m: token_to_spoken_english(m.group(1)),
t,
flags=re.I,
)
processed_terms.append(converted)
else:
processed_terms.append(t)
report = analyze_terms(processed_terms, workdir=args.workdir)
report["quant_mode"] = args.quant_mode
if args.revise_anchor:
anchor_id, new_digit, new_spoken_eng = args.revise_anchor
@@ -647,6 +855,16 @@ def main() -> int:
workdir=args.workdir,
)
out_str = json.dumps(rev_report, indent=2, ensure_ascii=False)
elif args.scan_harvest:
eff_mode = "dual" if args.quant_mode == "off" else args.quant_mode
scan_res = scan_harvest_for_revisions(
harvest_path=args.scan_harvest,
anchors_path=args.anchors_file,
base_report=report,
quant_mode=eff_mode,
workdir=args.workdir,
)
out_str = json.dumps(scan_res, indent=2, ensure_ascii=False)
else:
out_str = json.dumps(report, indent=2, ensure_ascii=False)