fallback¶
Fast phonetic key encoder that works on any string without CMU dict lookup. Simplified Metaphone-inspired encoding tuned for package names.
phonemenal.fallback
¶
Fast phonetic key encoder — works on any string without CMU dict lookup.
Simplified Metaphone-inspired encoding that handles arbitrary strings. Useful as a fallback when the CMU dict doesn't cover a word (non-English, neologisms, coined terms like "numpy", "pytorch", "fastapi").
Also provides an LCS-based similarity ratio for comparing phonetic keys.
phonetic_key(name: str) -> str
¶
Generate a coarse phonetic key for a name.
Applies digraph replacements, vowel normalization, and character collapsing to produce a phonetic skeleton. Sound-alike names produce the same or similar keys.
Examples:
phonetic_key("phone") → "fAn" phonetic_key("fone") → "fAn" phonetic_key("flask") → "flAsk" phonetic_key("phlask") → "flAsk"
Source code in phonemenal/fallback.py
similarity(key1: str, key2: str) -> float
¶
LCS-based similarity ratio between two phonetic keys.
Returns 0.0–1.0 reflecting phonetic structure overlap.
Source code in phonemenal/fallback.py
compare(name1: str, name2: str) -> dict
¶
Compare two names using the fallback phonetic encoder.
Returns dict with keys, similarity score, and whether they're an exact match.