Fixes
fix: support soft hyphens in the word splitter (#9144)
fix: support soft hyphens in the word splitter (#9144)
This pull request introduces several improvements and fixes to the word segmentation and word splitting logic, especially for Thai language support and symbol handling. The main changes include updating the Thai segmentation to use soft hyphens, enhancing the word splitting logic to handle more cases (including camelCase, symbols, and soft hyphens), and refactoring the code for better modularity and test coverage.
Word segmentation and Thai language improvements:
- Updated Thai (
th-TH) segmentation to use soft hyphens (\u00AD) instead of spaces, improving the accuracy of word breaks and ensuring better compatibility with spell checking and downstream processing. [1] [2] [3] - Added the
@cspell/dict-th-thpackage to dependencies, enabling Thai dictionary support. - Adjusted tests and expectations for Thai segmentation to reflect the use of soft hyphens and to ensure no false positives in validation.
Word splitting and symbol handling enhancements:
- Introduced a new
generateWordBreaksutility that generates all possible word breaks in a string, including camelCase, symbols, numbers, and soft hyphens. Includes comprehensive tests and snapshot coverage for various edge cases. [1] [2] [3] [4] - Improved regular expressions for word splitting to support soft hyphens and better handle punctuation and symbols.
Refactoring and code organization:
- Refactored imports to use the new
wordSplitter/index.jsentry point, improving modularity and future maintainability. [1] [2] - Added explicit exports for
split,SplitOptions, andSplitResultinwordSplitter/index.tsto clarify and centralize the public API.
Other enhancements:
- Exposed the
softHyphenconstant for consistent use throughout the codebase. [1] [2]