Files
ingglish-hyperdope-ci/tools/normalize_caps.py
T
Hermes Agent 94f46d436e feat(db): provision verified Ingglish phonetic lexicon and AQ attractor corpus
- Provision 872 verified Ingglish phonetic entries (253 Tier-1 lexicon/bridge
  items + 619 Tier-2 multi-scale 333/666/777/Numogram equations) formatted
  with native `[Ingglish: <English Gloss>]` comment brackets.
- Guard short Ingglish syllables (`di`, `li`, `mi`, `vi`, `iv`) against Roman-numeral
  false positives in `tools/normalize_caps.py`.
- Add newcomer onboarding documentation (`docs/ONBOARDING-INGGLISH-AQ.md`).
- Bump `databaseVersion` in `config.default.js` to cache-bust precomputed JSON.
- Verified 100% pass rate across all 4 CI gates (0 normalize mutations,
  100.0% classify_candidates keep rate, 0 comment-strip/AQ mismatches).
2026-11-03 06:13:06 +00:00

69 lines
1.9 KiB
Python

#!/usr/bin/env python3
"""Upstream-compatible tools/normalize_caps.py for hyperdope-gematria."""
import re
import sys
from pathlib import Path
ROMAN = re.compile(r"M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})", re.I)
def load_dict():
for p in ("/usr/share/dict/words", "/etc/dictionaries-common/words"):
if Path(p).exists():
return {w.strip().lower() for w in Path(p).read_text(encoding="utf-8", errors="ignore").splitlines() if w.strip()}
return set()
DICT = load_dict()
INGGLISH_NON_ROMAN = {"di", "li", "mi", "vi", "iv", "ci", "xi"}
def is_roman(s):
return bool(s) and s.lower() not in INGGLISH_NON_ROMAN and ROMAN.fullmatch(s) is not None
def xform_word(w):
if any(c.isdigit() for c in w) or "[" in w or "]" in w:
return w
letters = re.sub(r"[^A-Za-z]", "", w)
if not letters:
return w
if w != w.lower() and w != w.upper() and not (w[0].isupper() and w[1:] == w[1:].lower()):
return w
if w == w.upper() and len(letters) >= 2:
return w
if len(letters) >= 2 and is_roman(letters) and letters.lower() not in DICT:
return w.upper()
return w[:1].upper() + w[1:].lower()
def xform_line(line):
return " ".join(xform_word(w) for w in line.split())
def main():
if len(sys.argv) < 3:
sys.exit(0)
in_path, out_path = Path(sys.argv[1]), Path(sys.argv[2])
raw_lines = in_path.read_text(encoding="utf-8").splitlines()
header = raw_lines[0] if raw_lines and "GEMATRO" in raw_lines[0].upper() else "CREATE_GEMATRO_DB"
seen = set()
body = []
for line in raw_lines[1:]:
s = line.strip()
if not s:
continue
norm = xform_line(s)
key = norm.lower()
if key not in seen:
seen.add(key)
body.append(norm)
body.sort(key=lambda x: x.lower())
out_path.write_text("\n".join([header] + body) + "\n", encoding="utf-8")
if __name__ == "__main__":
main()