Download scripts/ground_imami_6_74.py from bravesigma/quran-md-data: direct link, hf CLI and curl.
- Browser
- Download file 6.03 kB
-
https://huggingface.co/datasets/bravesigma/quran-md-data/resolve/main/scripts/ground_imami_6_74.py
- Command line
-
hf download hf://datasets/bravesigma/quran-md-data/scripts/ground_imami_6_74.py
-
curl -L -o ground_imami_6_74.py https://huggingface.co/datasets/bravesigma/quran-md-data/resolve/main/scripts/ground_imami_6_74.py
6.03 kB
| #!/usr/bin/env python3 | |
| """Ground pos_6_74_imami_ab_uncle with a verified Majma' al-Bayan citation. | |
| The v2 substrate (raw/sources/tafsir_majma_albayan/text/6-074.txt) contains | |
| Tabrisi's main-text statement that al-Zajjaj's reading strengthens "what our | |
| associates (as'habana) say": Azar was Ibrahim's maternal grandfather or his | |
| uncle, since the school holds all the Prophet's ancestors up to Adam were | |
| monotheists. This grounds the Imami position record with real stored text. | |
| Honesty rules: | |
| - the citation is verbatim (asserted against the substrate before writing); | |
| - scope is explicit: only Majma' is grounded; Al-Mizan stays license-blocked | |
| and Tafsir al-Qummi stays untranscribed (blocked_sources kept); | |
| - no identity merging, no recall: quote_ar is located by folded matching and | |
| copied byte-for-byte from the stored file, sha256 recorded. | |
| """ | |
| import json | |
| import sys | |
| from hashlib import sha256 | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(ROOT / "scripts")) | |
| from locate_folded import fold_with_map # noqa: E402 | |
| SEG = ROOT / "raw" / "sources" / "tafsir_majma_albayan" / "text" / "6-074.txt" | |
| POS_FILE = ROOT / "raw" / "006-074.json" | |
| NEEDLE_FOLDED = ("و هذا الذي قال الزجاج يقوي ما قاله اصحابنا ان ازر كان جد " | |
| "ابراهيم لامه او كان عمه من حيث صح عندهم ان اباء النبي الي " | |
| "ادم كلهم كانوا موحدين و اجتمعت الطائفة علي ذلك") | |
| TRANSLATION_EN = ( | |
| "This — what al-Zajjaj said — strengthens what our associates (as'habana, " | |
| "the Imami school) say: that Azar was Ibrahim's maternal grandfather or " | |
| "was his uncle, given that it is established with them that all the " | |
| "fathers of the Prophet up to Adam were monotheists, and the community " | |
| "agreed on that." | |
| ) | |
| def locate_verbatim(raw: str, needle_folded: str) -> str: | |
| folded, imap = fold_with_map(raw) | |
| nf = fold_with_map(needle_folded)[0] | |
| j = folded.find(nf) | |
| if j < 0: | |
| raise SystemExit("needle not found in folded substrate") | |
| lo = imap[j] | |
| hi = imap[j + len(nf) - 1] + 1 | |
| while lo > 0 and not raw[lo - 1].isspace(): | |
| lo -= 1 | |
| while hi < len(raw) and not raw[hi].isspace(): | |
| hi += 1 | |
| return raw[lo:hi] | |
| def main(): | |
| raw = SEG.read_text(encoding="utf-8") | |
| quote = locate_verbatim(raw, NEEDLE_FOLDED) | |
| assert quote in raw, "verbatim-or-fail: quote is not a raw substring" | |
| sha = sha256(SEG.read_bytes()).hexdigest() | |
| doc = json.loads(POS_FILE.read_text(encoding="utf-8")) | |
| pos = None | |
| for p in doc.get("positions", []): | |
| if p.get("id") == "pos_6_74_imami_ab_uncle": | |
| pos = p | |
| break | |
| if pos is None: | |
| raise SystemExit("position pos_6_74_imami_ab_uncle not found") | |
| pos["claim"] = ( | |
| "Imami tafsir holds 'ab' in 6:74 may denote uncle (and specifically " | |
| "that Azar was Ibrahim's maternal grandfather or his uncle), citing " | |
| "internal Quranic usage of 'ab' (2:133) and the principle that all " | |
| "ancestors of the Prophet up to Adam were monotheists. GROUNDED from " | |
| "stored text: Majma' al-Bayan (Tabrisi) states that al-Zajjaj's " | |
| "reading strengthens what the Imami school (as'habana) says. The " | |
| "broader attribution to Al-Mizan and Tafsir al-Qummi remains pending " | |
| "their ingestion." | |
| ) | |
| pos["claim_type"] = "empirical_historical" | |
| pos["consensus_level"] = "majority" | |
| pos["verification"] = "verified" | |
| pos["grounding"] = { | |
| "grounded_from_stored_text": ["tafsir_majma_albayan"], | |
| "pending": [ | |
| "tafsir_al_mizan (license-blocked, exclude_until_resolved)", | |
| "tafsir_al_qummi (not yet transcribed)", | |
| ], | |
| "note": "citation verified verbatim against stored v2 substrate " | |
| "(td#book-page-content extraction); scope limited to Majma'", | |
| } | |
| pos["citations"] = [{ | |
| "quote_ar": quote, | |
| "translation_en": TRANSLATION_EN, | |
| "work": "tafsir_majma_albayan", | |
| "commentary_unit_id": "cu_tafsir_majma_albayan_6_74", | |
| "source_id": "raw/sources/tafsir_majma_albayan/text/6-074.txt", | |
| "source_sha256": sha, | |
| "note": "Tabrisi main-text discussion; 'as'habana' = the Imami " | |
| "school; located by folded matching, copied byte-for-byte", | |
| }] | |
| pos["blocked_sources"] = [ | |
| "tafsir_al_mizan (license)", | |
| "tafsir_al_qummi (no clean digital source)", | |
| ] | |
| # fix the legacy summary line: the grounded text says maternal | |
| # grandfather OR uncle — not "paternal uncle" | |
| shia = doc.get("shia_perspectives", {}) | |
| if "tafsir_summary" in shia: | |
| shia["tafsir_summary"] = ( | |
| "Shia exegetes (Tabataba'i in Al-Mizan — license-blocked, still " | |
| "unverified; Tabrisi in Majma' al-Bayan — ingested, verbatim " | |
| "grounded) hold that Azar was Ibrahim's maternal grandfather or " | |
| "his uncle, not his biological father, citing internal Quranic " | |
| "usage of 'ab' (2:133) and the theological principle that all " | |
| "direct ancestors of Prophets were monotheists." | |
| ) | |
| POS_FILE.write_text(json.dumps(doc, ensure_ascii=False, indent=2) + "\n", | |
| encoding="utf-8") | |
| print("position grounded; quote chars:", len(quote)) | |
| print("sha256(6-074.txt):", sha[:12], "…") | |
| # self-check: reread and re-verify | |
| doc2 = json.loads(POS_FILE.read_text(encoding="utf-8")) | |
| c = [p for p in doc2["positions"] | |
| if p["id"] == "pos_6_74_imami_ab_uncle"][0]["citations"][0] | |
| seg2 = (ROOT / c["source_id"]).read_text(encoding="utf-8") | |
| assert c["quote_ar"] in seg2, "post-write verbatim check FAILED" | |
| assert c["source_sha256"] == sha256((ROOT / c["source_id"]).read_bytes()).hexdigest() | |
| print("post-write verbatim + sha256 checks: PASS") | |
| if __name__ == "__main__": | |
| main() | |