Skip to main content
Every validation layer depends on accurate syllable boundaries. The RegexSegmenter uses three complementary regex patterns to identify where one syllable ends and the next begins, handling stacked consonants, Kinzi formations, and mixed-script text.

Overview

Myanmar text has no whitespace between words, making segmentation challenging. The syllable segmenter breaks continuous Myanmar text into individual syllables using regex-based pattern matching combined with syllable rule validation.

Algorithm Design

The RegexSegmenter uses three regex patterns to identify syllable boundaries:

Pattern 1: Myanmar Consonant Syllable Start

This pattern identifies consonants (U+1000-U+1021) that start new syllables:
  • Negative lookbehind: (?<!(?<!\u103a)\u1039) - NOT preceded by a stacking Virama (unless preceded by Asat for Kinzi)
  • Negative lookahead: (?!\u103a) - NOT followed by Asat (the Virama case is handled by the lookbehind, so the lookahead only checks Asat)
This ensures stacked consonants stay together while allowing breaks after Kinzi formations.

Pattern 2: Other Syllable Starters

Matches:
  • Independent vowels (U+1022-U+102A)
  • Great Sa (U+103F)
  • Symbols (U+104C-U+104F)
  • Digits (U+1040-U+1049)
  • Punctuation (U+104A-U+104B)

Pattern 3: Non-Myanmar Characters

Groups consecutive non-Myanmar characters (English, punctuation, whitespace) to avoid over-fragmentation.

Implementation

RegexSegmenter Class

Configuration Options

Syllable Validation

After segmentation, each syllable is validated using SyllableRuleValidator:

Myanmar Syllable Structure

A valid Myanmar syllable follows this pattern:

Performance

The segmenter has two implementations: The Cython version is automatically used when available:

Edge Cases

Stacked Consonants

Stacked consonants (using Virama U+1039) stay together:

Kinzi Formation

Kinzi (Asat + Virama + Consonant) is handled correctly:

Mixed Script

Non-Myanmar text is grouped together:

See Also