Download scripts/register_qummi_source.py from bravesigma/quran-md-data: direct link, hf CLI and curl.
- Browser
- Download file 11.9 kB
-
https://huggingface.co/datasets/bravesigma/quran-md-data/resolve/main/scripts/register_qummi_source.py
- Command line
-
hf download hf://datasets/bravesigma/quran-md-data/scripts/register_qummi_source.py
-
curl -L -o register_qummi_source.py https://huggingface.co/datasets/bravesigma/quran-md-data/resolve/main/scripts/register_qummi_source.py
11.9 kB
| #!/usr/bin/env python3 | |
| """ | |
| Register the acquired state of tafsir_al_qummi in sources/manifest.json | |
| (replace the pre-acquisition stub) and append the audit addendum + | |
| permission-request draft. | |
| Idempotent: markers prevent duplicate appends; manifest replacement is | |
| in-place by source id. | |
| """ | |
| import json | |
| from hashlib import sha256 | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent.parent | |
| MANIFEST = ROOT / "sources" / "manifest.json" | |
| AUDIT = ROOT / "docs" / "LICENSE_AUDIT.md" | |
| REQ = ROOT / "docs" / "PERMISSION_REQUESTS.md" | |
| REPORT = ROOT / "raw" / "sources" / "tafsir_al_qummi" / "extraction_report.json" | |
| AUDIT_MARK = "<!-- qummi-addendum-2026-11-27 -->" | |
| REQ_MARK = "<!-- qummi-permission-2026-11-27 -->" | |
| ENTRY = { | |
| "id": "tafsir_al_qummi", | |
| "category": "tafsir", | |
| "traditions": ["imami"], | |
| "title_ar": "تفسير القمي", | |
| "title_en": "Tafsir al-Qummi (attributed)", | |
| "author": "attributed to Ali ibn Ibrahim al-Qummi (d. 307/329 AH)", | |
| "author_death": "307 or 329 AH / 919-940 CE", | |
| "work_class": "classical", | |
| "license": { | |
| "value": "public_domain_underlying_text_transcription_hosted", | |
| "verified": "legal_analysis", | |
| "evidence_urls": [ | |
| "https://ar.lib.eshia.ir/12015", | |
| "https://sites.dlib.nyu.edu/viewer/books/nyu_aco000157/1", | |
| ], | |
| "summary": ( | |
| "Underlying classical text is public domain (author d. 307/329 AH; attribution is by " | |
| "transmission — a data-quality matter handled by Phase 4 flags, not a license matter). " | |
| "Digital transcription acquired from ar.lib.eshia.ir (Maktabat Madrasat al-Fiqahah, book " | |
| "12015, Najaf: Maktabat al-Huda 1387 AH / 1967 edition, ed. Sayyid Tayyib al-Musawi " | |
| "al-Jaza'iri), a free-access Islamic digital library. Pages inspected 2026-11-27 show NO " | |
| "terms forbidding scholarly extraction, but no explicit license is granted either, so the " | |
| "modern digital transcription is taken as use_with_notice with attribution, a permission " | |
| "request (docs/PERMISSION_REQUESTS.md) and a removal pledge. The host's AI-assist features " | |
| "(auto-i'rab, translation widgets) were NOT used; only the page text itself was stored." | |
| ), | |
| }, | |
| "redistribution": { | |
| "huggingface": "allowed_with_attribution", | |
| "basis": ( | |
| "Public-domain classical Arabic text as transcribed on ar.lib.eshia.ir; host credited in " | |
| "every unit's provenance and in DATASET_CARD; removal on rights-holder request." | |
| ), | |
| }, | |
| "access": { | |
| "method": "programmatic_page_fetch", | |
| "urls": [ | |
| "https://ar.lib.eshia.ir/12015/1/28", | |
| "https://ar.lib.eshia.ir/12015/1/30", | |
| "https://ar.lib.eshia.ir/12015/1/205", | |
| "https://ar.lib.eshia.ir/12015/1/290", | |
| "https://ar.lib.eshia.ir/12015/1/371", | |
| "https://ar.lib.eshia.ir/12015/2/48", | |
| "https://ar.lib.eshia.ir/12015/2/361", | |
| ], | |
| "terms_verified": False, | |
| "rate_or_key": "0.65 s per page, UA quran-md-research/0.1, no key required", | |
| "notes": ( | |
| "Vol 1 = surahs 1-16 (content pages 3-396), vol 2 = surahs 17-114 (content pages 3-452); " | |
| "eshia serves the edition's complete pericope TOC as out-of-range digital pages " | |
| "(vol 1 -> p.400, vol 2 -> p.457); that TOC maps [surah(n): verse-range] -> printed page " | |
| "and all fetch spans were derived from it (raw/sources/tafsir_al_qummi/fetch_plan.json). " | |
| "Pages stored per page with sha256 (extraction_report.json). Substrate normalization: " | |
| "bidi/ZWNJ control chars removed, whitespace collapsed; diacritics kept verbatim. Anchoring: " | |
| "bracketed quotes or longest consecutive word-run under a nospace fold (the Najaf edition " | |
| "interleaves Qummi's own word-glosses between verse phrases, so full-verse contiguity is " | |
| "impossible by design); hamza-loose second pass and whole-word opener pass are method-flagged " | |
| "per unit. Verses with no anchor are NOT ingested (honest gap)." | |
| ), | |
| }, | |
| "format": ("Najaf: Maktabat al-Huda 1387 AH / 1967 (digital transcription on eshia), 2 vols; " | |
| "per-page HTML files + per-surah/per-verse text substrates"), | |
| "provenance_plan": { | |
| "recorded_fields": [ | |
| "source_id", "edition", "volume", "page", "sha256", "char_offsets", "retrieval_url", | |
| "retrieval_date", | |
| ], | |
| "retrieval_url": "https://ar.lib.eshia.ir/12015", | |
| "retrieval_date": "2026-11-27", | |
| "sha256": None, | |
| }, | |
| "planned_use": [ | |
| "earliest-layer Imami tafsir side-by-side with Majma' al-Bayan and the Sunni trio", | |
| "compare_traditions plugin output", | |
| "exegetical xref edges with citing_mufassir=tafsir_al_qummi", | |
| ], | |
| "flags": [ | |
| "use_with_notice: host (ar.lib.eshia.ir) grants no explicit license; permission requested, " | |
| "removal pledged (NOTICE.md 3b)", | |
| "inline Najaf edition footnote text/markers are retained inside flagged segments " | |
| "(attribution_flags on every unit) and never presented as al-Qummi's own words", | |
| "attribution is by transmission (student transmission, not autograph) - data-quality note " | |
| "carried on every unit", | |
| ], | |
| "proposed_state": "use_with_notice", | |
| "blocking_issues": [ | |
| "eshia explicit permission pending (letter drafted in docs/PERMISSION_REQUESTS.md)", | |
| "Najaf edition inline footnote text/markers are not separable in the eshia HTML; they remain " | |
| "in the substrate and are flagged per commentary unit (attribution_flags)", | |
| "verses whose discussion carries no directly matchable anchor are not ingested; skip list " | |
| "preserved in extraction_report.json (uncovered_verses + per-verse flags)", | |
| "citations of short ayahs (< 12 folded chars) are undetectable in plain text (same documented " | |
| "detection limit as the other works)", | |
| ], | |
| } | |
| def main(): | |
| report_sha = sha256(REPORT.read_bytes()).hexdigest() | |
| ENTRY["provenance_plan"]["sha256"] = report_sha | |
| m = json.loads(MANIFEST.read_text(encoding="utf-8")) | |
| idx = next((i for i, x in enumerate(m["sources"]) if x["id"] == ENTRY["id"]), None) | |
| if idx is None: | |
| m["sources"].append(ENTRY) | |
| print(f"manifest: {ENTRY['id']} added (total sources {len(m['sources'])})") | |
| else: | |
| old_state = m["sources"][idx].get("proposed_state") | |
| m["sources"][idx] = ENTRY | |
| print(f"manifest: {ENTRY['id']} replaced in place " | |
| f"(proposed_state {old_state!r} -> {ENTRY['proposed_state']!r}; " | |
| f"total sources {len(m['sources'])})") | |
| # reconcile stored summary_counts with the new per-source states | |
| counts = {"use": 0, "use_with_notice": 0, "exclude_until_resolved": 0, "exclude_entirely": 0} | |
| for s in m["sources"]: | |
| counts[s["proposed_state"]] += 1 | |
| m["summary_counts"] = { | |
| "total_sources": len(m["sources"]), | |
| "proposed_use": counts["use"], | |
| "proposed_use_with_notice": counts["use_with_notice"], | |
| "exclude_until_resolved": counts["exclude_until_resolved"], | |
| "exclude_entirely": counts["exclude_entirely"], | |
| "note": ("proposed_use counts plain 'use' only; 'use_with_notice' is counted " | |
| "separately (see per-source proposed_state)"), | |
| } | |
| print(f"manifest: summary_counts reconciled -> use={counts['use']}, " | |
| f"use_with_notice={counts['use_with_notice']}, " | |
| f"exclude_until_resolved={counts['exclude_until_resolved']}, " | |
| f"exclude_entirely={counts['exclude_entirely']}") | |
| MANIFEST.write_text(json.dumps(m, ensure_ascii=False, indent=1) + "\n", encoding="utf-8") | |
| audit_add = AUDIT_MARK + """ | |
| ## Addendum 2026-11-27 — Tafsir al-Qummi (Imami) acquisition | |
| - Work: Tafsir al-Qummi, attributed to Ali ibn Ibrahim al-Qummi (d. 307 AH / 919-920 CE; 329 AH per | |
| some biographers). The classical Arabic original is public domain by duration everywhere; the | |
| attribution is by transmission (student transmission, not autograph) — a data-quality matter already | |
| handled by Phase 4 attribution flags, not a license matter. | |
| - Acquisition channel: ar.lib.eshia.ir book 12015 (Najaf: Maktabat al-Huda 1387 AH / 1967, ed. Sayyid | |
| Tayyib al-Musawi al-Jaza'iri), free-access Islamic library — the same host already classified | |
| use_with_notice for Majma' al-Bayan (addendum above). Pages inspected 2026-11-27: no terms forbidding | |
| scholarly extraction, no explicit license granted. Classification: use_with_notice; permission letter | |
| drafted; removal pledge recorded. | |
| - Resolution of the open item in the Majma' addendum above ("no machine-usable transcription located | |
| yet"): FOUND on the same host, book 12015. | |
| - Text integrity: per-page HTML stored with sha256; substrate = normalized page text (bidi/ZWNJ removed, | |
| whitespace collapsed; diacritics kept); every commentary quote must be a verbatim substring of its | |
| stored per-verse file (G2). The host's AI widgets (translation/i'rab) were not used. | |
| - Detection method (no recall): page spans derived from the edition's own pericope TOC as served by the | |
| host; anchoring by bracketed quote, longest consecutive word-run under a nospace fold (the Najaf text | |
| interleaves Qummi's word-glosses between verse phrases), a hamza-loose second pass, and a whole-word | |
| pass for muqatta'ah-class openers — all method-flagged per unit. Verses with no anchor are NOT | |
| ingested; the skip list is preserved in raw/sources/tafsir_al_qummi/extraction_report.json. | |
| - Coverage outcome on the 192 ingested verses: 130 anchored units (surah yields: S1 5/7, S2 34/55, | |
| S6 17/17, S9 1/1, S14 1/1, S19 63/98, S60 9/13); 62 verses without a Qummi comment remain Sunni+Majma | |
| only and are listed in the report (honest gap). | |
| """ | |
| if AUDIT_MARK not in AUDIT.read_text(encoding="utf-8"): | |
| AUDIT.write_text(AUDIT.read_text(encoding="utf-8") + audit_add, encoding="utf-8") | |
| print("LICENSE_AUDIT.md: addendum appended") | |
| else: | |
| print("LICENSE_AUDIT.md: already appended") | |
| req_add = REQ_MARK + """ | |
| ### ar.lib.eshia.ir (Maktabat Madrasat al-Fiqahah) — Tafsir al-Qummi, Najaf: Maktabat al-Huda 1387/1967 edition (book 12015) | |
| To: the Madrasat al-Fiqahah library team (contact via eshia.ir) — extends the request above to a | |
| second work hosted in the same library. | |
| We (the quran.md project) have stored per-page Arabic text of Tafsir al-Qummi (attributed to Ali ibn | |
| Ibrahim al-Qummi, d. 307/329 AH), Najaf: Maktabat al-Huda 1387 AH / 1967 edition, as served by your | |
| library at ar.lib.eshia.ir/12015, for a non-profit scholarly dataset whose every quote is verified | |
| verbatim against the stored substrate and attributed to your library in every record (source field | |
| `retrieval_url`). | |
| The underlying work is a public-domain classical text. We found no terms on your site forbidding such | |
| extraction, but since no explicit license is stated either, we are asking for your explicit permission | |
| to keep and redistribute this transcription within an openly licensed research dataset. We commit to | |
| remove it promptly on your request and to keep your attribution regardless. | |
| Fetch profile: 63 pages on 2026-11-27 (plus the two TOC pages the host serves as out-of-range ids), | |
| 0.65 s between requests, generic research user-agent, no account/key bypass, no AI-derived paraphrase | |
| of your text (verbatim storage only). | |
| """ | |
| if REQ_MARK not in REQ.read_text(encoding="utf-8"): | |
| REQ.write_text(REQ.read_text(encoding="utf-8") + req_add, encoding="utf-8") | |
| print("PERMISSION_REQUESTS.md: draft appended") | |
| else: | |
| print("PERMISSION_REQUESTS.md: already appended") | |
| if __name__ == "__main__": | |
| main() | |