美文网首页
HanziToPinyin

HanziToPinyin

作者: CentForever | 来源:发表于2021-01-26 00:00 被阅读0次

    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");
            }
        }
    

    相关文章

      网友评论

          本文标题:HanziToPinyin

          本文链接:https://www.haomeiwen.com/subject/vkoyzktx.html