Skip to main content
N-gram models excel at scoring how “natural” a word sequence sounds, but they can’t enforce hard constraints. A double-verb sequence without an intervening particle is always wrong in Myanmar, regardless of how common the individual words are. The Syntactic Rule Checker runs as Layer 2.5, between word validation and N-gram scoring, to enforce these non-negotiable grammatical patterns.

Overview

The Syntactic Rule Checker runs after word validation but before the statistical N-gram check. It is designed to catch:
  1. Grammatically Impossible Sequences: e.g., two verbs without a particle between them.
  2. Particle Errors: Using a noun-particle after a verb, or vice versa.
  3. Medial Consonant Confusions: vs based on linguistic roots (handled via lookup).
  4. Sentence Structure: Missing sentence-final particles.

Architecture

The grammar system consists of:

Core Components

Grammar Checkers

YAML Rule Files

Grammar rules are defined in YAML files located in src/myspellchecker/rules/: Core Grammar Checkers and Patterns Confusion and Error Correction Detection and Scoring

Key Features

1. Particle Agreement

Myanmar particles are highly specific to the part of speech they modify.
  • Verb Particles: မယ်, ခဲ့, နေ must follow verbs.
  • Noun Particles: မှာ, က, ကို must follow nouns.
Example Error:
  • Input: ကျောင်း သွား မှာ (“School go at”)
  • Analysis: သွား is a Verb. မှာ is usually a location marker (Noun particle).
  • Correction: Suggest မယ် (Future tense) or မလား (Question) depending on context, or flag as suspicious.

2. Medial Confusion ( vs )

Many words sound similar but use different medials (Ya-pin vs Ya-yit).
  • Rule: ကျောင်း (School) vs ကြောင်း (Cause/Fact).
  • Logic:
    • If preceded by a Verb (e.g., ဖြစ်), it implies “Cause”. Suggest ကြောင်း.
    • If preceded by a Noun or at start, it implies “School”. Keep ကျောင်း.

3. POS Sequence Validation

We maintain a matrix of invalid POS transitions.
  • Verb -> Verb (Directly): Usually invalid. Needs a particle like ပြီး or .

Configuration

Enable Grammar Checking

Grammar Engine Configuration

Note: GrammarRuleConfig in myspellchecker.grammar.config is a separate class for loading YAML-based grammar rule definitions.

Using SyntacticRuleChecker Directly

Internally, the grammar engine uses RuleMatch dataclass (exported from myspellchecker.grammar.engine) for priority-based conflict resolution. RuleMatch has fields: position, word, suggestion, priority, rule_name, and confidence. The check_sequence method resolves conflicts and returns simplified (index, word, suggestion) tuples.

YAML Rule Format

Grammar rules are defined in YAML format with JSON Schema validation.

Example: grammar_rules.yaml

Schema Validation

Rules are validated against JSON Schema:
  • src/myspellchecker/schemas/grammar_rules.schema.json

Error Types

Grammar checking produces errors with specific types:

Integration with SpellChecker

Grammar checking is integrated into the validation pipeline:

Performance

Next Steps