HanziToPinyin
2021-01-26 本文已影响0人
CentForever
title: HanziToPinyin
date: 2019-11-18 12:40:50
categories:
- pinyin
tags:
- 汉字转拼音
汉字转拼音
https://developer.android.google.cn/guide/topics/resources/icu4j-framework
https://www.jianshu.com/p/58a8a0eebe9d
implementation 'org.apache.lucene:lucene-icu4j:3.2.0'
Transliterator pinyin = Transliterator.getInstance("Han-Latin");
Tokenizer tokenizer = new KeywordTokenizer(new StringReader("中国"));
ICUTransformFilter filter = new ICUTransformFilter(tokenizer,pinyin);
assertTokenStreamContents(filter, new String[] { "zhōngguó"});
Transliterator pinyin = Transliterator.getInstance("Han-Latin");
Tokenizer tokenizer = new KeywordTokenizer(new StringReader("中国"));
ICUTransformFilter filter = new ICUTransformFilter(tokenizer,pinyin);
assertTokenStreamContents(filter, new String[] {"zhongguo"});
private Transliterator mPinyinTransliterator;
private Transliterator mAsciiTransliterator;
private HanziToPinyin() {
try {
mPinyinTransliterator = /*new Transliterator(
"Han-Latin/Names; Latin-Ascii; Any-Upper")*/Transliterator.getInstance("Han-Latin/Names; Latin-Ascii; Any-Upper");
mAsciiTransliterator = /*new Transliterator("Latin-Ascii")*/Transliterator.getInstance("Latin-Ascii");
} catch (IllegalArgumentException e) {
Log.w(TAG, "Han-Latin/Names transliterator data is missing,"
+ " HanziToPinyin is disabled");
}
}