Overview
The Syntactic Rule Checker runs after word validation but before the statistical N-gram check. It is designed to catch:- Grammatically Impossible Sequences: e.g., two verbs without a particle between them.
- Particle Errors: Using a noun-particle after a verb, or vice versa.
- Medial Consonant Confusions:
ျvsြbased on linguistic roots (handled via lookup). - 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 insrc/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.
- 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
ကျောင်း.
- If preceded by a Verb (e.g.,
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:GrammarRuleConfiginmyspellchecker.grammar.configis 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
- POS Tagging - How POS tags are assigned
- Context Checking - N-gram context validation
- Validation Strategies - Strategy pattern overview