06/15 Phase 1 + 2 codes

This commit is contained in:
2026-06-15 11:23:05 -04:00
commit c2064b84b4
62 changed files with 2937 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
"""Text normalization for accent-insensitive search.
Strips diacritics so "phở" -> "pho" and "ñandú" -> "nandu".
Used now for display/utility; drives `title_norm` shadow column in Phase 2 listings.
"""
import unicodedata
# Vietnamese đ/Đ do not decompose via NFKD, map explicitly.
_EXPLICIT = {
"đ": "d", "Đ": "d",
"ð": "d", "Ð": "d",
}
def normalize(text: str) -> str:
if not text:
return ""
out = []
for ch in text:
if ch in _EXPLICIT:
out.append(_EXPLICIT[ch])
continue
decomposed = unicodedata.normalize("NFKD", ch)
stripped = "".join(c for c in decomposed if not unicodedata.combining(c))
out.append(stripped)
return "".join(out).lower().strip()