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

2014-11-24 09:46:32 · 作者: · 浏览: 1
HanyuPinyinOutputFormat outputFormat)
throws BadHanyuPinyinOutputFormatCombination
{
return getFormattedHanyuPinyinStringArray(ch, outputFormat);
}

/**
* Return the formatted Hanyu Pinyin representations of the given Chinese
* character (both in Simplified and Tranditional) in array format.
*
* @param ch
* the given Chinese character
* @param outputFormat
* Describes the desired format of returned Hanyu Pinyin string
* @return The formatted Hanyu Pinyin representations of the given codepoint
* in array format; null if no record is found in the hashtable.
*/
static private String[] getFormattedHanyuPinyinStringArray(char ch,
HanyuPinyinOutputFormat outputFormat)
throws BadHanyuPinyinOutputFormatCombination
{
String[] pinyinStrArray = getUnformattedHanyuPinyinStringArray(ch);

if (null != pinyinStrArray)
{

for (int i = 0; i < pinyinStrArray.length; i++)
{
pinyinStrArray[i] = PinyinFormatter.formatHanyuPinyin(pinyinStrArray[i], outputFormat);
}

return pinyinStrArray;

} else
return null;
}

/**
* Delegate function
*
* @param ch
* the given Chinese character
* @return unformatted Hanyu Pinyin strings; null if the record is not found
*/
private static String[] getUnformattedHanyuPinyinStringArray(char ch)
{
return ChineseToPinyinResource.getInstance().getHanyuPinyinStringArray(ch);
}

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

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

/**
* Get all unformmatted MPS2 (Mandarin Phonetic Symbols 2) presentations of
* a single Chinese character (both Simplified and Tranditional)
*
* @param ch
* the given Chinese character
*
* @return a String array contains all unformmatted MPS2 (Mandarin Phonetic
* Symbols 2) presentations with tone numbers; null for non-Chinese
* character
*
* @see #toHanyuPinyinStringArray(char)
*
*/
static public String[] toMPS2PinyinStringArray(char ch)
{
return convertToTargetPin