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: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.- Scan word for medial characters (U+103B-U+103E)
- Generate swap variants using configured pairs (ျ↔ြ, ွ↔ှ)
- Generate insertion variants (add missing medial after consonant)
- Generate deletion variants (remove extra medial)
- Optionally generate anusvara (ံ) insert/delete variants
- Validate each variant against the dictionary
- Return valid variants as
SuggestionDatawithsource="medial_swap"
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 toSpellChecker. Instead, they are
wired internally via the WordValidator, which receives a CompositeSuggestionStrategy
through the DI container and factory system:
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
- Suggestion Ranking - Ranking algorithms
- SymSpell Algorithm - Edit distance suggestions
- Context Checking - N-gram context
- Algorithm Factory - Strategy creation