/** * @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); } }
/** * convert the given unformatted Pinyin string from source Romanization * system to target Romanization system * * @param sourcePinyinStr * the given unformatted Pinyin string * @param sourcePinyinSystem * the Romanization system which is currently used by the given * unformatted Pinyin string * @param targetPinyinSystem * the Romanization system that should be converted to * @return unformatted Pinyin string in target Romanization system; null if * error happens */ public static String convertRomanizationSystem(String sourcePinyinStr, PinyinRomanizationType sourcePinyinSystem, PinyinRomanizationType targetPinyinSystem) { String pinyinString = TextHelper.extractPinyinString(sourcePinyinStr); String toneNumberStr = TextHelper.extractToneNumber(sourcePinyinStr); // return value String targetPinyinStr = null; try { // find the node of source Pinyin system String xpathQuery1 = "//" + sourcePinyinSystem.getTagName() + "[text()='" + pinyinString + "']"; XmlDocument pinyinMappingDoc = PinyinRomanizationResource.getInstance().getPinyinMappingDoc(); XmlNode hanyuNode = pinyinMappingDoc.SelectSingleNode(xpathQuery1); if (null != hanyuNode) { // find the node of target Pinyin system String xpathQuery2 = "../" + targetPinyinSystem.getTagName() + "/text()"; String targetPinyinStrWithoutToneNumber = hanyuNode.SelectSingleNode(xpathQuery2).Value; targetPinyinStr = targetPinyinStrWithoutToneNumber + toneNumberStr; } } catch (Exception e) { Util.Log(e); } return(targetPinyinStr); }
/** * @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; }