Repository navigation
Add optional ICU-based InternationalTokenizer - #648
Draft
TheFabbest wants to merge 2 commits into
Draft
TheFabbest wants to merge 2 commits into
TheFabbest wants to merge 2 commits into
Conversation
`--tokenizer international` splits words with icu::BreakIterator so that languages written without spaces (Chinese, Japanese, Thai) and mixed-language text can be tokenized. Tokens are case-folded; whitespace, symbols and punctuation are dropped. ICU is optional and auto-detected (PISA_ENABLE_ICU, default ON). Without it, PISA still builds, CMake warns, and the tokenizer throws std::runtime_error. ICU state lives behind a pimpl, so no ICU headers appear in public headers. Relates to pisa-engine#464
TheFabbest
force-pushed
the
international-tokenizer
branch
from
October 28, 2026 15:22
3f4380e to
cb05ae1
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Relates to #464
Adds
InternationalTokenizer, selectable with--tokenizer international. It splits text into words with ICU'sicu::BreakIterator, which makes it possible to tokenize languages written without spaces (Chinese, Japanese, Thai and more) and mixed-language text.ICU is an optional dependency. Without it, PISA builds and works normally and
cmakeprints a warning, but--tokenizer internationalfails at runtime with an error.Most Linux distributions already have the ICU runtime installed, but PISA needs the development files (
libicu-devon Debian/Ubuntu,libicu-develon Fedora), which may be missing, for example in Docker images. As far as I know, macOS should work with-DICU_ROOT=$(brew --prefix icu4c), but I couldn't test it.Behavior
For
InternationalTokenizer:Straße->strasse). This is standard, but can be changed easily to lowercase only. Accents are kept.shouldn't->shouldn't). Dotted words stay whole, only a trailing.is dropped (U.S.A.->u.s.a,himself.image->himself.image).Dependency handling
ICU is large, but is available as a standard system package on common platforms. PISA does not vendor it, so unlike the
PISA_SYSTEM_*options (which choose between a system and a vendored copy of a dependency),PISA_ENABLE_ICUsimply enables or disables an optional feature. The default of ON follows the same convention as the vendored boost-cmake'sBOOST_LOCALE_ENABLE_ICU_BACKEND("enable if available", default ON). The table below summarizes the behavior:PISA_ENABLE_ICUPISA_HAS_ICU=1is defined, ICU is linked, tokenizer worksstd::runtime_errorstd::runtime_errorICU is already probed optionally by the existing build via
external/boost-cmake/libs/locale.cmake(find_package(ICU ...)withoutREQUIRED, falling back to iconv). So this PR does not add a new required dependency, but it is the first time PISA's own code uses ICU.No ICU headers are exposed by PISA’s public headers:
InternationalTokenStreamis declared intokenizer.hpplike the other streams, but its ICU state lives behind a pimpl defined intokenizer.cpp. Since PISA is a static library, binaries linking it when built with ICU also link ICU.ICU is widely used and well-maintained, and is the de facto standard for Unicode text processing.
Testing
Environment: PopOS! 24.04 (ubuntu-based), GCC 13.3, ICU 74.2 locally (was already installed).
Also an Ubuntu 24.04 docker container with no ICU headers installed.
PISA_ENABLE_ICUON or OFF) were checked.-DPISA_COMPILE_HEADERS=ONpasses, confirming thattokenizer.hppdoesn’t leak ICU includes.parse_collectiontool with all three tokenizers and manually verified that the output is as expected.EnglishTokenizeron English text, with little difference in memory usage.Notes
PISA_ENABLE_ICU. I chose ON (auto-detect) to match the existing Boost.Locale probe. If you prefer optional features to be strictly opt-in, flipping it to OFF is a one-line change.icu::BreakIteratorandicu::UnicodeString, with no shared mutable state. This suggests it is safe.InternationalTokenStreamis not copyable. Streams are only handed out asstd::unique_ptr<TokenStream>, so copying isn’t needed, and a correct copy would have to re-bind the ICU break iterator to the copied text. I can add copy support if you prefer consistency.