Fix HMM segmentation of digit+letter tokens to align with Python jieba#212
Merged
Fix HMM segmentation of digit+letter tokens to align with Python jieba#212
Conversation
…binations Co-authored-by: yanyiwu <2162645+yanyiwu@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix word segmentation alignment between C++ and Python
Fix HMM segmentation of digit+letter tokens to align with Python jieba
Mar 11, 2026
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.
C++ cppjieba splits alphanumeric combinations like "5G" and "3D" into separate tokens, while Python jieba's
finalsegkeeps them together viare_skip = [a-zA-Z0-9]+(?:\.\d+)?.Root cause
HMMSegment::NumbersRuleconsumed only[0-9.]+, so "5G" produced["5", "G"]instead of["5G"].Changes
HMMSegment::NumbersRule: Inner loop changed from[0-9.]to[a-zA-Z0-9], allowing letters after an initial digit. Replaced multi-dot permissiveness with a single optional decimal suffix\.\d+, matching Python's pattern.HMMSegment::SequentialLetterRule: Added the same optional\.\d+suffix (e.g.abc1.2stays together).HMMSegmentTest.AlphanumericCombinationsand two new cases inMixSegmentTest.Test1covering the above patterns.Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.