Expand description
The core tokenizer, v2.
The pipeline mirrors what the strongest lexical engines (Lucene’s
ICU/Standard analyzers, SQLite FTS5 unicode61) converge on, built
from the pure-core unicode-rs table crates so it runs identically on
native and every wasm runtime:
- NFKC normalization of the input (fullwidth
A→A, ligaturefi→fi, decomposed marks recomposed) — one pass into a reused scratch buffer. - UAX #29 word segmentation (
unicode-segmentation) — the same boundary standard ICU implements. Consequences worth knowing:don'tando'clockstay whole (apostrophe joins letters),3.14/v1.2.3/example.comstay whole (./,join digits and letters),snake_casestays whole (_joins),gpt-4osplits on the hyphen. - Per-token folding: full Unicode lowercase; Latin diacritics
stripped (
café→cafe, the FTS5remove_diacriticsbehavior, applied only to Latin bases so Cyrillicйis untouched); the Russian-specificё→еfold every major Russian search engine applies. - CJK: Han ideographs and Hiragana come out of UAX #29 as
single-character segments; adjacent ones are joined into
overlapping bigrams (the Lucene
CJKBigramFilterscheme — the standard dictionary-free CJK treatment), a lone character stays a unigram. Katakana and Hangul already segment into word runs and are kept as words. - A token longer than
MAX_TOKEN_BYTESis truncated at the last char boundary that fits (long tokens sharing a 64-byte prefix collapse — accepted by spec).
No stemming or lemmatization in v1. Emitted tokens are canonical: a fixed point of the tokenizer (fixed by a property test).
Structs§
- Tokenizer
- Streaming tokenizer with reusable scratch buffers.
Constants§
- MAX_
TOKEN_ BYTES - Upper bound on an emitted token, in bytes.