"""Shared text utilities for deterministic metrics."""

from __future__ import annotations

import re
import unicodedata


def normalize_text(text: str) -> str:
    text = unicodedata.normalize("NFKD", text)
    text = text.lower().strip()
    text = re.sub(r"[^\w\s]", "", text)
    return re.sub(r"\s+", " ", text)


def format_context(chunks: list[str]) -> str:
    return "\n".join(f"[{i + 1}] {chunk}" for i, chunk in enumerate(chunks))
