Vietnamese word segmentation for Koharu: a Rust port of pyvi's tokenizer, with its model built in. Vietnamese spaces every syllable, so a word of two or more has spaces inside it, and Koharu's line breaking asks this crate where they are.
let text = "Cảm ơn cậu nhiều lắm!";
let words: Vec<&str> = pyvi::tokenize(text).into_iter().map(|word| &text[word]).collect();
assert_eq!(words, ["Cảm ơn", "cậu", "nhiều", "lắm", "!"]);It follows pyvi/ViTokenizer.py at
e2ac2ec:
sylabelize's syllables, word2features's features, the CRF's tags, and
tokenize's joins. Words come back as byte ranges of the text it was given,
composed or not.
data/pyvi.crfsuite: the CRFsuite model inside pyvi'smodels/pyvi3.pkl, taken out byte for byte byscripts/extract_model.py, which walks the pickle's opcodes and runs none of them. crfs runs it.data/words.txt: pyvi'smodels/words.txt, unchanged.
On 10,432 inputs, pyvi's treebank sample data/vtb.txt and manga dialogue with
decomposed copies, the port's syllables, tags, and words match pyvi's exactly:
265,770 syllables in all. The tests check the dialogue in tests/inputs.txt
against tests/reference.jsonl, which scripts/reference.py writes from a
pyvi checkout.
To try a change in Koharu before it's merged, patch Koharu's dependency on this repository to a local checkout, and leave the patch out of Koharu's commits:
[patch."https://github.com/koharu-rs/pyvi"]
pyvi = { path = "../pyvi" }MIT, as pyvi is; see LICENSE.