"""
Practice: entity accuracy, the words a customer actually cares about.

WER gives "the" and "4471-2209" equal weight. An entity check looks only at the words that
matter (account numbers, names, drug names) and uses rules that fit each kind.

Fill in the three TODOs, then run the tests:
    pytest test_entities_practice.py        (locally)
or press "Run tests" on the chapter page.
"""

DIGIT_WORDS = {"zero": "0", "oh": "0", "o": "0", "one": "1", "two": "2", "three": "3", "four": "4",
               "five": "5", "six": "6", "seven": "7", "eight": "8", "nine": "9"}


def basic(text: str) -> list[str]:
    """Basic normalizer (given): lowercase, hyphens to spaces, drop punctuation, split."""
    text = text.lower().replace("-", " ")
    text = "".join(ch if ch.isalnum() or ch in " '" else " " for ch in text)
    return text.split()


def digit_runs(text: str) -> list[str]:
    """Every run of consecutive digits and digit words, joined into one string.

    'account 4471-2209 or four four'        -> ['44712209', '44']
    'card ending in oh three five eight'    -> ['0358']
    Separators inside a number (spaces, hyphens, commas) don't break a run; any other word does.

    TODO 1: walk the tokens from basic(text). Digits and digit words extend the current run;
    any other token ends it.
    """
    return []


def entity_correct(kind: str, expected: str, transcript: str) -> bool:
    """Is the entity in the transcript?

    kind "digits": `expected` (like "44712209") must appear as one complete digit run.
                   A run that only contains it ("447122090") doesn't count, nor does "358" for "0358".
    kind "name":   the name's words must appear, in order, as whole words (case-insensitive).

    TODO 2
    """
    return False


def entity_accuracy(items: list[tuple[str, str, str]]) -> float:
    """Share of entities a model got right. Each item is (kind, expected, transcript).

    TODO 3
    """
    return 0.0
