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

WordBreakIterator::word_type() returns wrong type #3392

Closed
MichalDolata opened this issue Apr 25, 2023 · 2 comments · Fixed by #3404
Closed

WordBreakIterator::word_type() returns wrong type #3392

MichalDolata opened this issue Apr 25, 2023 · 2 comments · Fixed by #3404
Assignees
Labels
C-segmentation Component: Segmentation

Comments

@MichalDolata
Copy link

I was testing an example from https://docs.rs/icu/latest/icu/segmenter/struct.WordSegmenter.html and I spotted a bug.

If the last character is . preceded directly by word, the word isn't returned in result.

use icu::segmenter::{WordSegmenter, WordType};
use itertools::Itertools;

fn main() {
    let text = "one.";
    let segmenter =
        WordSegmenter::try_new_auto_unstable(&icu_testdata::unstable()).expect("Data exists");
    let words: Vec<&str> = {
        let mut it = segmenter.segment_str(text);
        std::iter::from_fn(move || it.next().map(|i| (i, it.word_type())))
            .tuple_windows()
            .filter(|(_, (_, status))| *status == WordType::Letter)
            .map(|((i, _), (j, _))| &text[i..j])
            .collect()
    };

    println!("{:?}", words);
}

I expect it to return ["one"] but it returns empty vector. But if . is replaced with other punctation mark, for example ? it works as expected.

I'm new to icu4x so I wasn't able to prepare fix for that :/

@sffc
Copy link
Member

sffc commented Apr 27, 2023

In one. it appears that we do find a breakpoint between the e and the . -- my initial guess is that the lookahead sees the . and returns a different rule status (since it could be an abbreviation, URL, etc) than ? which is a definite hard stop. @makotokato @aethanyc Can you take a look at what the expected behavior is here?

@sffc sffc added C-segmentation Component: Segmentation needs-approval One or more stakeholders need to approve proposal labels Apr 27, 2023
@aethanyc aethanyc self-assigned this May 2, 2023
@aethanyc
Copy link
Contributor

aethanyc commented May 2, 2023

I can reproduce this. I'll look into it.

@aethanyc aethanyc removed the needs-approval One or more stakeholders need to approve proposal label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-segmentation Component: Segmentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants