"""Baseline: single-char canonicalization + Levenshtein."""

import unicodedata
from rapidfuzz import fuzz
from harness import evaluate

# Single-character equivalence classes (visually identical)
CHAR_MAP = {}
for group in [
    "lI1|!",       # vertical strokes
    "oO0",         # round shapes
    "sS5",         # S-shapes
    "zZ2",         # Z-shapes
    "bB8",         # B-shapes (optional)
]:
    canonical = group[0]
    for ch in group:
        CHAR_MAP[ch] = canonical


def canonicalize(text):
    text = unicodedata.normalize("NFKC", text)
    text = text.lower()
    text = "".join(CHAR_MAP.get(ch, ch) for ch in text)
    # Collapse whitespace
    text = " ".join(text.split())
    return text


def score(query, candidate):
    q = canonicalize(query)
    c = canonicalize(candidate)
    return fuzz.ratio(q, c) / 100.0


if __name__ == "__main__":
    evaluate(score, name="05 - Simple Canonicalization + Levenshtein")
