Skip to main content
The PhoneticHasher converts Myanmar text into pronunciation-based hash codes, letting the suggestion engine surface candidates that sound alike, even when their spellings differ significantly.

Phonetic Hasher

mySpellChecker includes a custom PhoneticHasher optimized for Myanmar phonology. It converts a string into a phonetic code, allowing for fuzzy matching based on pronunciation.

Key Features

  • Consonant Grouping: Maps similar-sounding consonants (e.g., က vs ) to the same code.
  • Tone Normalization: Can ignore tone marks (e.g., ကာ, ကား, က) to find tonal errors.
  • Vowel Normalization: Treats short and long vowels (e.g., vs ) as identical.
  • Adaptive Length Encoding: Automatically extends the code length for compound words to preserve phonetic information.
  • Nasal Normalization: Optionally unifies various nasal endings (e.g., န်, မ်, င်) to the Anusvara () sound. Note: normalize_nasals defaults to False — you must explicitly enable it if needed.

Python API

How It Works

Encoding Process

  1. Normalization: Text is converted to Unicode NFC form.
  2. Preprocessing: If normalize_nasals=True, common nasal endings (န်, မ်, င်) are normalized to . (Disabled by default.)
  3. Mapping: Each character is mapped to a phonetic group code (e.g., KA_GROUP, MEDIAL_R).
  4. Filtering: Tone marks and viramas are optionally stripped.
  5. Concatenation: Codes are joined to form the final hash.

Scoring

The compute_phonetic_similarity method uses a multi-factor scoring approach:
  1. Character-level similarity: Compares characters pairwise using Myanmar substitution costs (MYANMAR_SUBSTITUTION_COSTS), visual confusability, and phonetic group membership.
  2. Length penalty: Proportional penalty for length differences: (max_len - min_len) / max_len * 0.2.
  3. Phonetic code blending: Levenshtein distance on phonetic codes is blended with character-level similarity, with code weight scaled by input length (min(0.4, len / 20.0)).
Score = (1 - w) * CharSimilarity + w * CodeSimilarity - LengthPenalty Where CharSimilarity is the average per-character similarity using substitution costs, CodeSimilarity = 1 - Levenshtein(Code_A, Code_B) / MaxLen, and w = min(0.4, len(input) / 20.0).

Usage in Spell Checking

Note: Phonetic hashing is computed at runtime, not stored in the database schema. There is no phonetic_hash column in the database tables. Hashes are generated on-the-fly using the PhoneticHasher during lookup.
  1. Lookup: When a word is unknown (OOV), the system computes its phonetic hash at runtime.
  2. Comparison: The hash is compared against hashes computed for dictionary candidates (from SymSpell delete index).
  3. Suggestion: Candidates are matched by:
    • Exact Hash Match: Words that sound identical.
    • Near Hash Match: Words that sound very similar (e.g., slight medial difference).

Constructor Parameters

Configuration

Controlled by use_phonetic in SpellCheckerConfig.