from pathlib import Path
from typing import Dict, List


class CorpusBuilder:
    """
    Writes raw corpus content to text files.
    """

    def __init__(self, output_dir: str = "corpus_raw"):
        self.output_dir = Path(output_dir)
        self.output_dir.mkdir(parents=True, exist_ok=True)

    def save(self, raw_corpus: Dict[str, List[dict]]) -> None:
        for category, docs in raw_corpus.items():
            path = self.output_dir / f"{category}.txt"
            with path.open("w", encoding="utf-8") as f:
                for d in docs:
                    f.write(d["content"].strip() + "\n")
