Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in segmenter involving short strings of complex scripts #3341

Merged
merged 4 commits into from
Apr 18, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Start debugging Segmenter bug
  • Loading branch information
sffc committed Apr 17, 2023
commit 7670d162fed8a64d7efea27116e722e035d651d9
1 change: 1 addition & 0 deletions components/segmenter/src/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ where
iter.result_cache = iter.result_cache.iter().skip(1).map(|r| r - i).collect();
return iter.get_current_position();
}
debug_assert!(i < first_pos, "we should always arrive back at the same index when resolving the complex script: near index {:?}", iter.get_current_position());
iter.advance_iter();
if iter.is_eof() {
iter.result_cache.clear();
Expand Down
17 changes: 17 additions & 0 deletions components/segmenter/tests/complex_word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,20 @@ fn word_break_mixed_han() {
);
}
}

#[test]
fn word_break_th_wikipedia() {
let text = "แพนด้าแดง (อังกฤษ: Red panda, Shining cat; จีน: 小熊貓; พินอิน: Xiǎo xióngmāo) สัตว์เลี้ยงลูกด้วยนมชนิดหนึ่ง มีชื่อวิทยาศาสตร์ว่า Ailurus fulgens";

assert_eq!(text.len(), 297);

let segmenter_line_auto =
WordSegmenter::try_new_auto_unstable(&icu_testdata::unstable()).expect("Data exists");

let breakpoints = segmenter_line_auto.segment_str(text).collect::<Vec<_>>();

assert_eq!(
breakpoints,
[0, 9, 18, 27, 28, 29, 38, 47, 48, 49, 52, 53, 58, 59, 60, 67, 68, 71, 72, 73, 297]
);
}