Expand description
§khmer-tokenizer-core
A fast, dependency-free Khmer word segmenter.
Written Khmer does not put spaces between words, so segmentation is the first step of nearly every Khmer NLP pipeline. This crate does it in two passes:
- Cluster pass —
split_kccgroups the text into Khmer Character Clusters (a base character plus its subscripts and vowels). This keeps the segmenter from ever splitting inside an orthographic syllable. - Boundary pass —
KhmerTokenizerwalks a cluster-keyed trie to place word boundaries, using one of a fewStrategyalgorithms (default: greedy longest-match, falling back to a single cluster when nothing matches).
The engine is std-only (no external dependencies) and deterministic.
§Quick start
use khmer_tokenizer_core::KhmerTokenizer;
let tk = KhmerTokenizer::with_default_dict();
let tokens = tk.segment("សួស្តីអ្នកទាំងអស់គ្នា");
assert_eq!(tokens, vec!["សួស្តី", "អ្នក", "ទាំងអស់គ្នា"]);Structs§
- HmmModel
- A trained BMES Hidden Markov Model for segmenting clusters the dictionary has no match for at all.
- Khmer
Tokenizer - Dictionary-backed Khmer word segmenter.
Enums§
- Strategy
- Which segmentation algorithm
KhmerTokenizer::segmentuses.
Constants§
- DEFAULT_
DICT - The embedded default dictionary (59,526 words; see
ATTRIBUTION.md): one word per line; blank lines and lines starting with#are ignored. Replace or extend it for your own use case — see the dictionary notes in the project README.
Functions§
- is_
khmer - True if
cfalls anywhere in the Khmer Unicode block (U+1780..=U+17FF). - normalize
- Canonicalize
text’s Khmer encoding before segmentation. Idempotent: normalizing already-canonical (or already-normalized) text is a no-op. Byte-length-preserving: only reorders characters, never adds or removes any, so span offsets over the original text stay valid. - split_
kcc - Split
textinto Khmer Character Clusters.