赞
踩
新版本的功能包括:
1.支持简体中文和繁体中文字符;
2.支持转换到汉语拼音,通用拼音, 威妥玛拼音(威玛拼法),
注音符号第二式, 耶鲁拼法和国语罗马字;
3.支持多音字,即可以获取一个中文字符的多种发音;
4.支持多种字符串输出格式,比如支持Unicode格式的字符ü和声调符号(阴平
"ˉ",阳平"ˊ",上声"ˇ",去声"ˋ")的输出。
网站: http://pinyin4j.sourceforge.net/
简单写了个测试例子
package testcase;
import junit.framework.TestCase;
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import
net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import
net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
public class PinyinHelperTest extends TestCase {
public void testCNToPinYin() {
HanyuPinyinOutputFormat defaultFormat = new
HanyuPinyinOutputFormat();
//输出拼音全部小写
defaultFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
//不带声调
defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
try {
System.out.println((String)
PinyinHelper.toHanyuPinyinStringArray(
'鑫', defaultFormat)[0]);
System.out.println((String)
PinyinHelper.toTongyongPinyinStringArray('鑫')[0]);
System.out.println((String)
PinyinHelper.toWadeGilesPinyinStringArray('鑫')[0]);
System.out.println((String)
PinyinHelper.toYalePinyinStringArray('鑫')[0]);
} catch (BadHanyuPinyinOutputFormatCombination
e) {
e.printStackTrace();
}
}
}
顺便说一下,这东西支持多音字
1.在使用pinyin4j時.發現其對於某些字符的翻譯上..容易有失真的情況..
如"葉" ..一般羅馬拼音應該是"YEH' 或是"YE"但是這個專案的拼音會
將其預設翻譯為"XIE"..非"YEH"
2.這是目前使用後..覺的稍微不足的地方,不過中文字原本就比較複雜一點
3.HanyuPinyinOutputFormat提供了幾種輸出的模式
HanyuPinyinCaseType:設定輸出的結果是大寫英文字或是小寫英文字
LOWERCASE :小寫
UPPERCASE :大寫
HanyuPinyinToneType:輸出是否要標明重音及聲調
WITH_TONE_NUMBER:標明聲調 如YE1
1-4表示 1-4聲
WITHOUT_TONE:不顯示聲調符
HanyuPinyinVCharType :輸出是要用何種的拼音編碼
目前測試只有WITH_V 符合我的需求...
这里也有一些演示的截屏
转换到汉语拼音,通用拼音, 威妥玛拼音(威玛拼法), 注音符号第二式,
耶鲁拼法和国语罗马字
指定输出格式
支持繁体中文的转换
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。