"""Safe, conservative Persian text normalization for human-authored fields.""" import re from functools import lru_cache from hazm import Normalizer # Hazm's spacing rules are intended for prose and can add spaces inside URLs and # technical identifiers. Temporarily replace those spans before normalization. _PROTECTED_SPAN = re.compile( r"https?://\S+|www\.\S+|[\w.+-]+@[\w.-]+\.\w+|" r"(?