File size: 4,430 Bytes
5f0f37c | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #!/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()
|