Skip to main content
Use SpellCheckerBuilder for convenient construction, or inject dependencies directly via the constructor for advanced use cases.

Class: SpellChecker

Initialization

The recommended way to initialize SpellChecker is via the SpellCheckerBuilder.
from myspellchecker.core import SpellCheckerBuilder, ConfigPresets

# Quick start (uses default config and provider)
checker = SpellCheckerBuilder().build()

# Optimized for speed
checker = (
    SpellCheckerBuilder()
    .with_config(ConfigPresets.FAST)
    .build()
)

# Custom configuration with POS tagging and Joint Segmentation
checker = (
    SpellCheckerBuilder()
    .with_phonetic(True)
    .with_context_checking(True)
    .with_max_suggestions(5)
    .with_pos_tagger(tagger_type="transformer", device=0)
    .with_joint_segmentation(enabled=True)
    .build()
)
The constructor SpellChecker(config, segmenter, provider, syllable_validator, word_validator, context_validator, factory) is still available for advanced users who need direct dependency injection but is less convenient. All parameters are optional (defaulting to None).

check()

Performs spell checking on the given text.
text
str
required
The input Myanmar text to check.
level
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth. SYLLABLE for fast checks, WORD for full validation including context.
use_semantic
bool | None
default:"None"
Override semantic checking for this call. None uses config default, True/False forces on/off.
Returns: Response

segment_and_tag(text: str) -> Tuple[List[str], List[str]]

Segments text into words and assigns Part-of-Speech tags using the configured method (Joint or Sequential). Returns:
  • Tuple of (words, tags).
Example:
words, tags = checker.segment_and_tag("မြန်မာနိုင်ငံ")
# words: ['မြန်မာ', 'နိုင်ငံ']
# tags: ['N', 'N']

check_async()

Asynchronous version of check. Runs the CPU-intensive logic in a thread pool to avoid blocking the event loop.
text
str
required
The input Myanmar text to check.
level
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth.
use_semantic
bool | None
default:"None"
Override semantic checking for this call.
Returns: Response Usage Example:
import asyncio
from myspellchecker import SpellChecker

async def main():
    checker = SpellChecker()
    
    # Run in event loop without blocking
    result = await checker.check_async("မြန်မာ")
    print(result.corrected_text)

asyncio.run(main())
Ideal for:
  • Web APIs (FastAPI/Sanic): Keeps the server responsive while processing text.
  • Concurrent Batching: Processing multiple texts in parallel using asyncio.gather.

check_batch()

Efficiently checks a list of texts.
texts
list[str]
required
List of texts to check.
level
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth applied to all texts.
Returns: list[Response]

Class: Response

The check method returns a Response object.
text
str
required
Original input text.
corrected_text
str
required
Text with top suggestions applied automatically.
has_errors
bool
required
True if any errors were found.
level
str
required
Validation level used ("syllable" or "word").
errors
list[Error]
required
List of error objects found in the text.
metadata
dict[str, Any]
required
Processing metadata including processing_time, error counts, and validation statistics.