Download scripts/data_ingestion/00_fetch_external_data.py from RaiyanKhaan/Beyond-Chunking: direct link, hf CLI and curl.
- Browser
- Download file 4.43 kB
-
https://huggingface.co/datasets/RaiyanKhaan/Beyond-Chunking/resolve/main/scripts/data_ingestion/00_fetch_external_data.py
- Command line
-
hf download hf://datasets/RaiyanKhaan/Beyond-Chunking/scripts/data_ingestion/00_fetch_external_data.py
-
curl -L -o 00_fetch_external_data.py https://huggingface.co/datasets/RaiyanKhaan/Beyond-Chunking/resolve/main/scripts/data_ingestion/00_fetch_external_data.py
4.43 kB
| #!/usr/bin/env python3 | |
| """ | |
| 00_fetch_external_data.py | |
| Documents, verifies, and validates the external provenance and availability of upstream | |
| datasets used across Agriculture, Legal, and Education benchmarks. | |
| Usage: | |
| python 00_fetch_external_data.py [--check_remote] | |
| """ | |
| import os | |
| import sys | |
| import json | |
| import hashlib | |
| import argparse | |
| from pathlib import Path | |
| if hasattr(sys.stdout, "reconfigure"): | |
| sys.stdout.reconfigure(encoding="utf-8", errors="replace") | |
| # Base paths | |
| SCRIPT_DIR = Path(__file__).resolve().parent | |
| REPO_ROOT = SCRIPT_DIR.parent.parent.parent | |
| DEFAULT_DATA_DIR = REPO_ROOT / "reproducibility" / "dataset" | |
| SOURCES = [ | |
| { | |
| "domain": "agriculture", | |
| "name": "Agricultural Information Service (AIS) / DAE & KrishokChat", | |
| "source_type": "Advisory Handbooks & Curated Extension Resources", | |
| "url": "https://krishok.gov.bd / ais.gov.bd", | |
| "license": "Research Access / CC-BY-4.0", | |
| "local_check_file": "processed/agriculture/structured_nodes.json", | |
| "expected_items": 1028 | |
| }, | |
| { | |
| "domain": "legal", | |
| "name": "Bangladesh Legal Acts Dataset & BDLawCorpus", | |
| "source_type": "Hugging Face Dataset (sakhadib/Bangladesh-Legal-Acts-Dataset, millat/BDLawCorpus-Dataset-V1)", | |
| "url": "https://huggingface.co/datasets/sakhadib/Bangladesh-Legal-Acts-Dataset", | |
| "license": "MIT / CC-BY-4.0", | |
| "local_check_file": "processed/legal/structured_nodes.json", | |
| "expected_items": 735 | |
| }, | |
| { | |
| "domain": "education", | |
| "name": "NCTB Secondary Science Curriculum Textbooks (Grades 9-10)", | |
| "source_type": "National Curriculum and Textbook Board Bangladesh", | |
| "url": "https://nctb.gov.bd", | |
| "license": "Public Curriculum / CC-BY-4.0 (derived QA annotations)", | |
| "local_check_file": "processed/education/structured_nodes.json", | |
| "expected_items": 190 | |
| } | |
| ] | |
| def verify_dataset_presence(data_dir: Path) -> bool: | |
| print("=" * 70) | |
| print("00_FETCH_EXTERNAL_DATA: Verifying Data Provenance and Local Artifacts") | |
| print("=" * 70) | |
| all_ok = True | |
| manifest_path = data_dir / "manifest.json" | |
| if manifest_path.exists(): | |
| with open(manifest_path, "r", encoding="utf-8") as f: | |
| manifest = json.load(f) | |
| print(f"[OK] Found dataset manifest: {manifest_path} ({len(manifest.get('files', {}))} registered files)") | |
| else: | |
| print(f"[WARN] manifest.json not found at {manifest_path}") | |
| for src in SOURCES: | |
| rel_path = src["local_check_file"] | |
| full_path = data_dir / rel_path | |
| print(f"\nChecking source: {src['name']} ({src['domain'].upper()})") | |
| print(f" - Source URL: {src['url']}") | |
| print(f" - License: {src['license']}") | |
| if full_path.exists(): | |
| size_mb = full_path.stat().st_size / (1024 * 1024) | |
| with open(full_path, "r", encoding="utf-8") as fp: | |
| data = json.load(fp) | |
| item_count = len(data) if isinstance(data, list) else 0 | |
| if item_count == src["expected_items"]: | |
| print(f" - Status: [VERIFIED LOCAL] ({item_count} items, {size_mb:.2f} MB)") | |
| else: | |
| print(f" - Status: [COUNT MISMATCH] Expected {src['expected_items']}, got {item_count}") | |
| all_ok = False | |
| else: | |
| print(f" - Status: [MISSING] File not found at {full_path}") | |
| all_ok = False | |
| print("\n" + "=" * 70) | |
| if all_ok: | |
| print("EXTERNAL DATA PROVENANCE AUDIT: ALL LOCAL ARTIFACTS VERIFIED") | |
| else: | |
| print("EXTERNAL DATA PROVENANCE AUDIT: INCOMPLETE (Some files missing)") | |
| print("=" * 70) | |
| return all_ok | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Verify external dataset sources and local presence.") | |
| parser.add_argument("--data_dir", type=str, default=str(DEFAULT_DATA_DIR), help="Path to reproducibility/dataset folder") | |
| parser.add_argument("--check_remote", action="store_true", help="Check remote HTTP connectivity to repositories") | |
| args = parser.parse_args() | |
| data_dir = Path(args.data_dir).resolve() | |
| if not data_dir.exists(): | |
| print(f"Error: Data directory does not exist: {data_dir}", file=sys.stderr) | |
| sys.exit(1) | |
| success = verify_dataset_presence(data_dir) | |
| sys.exit(0 if success else 1) | |
| if __name__ == "__main__": | |
| main() | |