Estarcode's picture
Upload folder using huggingface_hub
2ab2b76 verified
Raw History Blame Contribute Delete
1 kB
"""Raw document extractors for institutional PDF notices and CSV schedules."""
import csv
from pathlib import Path
from typing import Dict, List
import pandas as pd
import pymupdf
from src.config import ROOT_DIR, SOURCE_MANIFEST_PATH
def load_manifest_rows(manifest_path: Path = SOURCE_MANIFEST_PATH) -> List[Dict[str, str]]:
"""Load source provenance rows from source_manifest.csv."""
with manifest_path.open("r", encoding="utf-8", newline="") as f:
return list(csv.DictReader(f))
def extract_pdf_text(file_path: str) -> str:
"""Extract raw text from all pages of a PDF notice."""
pdf_path = ROOT_DIR / file_path
doc = pymupdf.open(pdf_path)
text = "\n".join(page.get_text("text") for page in doc)
doc.close()
return text
def extract_csv_rows(file_path: str) -> List[Dict[str, str]]:
"""Read structured fee/tier schedule rows from CSV."""
csv_path = ROOT_DIR / file_path
df = pd.read_csv(csv_path)
return df.to_dict(orient="records")