AlgorithmFactory creates configured algorithm instances (SymSpell, N-gram checker, phonetic matcher) with built-in LRU caching for 10-100x speedup on repeated lookups. It’s used internally by SpellChecker but can be accessed directly for advanced use cases.
Overview
AlgorithmFactory Class
Central factory for all spell checking algorithms:Factory Methods
create_symspell
Creates a SymSpell instance with dictionary lookup caching:create_ngram_checker
Creates an N-gram context checker:create_semantic_checker
Creates an ONNX-based semantic checker:Cached Wrappers
CachedDictionaryLookup
Wraps dictionary lookups with LRU caching:CachedBigramSource
Wraps bigram lookups with caching:CachedPOSRepository
Wraps POS lookups with caching:Cache Statistics
get_cache_stats
Get statistics for all caches:clear_caches
Clear all caches:Performance Benefits
Speedup by Operation
| Operation | Uncached | Cached | Speedup |
|---|---|---|---|
| Word lookup | 0.5ms | 0.005ms | 100x |
| Bigram lookup | 1ms | 0.01ms | 100x |
| Suggestions | 50ms | 0.5ms | 100x |
| Semantic check | 200ms | 2ms | 100x |
Memory Usage
| Cache Size | Memory | Typical Coverage |
|---|---|---|
| 1,000 | ~1MB | 80% of common words |
| 10,000 | ~10MB | 95% of common words |
| 100,000 | ~100MB | 99% of vocabulary |
Integration with SpellChecker
The factory integrates with the main SpellChecker:Manual Factory Usage
Configuration
Factory Configuration
Per-Algorithm Configuration
Best Practices
1. Reuse Factory Instances
2. Monitor Cache Performance
3. Clear Caches When Needed
See Also
- SymSpell Algorithm - Suggestion algorithm
- N-gram Context - Context validation
- Semantic Checking - AI-powered checking
- Caching Guide - Caching strategies
- Performance Tuning - Optimization guide