java 使用sourceforge.pinyin4j查询汉字拼音(三)

2014-11-24 09:46:32 · 作者: · 浏览: 6
yinStringArray(ch, PinyinRomanizationType.MPS2_PINYIN);
}

/**
* Get all unformmatted Yale Pinyin presentations of a single Chinese
* character (both Simplified and Tranditional)
*
* @param ch
* the given Chinese character
*
* @return a String array contains all unformmatted Yale Pinyin
* presentations with tone numbers; null for non-Chinese character
*
* @see #toHanyuPinyinStringArray(char)
*
*/
static public String[] toYalePinyinStringArray(char ch)
{
return convertToTargetPinyinStringArray(ch, PinyinRomanizationType.YALE_PINYIN);
}

/**
* @param ch
* the given Chinese character
* @param targetPinyinSystem
* indicates target Chinese Romanization system should be
* converted to
* @return string representations of target Chinese Romanization system
* corresponding to the given Chinese character in array format;
* null if error happens
*
* @see PinyinRomanizationType
*/
private static String[] convertToTargetPinyinStringArray(char ch,
PinyinRomanizationType targetPinyinSystem)
{
String[] hanyuPinyinStringArray = getUnformattedHanyuPinyinStringArray(ch);

if (null != hanyuPinyinStringArray)
{
String[] targetPinyinStringArray = new String[hanyuPinyinStringArray.length];

for (int i = 0; i < hanyuPinyinStringArray.length; i++)
{
targetPinyinStringArray[i] = PinyinRomanizationTranslator.convertRomanizationSystem(hanyuPinyinStringArray[i], PinyinRomanizationType.HANYU_PINYIN, targetPinyinSystem);
}

return targetPinyinStringArray;

} else
return null;
}

/**
* Get all unformmatted Gwoyeu Romatzyh presentations of a single Chinese
* character (both Simplified and Tranditional)
*
* @param ch
* the given Chinese character
*
* @return a String array contains all unformmatted Gwoyeu Romatzyh
* presentations with tone numbers; null for non-Chinese character
*
* @see #toHanyuPinyinStringArray(char)
*
*/
static public String[] toGwoyeuRomatzyhStringArray(char ch)
{
return convertToGwoyeuRomatzyhStringArray(ch);
}

/**
* @param ch
* the given Chinese character
*
* @return Gwoyeu Romatzyh string representations corresponding to the given
* Chinese character in array format; null if error happens
*
* @see PinyinRomanizationType
*/
private static String[] convertToGwoyeuRomatzyhStringArray(char ch)
{
String[] hanyuPinyinStringArray = getUnformattedHanyuPinyinStringArray(ch);

if (null != hanyuPinyinStringArray)
{
String[] targetPinyinStringArray = new String[hanyuPinyinStringArray.length];

for (int i = 0; i < hanyuPinyinStringArray.length; i++)
{
targetPinyinStringArray[i] = GwoyeuRomatzyhTranslator.convertHanyuPinyinToGwoyeuRomatzyh(hanyuPinyinStringArray[i]);
}

return targetPinyinStringArray;

} else
return null;
}

/**
* Get a string which all Chinese characters are replaced by corresponding
* main (first) Hanyu Piny