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.
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).

Factory Methods

Convenience class methods for common configurations:

Context Manager

SpellChecker implements the context manager protocol. Use with to ensure resources (database connections, model sessions) are released automatically:
You can also call checker.close() manually if not using a context manager.

check()

Performs spell checking on the given text.
str
required
The input Myanmar text to check.
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth. SYLLABLE for fast checks, WORD for full validation including context.
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:

check_async()

Asynchronous version of check. Runs the CPU-intensive logic in a thread pool to avoid blocking the event loop.
str
required
The input Myanmar text to check.
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth.
bool | None
default:"None"
Override semantic checking for this call.
Returns: Response Usage Example:
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 sequentially.
list[str]
required
List of texts to check.
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth applied to all texts.
Returns: list[Response]

check_batch_async()

Asynchronously checks multiple texts with configurable concurrency using a semaphore.
list[str]
required
List of texts to check.
ValidationLevel
default:"ValidationLevel.SYLLABLE"
Validation depth applied to all texts.
int
default:"4"
Maximum concurrent operations.
bool | None
default:"None"
Override semantic checking for this batch. True forces semantic checking on, False forces it off, None uses the config default.
Returns: list[Response] (same order as input)

get_pos_tags()

Gets the most likely POS tag sequence for text or pre-segmented words.
str
default:""
Input text to tag (optional if words is provided).
list[str] | None
default:"None"
Pre-segmented words (optional if text is provided).
Returns: list[str], one POS tag per word.

cache_stats()

Returns unified cache statistics from all components (provider, joint tagger, semantic checker, Viterbi). Returns: dict[str, Any]

close()

Closes underlying resources (database connections, model sessions). Idempotent. Also called automatically when using the context manager.

Properties


Convenience Function: check_text()

A one-call function for quick spell checking without manually constructing a SpellChecker.
str
required
Myanmar text to check.
str
default:"syllable"
Validation level: "syllable" or "word".
str | None
default:"None"
Optional path to a SQLite dictionary database. When None, uses the default database lookup.
Returns: Response Raises:
  • MissingDatabaseError if no database is available
  • ValueError if level is not "syllable" or "word"
This creates a new SpellChecker instance per call. For repeated use, create a SpellChecker instance directly for better performance.

ActionType and Error Classification

The ActionType enum classifies the recommended action for each detected error. Every Error object exposes an .action property that returns one of these values.
The classification logic:
  • AUTO_FIX: Deterministic, high-confidence structural repairs (Zawgyi encoding, particle typos, medial confusion, medial order errors, medial compatibility error, ha-htoe confusion, broken virama/stacking, incomplete stacking, missing asat, leading vowel-e, vowel after asat, duplicate punctuation)
  • INFORM: Advisory errors (colloquial variants, colloquial info) or any error with confidence below 0.60
  • SUGGEST: Everything else, shown to user for confirmation

Internationalization (i18n)

Error messages can be localized. The library supports English ("en") and Myanmar ("my").
Language settings are thread-local, so different threads can use different languages concurrently without interference.

Class: Response

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

Serialization

Both Response and all Error subclasses (SyllableError, WordError, ContextError, GrammarError) provide to_dict() and to_json() methods for easy serialization.

to_dict() -> dict[str, Any]

Converts the object to a plain dictionary. For Response, all nested Error objects are also converted.

to_json(indent: int = 2) -> str

Converts the object to a JSON string with Myanmar Unicode preserved (ensure_ascii=False). Set indent=None for compact output.