import unicodedata
import re


def preprocess(rule: str) -> str:
    """
    Internal function for pre-processing of rules.

    @param rule: The rule to be preprocessed.
    @return: The cleaned, preprocessed rule.
    """

    # 1. Normalize to NFD, as per maniphono
    rule = unicodedata.normalize("NFD", rule)

    # 2. Replace multiple spaces with single ones, and remove leading/trailing spaces
    rule = re.sub(r"\s+", " ", rule.strip())

    return rule