Skip to main content
When a word fails validation, mySpellChecker generates correction candidates. The SuggestionStrategy protocol lets you swap the algorithm (SymSpell, phonetic matching, or a custom approach) without changing the rest of the pipeline.

Overview

SuggestionStrategy Protocol

The core protocol defining the suggestion interface:

SuggestionContext

Context information for generating suggestions:

Creating Context

SuggestionResult

Results from suggestion generation:

Accessing Results

BaseSuggestionStrategy

Base class with common functionality:

Implementing a Custom Strategy

CompositeSuggestionStrategy

Combines multiple strategies with unified ranking:

Using Composite Strategy

Context Support

Strategy Types

Morpheme-Level Strategy

Corrects typos inside compound words and reduplications by fixing individual morphemes:
The strategy is automatically included in the CompositeSuggestionStrategy pipeline when ReduplicationEngine or CompoundResolver are enabled. Suggestions use source="morpheme" with confidence 0.80-0.85, weighted by source_weight_morpheme=0.85 in RankerConfig.

Medial Swap Strategy

Generates candidates by swapping, inserting, or deleting Myanmar medials (ျ↔ြ, ွ↔ှ). This targets the #1 error type in Myanmar text, ya-pin/ya-yit confusion, which SymSpell’s delete-distance model cannot reliably find as edit-distance-1 candidates.
Algorithm:
  1. Scan word for medial characters (U+103B-U+103E)
  2. Generate swap variants using configured pairs (ျ↔ြ, ွ↔ှ)
  3. Generate insertion variants (add missing medial after consonant)
  4. Generate deletion variants (remove extra medial)
  5. Optionally generate anusvara (ံ) insert/delete variants
  6. Validate each variant against the dictionary
  7. Return valid variants as SuggestionData with source="medial_swap"
Rules are loaded from rules/medial_swap_pairs.yaml and can be customized via the rules_path parameter. Performance is O(1) per variant (3-8 variants per word). The strategy is automatically included in the suggestion pipeline and its candidates use source_weight_medial_swap=1.0 in RankerConfig.

Edit Distance Strategies

Context-Aware Strategies

Phonetic Strategies

Semantic Strategies

Batch Processing

Integration

With SpellChecker

Suggestion strategies are not passed directly to SpellChecker. Instead, they are wired internally via the WordValidator, which receives a CompositeSuggestionStrategy through the DI container and factory system:
To customize which strategies are used, configure the SpellCheckerConfig and pass it to SpellChecker. The WordValidator internally creates and composes strategies (SymSpell, Morphology, Compound, Morpheme, Context) based on the config and available components.

With Algorithm Factory

See Also