"""
Corpus Processor
================

Applies normalization, tokenization, and stemming
to a loaded raw corpus.
"""

from typing import Dict, List
from qubee_nlp.tokenizer import QubeeTokenizer
from qubee_nlp.normalizer import TextNormalizer
from qubee_nlp.stemmer import QubeeStemmer


class CorpusProcessor:
    def __init__(self):
        self.tokenizer = QubeeTokenizer()
        self.normalizer = TextNormalizer()
        self.stemmer = QubeeStemmer()

    def process(self, corpus: Dict[str, List[str]]) -> Dict[str, List[Dict]]:
        processed: Dict[str, List[Dict]] = {}

        for category, documents in corpus.items():
            processed[category] = []

            for text in documents:
                normalized = self.normalizer.normalize(text)
                tokens = self.tokenizer.tokenize(normalized)
                stems = [self.stemmer.stem(tok) for tok in tokens]

                processed[category].append({
                    "original": text,
                    "normalized": normalized,
                    "tokens": tokens,
                    "stems": stems,
                })

        return processed
