fix: avoid false-positive Title classification for long no-space text
Summary
- add a no-space length guard in
is_possible_title()to handle CJK text better - introduce
UNSTRUCTURED_TITLE_MAX_NO_SPACE_LENGTH(default:40) for tuning - add regression tests for Chinese text without spaces (short heading vs long body) Closes #3930
Why
Chinese OCR output often has no spaces, so long narrative text could be interpreted as a single "word" and incorrectly classified as Title. This change reduces those false positives while preserving expected short-title behavior.
Test plan
- [x] Added unit test coverage in
test_unstructured/partition/test_text_type.py - [ ] Run:
pytest -q test_unstructured/partition/test_text_type.py -k "title or chinese" - [ ] Verify OCR-only PDF flow no longer maps long Chinese body text to
Title - [ ] Sanity-check English title classification is unchanged
[!NOTE] Medium Risk Changes
is_possible_title()heuristics for Han-ideograph text, which can affect downstream element classification and chunking behavior; env-default tuning mismatch could surprise users if relied upon implicitly.Overview Reduces false-positive
Titleclassification for long whitespace-free CJK/Han text by adding a Han-ideograph regex and a max-length guard inis_possible_title()(configurable viaUNSTRUCTURED_TITLE_MAX_NO_SPACE_LENGTH).Adds regression tests covering short Chinese headings vs long Chinese body text and ensuring the new guard doesn’t apply to other no-space scripts. Bumps version to
0.22.28and documents the fix inCHANGELOG.md.Reviewed by Cursor Bugbot for commit eda9fe4606dd2f58afb249fd2a06318b0209d418. Bugbot is set up for automated code reviews on this repo. Configure here.
@SudSampath Would you please review?
@cragwolfe Would you please review?