Android支持基于字典的BreakIterator

时间:2015-11-05 19:57:29

标签: android tokenize icu

我在API级别16和API级别21中运行以下相同的代码,我发现在API级别16中,基于字典的迭代器(tokenizer)似乎不起作用,而在API级别21中,基于字典的迭代器是工作正常。

BreakIterator it = BreakIterator.getWordInstance();
String txt = "我们一起";
it.setText(txt);
int start = it.first();
int end = it.next();

buf = new StringBuffer();

while (end != BreakIterator.DONE) {
    String word = txt.substring(start,end).trim();
    if (!word.isEmpty()) {
        buf.append(word);
        buf.append("+");
    }
    start = end;
    end = it.next();
}

vw.setText(buf);

在API Level 21中,文本视图显示("我们"是一个单词,"一起"是一个单词)

   我们+一起+

但是在API级别16中,它显示如下(每个中文字符都是一个单词):

   我+们+一+起+

所以我怀疑API级别21启用了基于字典的迭代器,而以前的API版本没有。

然而,在我搜索了Android的C ++源代码之后,我发现两个API级别的关键函数RuleBasedBreakIterator :: checkDictionary都在rbbi.cpp中。它给出了两个API都应该支持基于字典的迭代器的提示。我也怀疑差异是因为为不同的char-set设置了不同的类别值。但是,我无法追溯这些值的设置方式以及是否存在差异。

我的问题是,如何进一步确认在API级别21中增强了API实现?

0 个答案:

没有答案