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

http://blog.csdn.net/zhongweijian/article/details/8064676


在我们的系统中,可能经常需要按首字母排序一些信息(比如淘宝商城的品牌列表字母序排列),那么我们就需要一个能够根据汉字查询对应的拼音,取出拼音的首字母即可。

 

我们使用sourceforge.pinyin4j开源包来完成我们的功能。

 

使用很简单:

 

提供的工具类是下面这个PinyinHelper.java help类,里面有所有开放的API,有几个方法是对应转换成不同的拼音系统,关于拼音系统大家可以查看 http://wenku.baidu.com/view/28dda445b307e87101f696f9.html

 

[java]  view plain copy
  1. /** 
  2.  * This file is part of pinyin4j (http://sourceforge.net/projects/pinyin4j/)  
  3.  * and distributed under GNU GENERAL PUBLIC LICENSE (GPL). 
  4.  *  
  5.  * pinyin4j is free software; you can redistribute it and/or modify  
  6.  * it under the terms of the GNU General Public License as published by  
  7.  * the Free Software Foundation; either version 2 of the License, or  
  8.  * (at your option) any later version.  
  9.  *  
  10.  * pinyin4j is distributed in the hope that it will be useful,  
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of  
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
  13.  * GNU General Public License for more details.  
  14.  *  
  15.  * You should have received a copy of the GNU General Public License  
  16.  * along with pinyin4j. 
  17.  */  
  18.   
  19. package net.sourceforge.pinyin4j;  
  20.   
  21. import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;  
  22. import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;  
  23.   
  24. /** 
  25.  * A class provides several utility functions to convert Chinese characters 
  26.  * (both Simplified and Tranditional) into various Chinese Romanization 
  27.  * representations 
  28.  *  
  29.  * @author Li Min (xmlerlimin@gmail.com) 
  30.  */  
  31. public class PinyinHelper  
  32. {  
  33.     /** 
  34.      * Get all unformmatted Hanyu Pinyin presentations of a single Chinese 
  35.      * character (both Simplified and Tranditional) 
  36.      *  
  37.      * <p> 
  38.      * For example, <br/> If the input is '间', the return will be an array with 
  39.      * two Hanyu Pinyin strings: <br/> "jian1" <br/> "jian4" <br/> <br/> If the 
  40.      * input is '李', the return will be an array with single Hanyu Pinyin 
  41.      * string: <br/> "li3" 
  42.      *  
  43.      * <p> 
  44.      * <b>Special Note</b>: If the return is "none0", that means the input 
  45.      * Chinese character exists in Unicode CJK talbe, however, it has no 
  46.      * pronounciation in Chinese 
  47.      *  
  48.      * @param ch 
  49.      *            the given Chinese character 
  50.      *  
  51.      * @return a String array contains all unformmatted Hanyu Pinyin 
  52.      *         presentations with tone numbers; null for non-Chinese character 
  53.      *  
  54.      */  
  55.     static public String[] toHanyuPinyinStringArray(char ch)  
  56.     {  
  57.         return getUnformattedHanyuPinyinStringArray(ch);  
  58.     }  
  59.   
  60.     /** 
  61.      * Get all Hanyu Pinyin presentations of a single Chinese character (both 
  62.      * Simplified and Tranditional) 
  63.      *  
  64.      * <p> 
  65.      * For example, <br/> If the input is '间', the return will be an array with 
  66.      * two Hanyu Pinyin strings: <br/> "jian1" <br/> "jian4" <br/> <br/> If the 
  67.      * input is '李', the return will be an array with single Hanyu Pinyin 
  68.      * string: <br/> "li3" 
  69.      *  
  70.      * <p> 
  71.      * <b>Special Note</b>: If the return is "none0", that means the input 
  72.      * Chinese character is in Unicode CJK talbe, however, it has no 
  73.      * pronounciation in Chinese 
  74.      *  
  75.      * @param ch 
  76.      *            the given Chinese character 
  77.      * @param outputFormat 
  78.      *            describes the desired format of returned Hanyu Pinyin String 
  79.      *  
  80.      * @return a String array contains all Hanyu Pinyin presentations with tone 
  81.      *         numbers; return null for non-Chinese character 
  82.      *  
  83.      * @throws BadHanyuPinyinOutputFormatCombination 
  84.      *             if certain combination of output formats happens 
  85.      *  
  86.      * @see HanyuPinyinOutputFormat 
  87.      * @see BadHanyuPinyinOutputFormatCombination 
  88.      *  
  89.      */  
  90.     static public String[] toHanyuPinyinStringArray(char ch,  
  91.             HanyuPinyinOutputFormat outputFormat)  
  92.             throws BadHanyuPinyinOutputFormatCombination  
  93.     {  
  94.         return getFormattedHanyuPinyinStringArray(ch, outputFormat);  
  95.     }  
  96.   
  97.     /** 
  98.      * Return the formatted Hanyu Pinyin representations of the given Chinese 
  99.      * character (both in Simplified and Tranditional) in array format. 
  100.      *  
  101.      * @param ch 
  102.      *            the given Chinese character 
  103.      * @param outputFormat 
  104.      *            Describes the desired format of returned Hanyu Pinyin string 
  105.      * @return The formatted Hanyu Pinyin representations of the given codepoint 
  106.      *         in array format; null if no record is found in the hashtable. 
  107.      */  
  108.     static private String[] getFormattedHanyuPinyinStringArray(char ch,  
  109.             HanyuPinyinOutputFormat outputFormat)  
  110.             throws BadHanyuPinyinOutputFormatCombination  
  111.     {  
  112.         String[] pinyinStrArray = getUnformattedHanyuPinyinStringArray(ch);  
  113.   
  114.         if (null != pinyinStrArray)  
  115.         {  
  116.   
  117.             for (int i = 0; i < pinyinStrArray.length; i++)  
  118.             {  
  119.                 pinyinStrArray[i] = PinyinFormatter.formatHanyuPinyin(pinyinStrArray[i], outputFormat);  
  120.             }  
  121.   
  122.             return pinyinStrArray;  
  123.   
  124.         } else  
  125.             return null;  
  126.     }  
  127.   
  128.     /** 
  129.      * Delegate function 
  130.      *  
  131.      * @param ch 
  132.      *            the given Chinese character 
  133.      * @return unformatted Hanyu Pinyin strings; null if the record is not found 
  134.      */  
  135.     private static String[] getUnformattedHanyuPinyinStringArray(char ch)  
  136.     {  
  137.         return ChineseToPinyinResource.getInstance().getHanyuPinyinStringArray(ch);  
  138.     }  
  139.   
  140.     /** 
  141.      * Get all unformmatted Tongyong Pinyin presentations of a single Chinese 
  142.      * character (both Simplified and Tranditional) 
  143.      *  
  144.      * @param ch 
  145.      *            the given Chinese character 
  146.      *  
  147.      * @return a String array contains all unformmatted Tongyong Pinyin 
  148.      *         presentations with tone numbers; null for non-Chinese character 
  149.      *  
  150.      * @see #toHanyuPinyinStringArray(char) 
  151.      *  
  152.      */  
  153.     static public String[] toTongyongPinyinStringArray(char ch)  
  154.     {  
  155.         return convertToTargetPinyinStringArray(ch, PinyinRomanizationType.TONGYONG_PINYIN);  
  156.     }  
  157.   
  158.     /** 
  159.      * Get all unformmatted Wade-Giles presentations of a single Chinese 
  160.      * character (both Simplified and Tranditional) 
  161.      *  
  162.      * @param ch 
  163.      *            the given Chinese character 
  164.      *  
  165.      * @return a String array contains all unformmatted Wade-Giles presentations 
  166.      *         with tone numbers; null for non-Chinese character 
  167.      *  
  168.      * @see #toHanyuPinyinStringArray(char) 
  169.      *  
  170.      */  
  171.     static public String[] toWadeGilesPinyinStringArray(char ch)  
  172.     {  
  173.         return convertToTargetPinyinStringArray(ch, PinyinRomanizationType.WADEGILES_PINYIN);  
  174.     }  
  175.   
  176.     /** 
  177.      * Get all unformmatted MPS2 (Mandarin Phonetic Symbols 2) presentations of 
  178.      * a single Chinese character (both Simplified and Tranditional) 
  179.      *  
  180.      * @param ch 
  181.      *            the given Chinese character 
  182.      *  
  183.      * @return a String array contains all unformmatted MPS2 (Mandarin Phonetic 
  184.      *         Symbols 2) presentations with tone numbers; null for non-Chinese 
  185.      *         character 
  186.      *  
  187.      * @see #toHanyuPinyinStringArray(char) 
  188.      *  
  189.      */  
  190.     static public String[] toMPS2PinyinStringArray(char ch)  
  191.     {  
  192.         return convertToTargetPinyinStringArray(ch, PinyinRomanizationType.MPS2_PINYIN);  
  193.     }  
  194.   
  195.     /** 
  196.      * Get all unformmatted Yale Pinyin presentations of a single Chinese 
  197.      * character (both Simplified and Tranditional) 
  198.      *  
  199.      * @param ch 
  200.      *            the given Chinese character 
  201.      *  
  202.      * @return a String array contains all unformmatted Yale Pinyin 
  203.      *         presentations with tone numbers; null for non-Chinese character 
  204.      *  
  205.      * @see #toHanyuPinyinStringArray(char) 
  206.      *  
  207.      */  
  208.     static public String[] toYalePinyinStringArray(char ch)  
  209.     {  
  210.         return convertToTargetPinyinStringArray(ch, PinyinRomanizationType.YALE_PINYIN);  
  211.     }  
  212.   
  213.     /** 
  214.      * @param ch 
  215.      *            the given Chinese character 
  216.      * @param targetPinyinSystem 
  217.      *            indicates target Chinese Romanization system should be 
  218.      *            converted to 
  219.      * @return string representations of target Chinese Romanization system 
  220.      *         corresponding to the given Chinese character in array format; 
  221.      *         null if error happens 
  222.      *  
  223.      * @see PinyinRomanizationType 
  224.      */  
  225.     private static String[] convertToTargetPinyinStringArray(char ch,  
  226.             PinyinRomanizationType targetPinyinSystem)  
  227.     {  
  228.         String[] hanyuPinyinStringArray = getUnformattedHanyuPinyinStringArray(ch);  
  229.   
  230.         if (null != hanyuPinyinStringArray)  
  231.         {  
  232.             String[] targetPinyinStringArray = new String[hanyuPinyinStringArray.length];  
  233.   
  234.             for (int i = 0; i < hanyuPinyinStringArray.length; i++)  
  235.             {  
  236.                 targetPinyinStringArray[i] = PinyinRomanizationTranslator.convertRomanizationSystem(hanyuPinyinStringArray[i], PinyinRomanizationType.HANYU_PINYIN, targetPinyinSystem);  
  237.             }  
  238.   
  239.             return targetPinyinStringArray;  
  240.   
  241.         } else  
  242.             return null;  
  243.     }  
  244.   
  245.     /** 
  246.      * Get all unformmatted Gwoyeu Romatzyh presentations of a single Chinese 
  247.      * character (both Simplified and Tranditional) 
  248.      *  
  249.      * @param ch 
  250.      *            the given Chinese character 
  251.      *  
  252.      * @return a String array contains all unformmatted Gwoyeu Romatzyh 
  253.      *         presentations with tone numbers; null for non-Chinese character 
  254.      *  
  255.      * @see #toHanyuPinyinStringArray(char) 
  256.      *  
  257.      */  
  258.     static public String[] toGwoyeuRomatzyhStringArray(char ch)  
  259.     {  
  260.         return convertToGwoyeuRomatzyhStringArray(ch);  
  261.     }  
  262.   
  263.     /** 
  264.      * @param ch 
  265.      *            the given Chinese character 
  266.      *  
  267.      * @return Gwoyeu Romatzyh string representations corresponding to the given 
  268.      *         Chinese character in array format; null if error happens 
  269.      *  
  270.      * @see PinyinRomanizationType 
  271.      */  
  272.     private static String[] convertToGwoyeuRomatzyhStringArray(char ch)  
  273.     {  
  274.         String[] hanyuPinyinStringArray = getUnformattedHanyuPinyinStringArray(ch);  
  275.   
  276.         if (null != hanyuPinyinStringArray)  
  277.         {  
  278.             String[] targetPinyinStringArray = new String[hanyuPinyinStringArray.length];  
  279.   
  280.             for (int i = 0; i < hanyuPinyinStringArray.length; i++)  
  281.             {  
  282.                 targetPinyinStringArray[i] = GwoyeuRomatzyhTranslator.convertHanyuPinyinToGwoyeuRomatzyh(hanyuPinyinStringArray[i]);  
  283.             }  
  284.   
  285.             return targetPinyinStringArray;  
  286.   
  287.         } else  
  288.             return null;  
  289.     }  
  290.   
  291.     /** 
  292.      * Get a string which all Chinese characters are replaced by corresponding 
  293.      * main (first) Hanyu Pinyin representation. 
  294.      *  
  295.      * <p> 
  296.      * <b>Special Note</b>: If the return contains "none0", that means that 
  297.      * Chinese character is in Unicode CJK talbe, however, it has not 
  298.      * pronounciation in Chinese. <b> This interface will be removed in next 
  299.      * release. </b> 
  300.      *  
  301.      * @param str 
  302.      *            A given string contains Chinese characters 
  303.      * @param outputFormat 
  304.      *            Describes the desired format of returned Hanyu Pinyin string 
  305.      * @param seperater 
  306.      *            The string is appended after a Chinese character (excluding 
  307.      *            the last Chinese character at the end of sentence). <b>Note! 
  308.      *            Seperater will not appear after a non-Chinese character</b> 
  309.      * @return a String identical to the original one but all recognizable 
  310.      *         Chinese characters are converted into main (first) Hanyu Pinyin 
  311.      *         representation 
  312.      *  
  313.      * @deprecated DO NOT use it again because the first retrived pinyin string 
  314.      *             may be a wrong pronouciation in a certain sentence context. 
  315.      *             <b> This interface will be removed in next release. </b> 
  316.      */  
  317.     static public String toHanyuPinyinString(String str,  
  318.             HanyuPinyinOutputFormat outputFormat, String seperater)  
  319.             throws BadHanyuPinyinOutputFormatCombination  
  320.     {  
  321.   
  322.         StringBuffer resultPinyinStrBuf = new StringBuffer();  
  323.   
  324.         for (int i = 0; i < str.length(); i++)  
  325.         {  
  326.             String mainPinyinStrOfChar = getFirstHanyuPinyinString(str.charAt(i), outputFormat);  
  327.   
  328.             if (null != mainPinyinStrOfChar)  
  329.             {  
  330.                 resultPinyinStrBuf.append(mainPinyinStrOfChar);  
  331.                 if (i != str.length() - 1)  
  332.                 { // avoid appending at the end  
  333.                     resultPinyinStrBuf.append(seperater);  
  334.                 }  
  335.             } else  
  336.             {  
  337.                 resultPinyinStrBuf.append(str.charAt(i));  
  338.             }  
  339.         }  
  340.   
  341.         return resultPinyinStrBuf.toString();  
  342.     }  
  343.   
  344.     /** 
  345.      * Get the first Hanyu Pinyin of a Chinese character <b> This function will 
  346.      * be removed in next release. </b> 
  347.      *  
  348.      * @param ch 
  349.      *            The given Unicode character 
  350.      * @param outputFormat 
  351.      *            Describes the desired format of returned Hanyu Pinyin string 
  352.      * @return Return the first Hanyu Pinyin of given Chinese character; return 
  353.      *         null if the input is not a Chinese character 
  354.      *  
  355.      * @deprecated DO NOT use it again because the first retrived pinyin string 
  356.      *             may be a wrong pronouciation in a certain sentence context. 
  357.      *             <b> This function will be removed in next release. </b> 
  358.      */  
  359.     static private String getFirstHanyuPinyinString(char ch,  
  360.             HanyuPinyinOutputFormat outputFormat)  
  361.             throws BadHanyuPinyinOutputFormatCombination  
  362.     {  
  363.         String[] pinyinStrArray = getFormattedHanyuPinyinStringArray(ch, outputFormat);  
  364.   
  365.         if ((null != pinyinStrArray) && (pinyinStrArray.length > 0))  
  366.         {  
  367.             return pinyinStrArray[0];  
  368.         } else  
  369.         {  
  370.             return null;  
  371.         }  
  372.     }  
  373.   
  374.     // ! Hidden constructor  
  375.     private PinyinHelper()  
  376.     {  
  377.     }  
  378. }  

拼音系统列表如下:

[java]  view plain copy
  1. /** 
  2.  * This file is part of pinyin4j (http://sourceforge.net/projects/pinyin4j/)  
  3.  * and distributed under GNU GENERAL PUBLIC LICENSE (GPL). 
  4.  *  
  5.  * pinyin4j is free software; you can redistribute it and/or modify  
  6.  * it under the terms of the GNU General Public License as published by  
  7.  * the Free Software Foundation; either version 2 of the License, or  
  8.  * (at your option) any later version.  
  9.  *  
  10.  * pinyin4j is distributed in the hope that it will be useful,  
  11.  * but WITHOUT ANY WARRANTY; without even the implied warranty of  
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
  13.  * GNU General Public License for more details.  
  14.  *  
  15.  * You should have received a copy of the GNU General Public License  
  16.  * along with pinyin4j. 
  17.  */  
  18.   
  19. /** 
  20.  *  
  21.  */  
  22. package net.sourceforge.pinyin4j;  
  23.   
  24. /** 
  25.  * The class describes variable Chinese Pinyin Romanization System 
  26.  *  
  27.  * @author Li Min (xmlerlimin@gmail.com) 
  28.  *  
  29.  */  
  30. class PinyinRomanizationType  
  31. {  
  32.     /** 
  33.      * Hanyu Pinyin system 
  34.      */  
  35.     static final PinyinRomanizationType HANYU_PINYIN = new PinyinRomanizationType("Hanyu");  
  36.   
  37.     /** 
  38.      * Wade-Giles Pinyin system 
  39.      */  
  40.     static final PinyinRomanizationType WADEGILES_PINYIN = new PinyinRomanizationType("Wade");  
  41.   
  42.     /** 
  43.      * Mandarin Phonetic Symbols 2 (MPS2) Pinyin system 
  44.      */  
  45.     static final PinyinRomanizationType MPS2_PINYIN = new PinyinRomanizationType("MPSII");  
  46.   
  47.     /** 
  48.      * Yale Pinyin system 
  49.      */  
  50.     static final PinyinRomanizationType YALE_PINYIN = new PinyinRomanizationType("Yale");  
  51.   
  52.     /** 
  53.      * Tongyong Pinyin system 
  54.      */  
  55.     static final PinyinRomanizationType TONGYONG_PINYIN = new PinyinRomanizationType("Tongyong");  
  56.   
  57.     /** 
  58.      * Gwoyeu Romatzyh system 
  59.      */  
  60.     static final PinyinRomanizationType GWOYEU_ROMATZYH = new PinyinRomanizationType("Gwoyeu");  
  61.   
  62.     /** 
  63.      * Constructor 
  64.      */  
  65.     protected PinyinRomanizationType(String tagName)  
  66.     {  
  67.         setTagName(tagName);  
  68.     }  
  69.   
  70.     /** 
  71.      * @return Returns the tagName. 
  72.      */  
  73.     String getTagName()  
  74.     {  
  75.         return tagName;  
  76.     }  
  77.   
  78.     /** 
  79.      * @param tagName 
  80.      *            The tagName to set. 
  81.      */  
  82.     protected void setTagName(String tagName)  
  83.     {  
  84.         this.tagName = tagName;  
  85.     }  
  86.   
  87.     protected String tagName;  
  88. }  

我们使用的API demo如下:


[java]  view plain copy
  1. package demo;  
  2.   
  3. import net.sourceforge.pinyin4j.PinyinHelper;  
  4. import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;  
  5. import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;  
  6. import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;  
  7. import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;  
  8. import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;  
  9.   
  10. public class MyPinyinDemo {  
  11.   
  12.     /** 
  13.      * @param args 
  14.      * @throws BadHanyuPinyinOutputFormatCombination  
  15.      */  
  16.     public static void main(String[] args) throws BadHanyuPinyinOutputFormatCombination {  
  17.         char chineseCharacter = "绿".charAt(0);  
  18.         HanyuPinyinOutputFormat outputFormat = new HanyuPinyinOutputFormat();  
  19.         outputFormat.setToneType(HanyuPinyinToneType.WITH_TONE_NUMBER); // 输出的声调为数字:第一声为1,第二声为2,第三声为3,第四声为4 如:lu:4  
  20. //      outputFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); // 输出拼音不带声调 如:lu:  
  21. //      outputFormat.setToneType(HanyuPinyinToneType.WITH_TONE_MARK); // 输出声调在拼音字母上 如:lǜ  
  22.         outputFormat.setVCharType(HanyuPinyinVCharType.WITH_U_AND_COLON); //ǜ的输出格式设置  'ü' 输出为 "u:"  
  23. //      outputFormat.setVCharType(HanyuPinyinVCharType.WITH_U_UNICODE); //ǜ的输出格式设置  'ü' 输出为 "ü" in Unicode form  
  24. //      outputFormat.setVCharType(HanyuPinyinVCharType.WITH_V); //ǜ的输出格式设置  'ü' 输出为 "v"  
  25.         outputFormat.setCaseType(HanyuPinyinCaseType.UPPERCASE); //输出拼音为大写  
  26. //      outputFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE); //输出拼音为小写  
  27.         String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(chineseCharacter, outputFormat); //汉字拼音  
  28.         for(String str: pinyinArray){ //多音字输出,会返回多音字的格式  
  29.             System.out.println(str);  
  30.         }  
  31.           
  32.         String pinyinstr = PinyinHelper.toHanyuPinyinString("绿色", outputFormat, "|");  
  33.         System.out.println(pinyinstr);  
  34.           
  35.           
  36.         //其他拼音系统的输出  
  37.           
  38.         String[] GwoyeuRomatzyhStringArray = PinyinHelper.toGwoyeuRomatzyhStringArray(chineseCharacter);  
  39.         for(String str: GwoyeuRomatzyhStringArray){ //多音字输出,会返回多音字的格式  
  40.             System.out.println(str);  
  41.         }  
  42.           
  43.         String[] MPS2PinyinStringArray = PinyinHelper.toMPS2PinyinStringArray(chineseCharacter);  
  44.         for(String str: MPS2PinyinStringArray){ //多音字输出,会返回多音字的格式  
  45.             System.out.println(str);  
  46.         }  
  47.           
  48.         String[] TongyongPinyinStringArray = PinyinHelper.toTongyongPinyinStringArray(chineseCharacter);  
  49.         for(String str: TongyongPinyinStringArray){ //多音字输出,会返回多音字的格式  
  50.             System.out.println(str);  
  51.         }  
  52.           
  53.         String[] WadeGilesPinyinStringArray = PinyinHelper.toWadeGilesPinyinStringArray(chineseCharacter);  
  54.         for(String str: WadeGilesPinyinStringArray){ //多音字输出,会返回多音字的格式  
  55.             System.out.println(str);  
  56.         }  
  57.           
  58.         String[] YalePinyinStringArray = PinyinHelper.toYalePinyinStringArray(chineseCharacter);  
  59.         for(String str: YalePinyinStringArray){ //多音字输出,会返回多音字的格式  
  60.             System.out.println(str);  
  61.         }  
  62.           
  63.     }  
  64.   
  65. }  

输出:

[html]  view plain copy
  1. LU:4  
  2. LU4  
  3. LU:4|SE4  
  4. liuh  
  5. luh  
  6. liu4  
  7. lu4  
  8. lyu4  
  9. lu4  
  10. lu:4  
  11. lu4  
  12. lyu4  
  13. lu4  

这个拼音包里还自带了一个demo, Pinyin4jAppletDemo.java

 

 

至于实现,其实很简单,就是有一个词典,汉字跟拼音的对应关系文件词典,unicode_to_hanyu_pinyin.txt是汉字的unicode字符对应的拼音对应表,pinyin_mapping.xml是汉语拼音系统跟其他系统的对照表,pinyin_Gwoyeu_mapping.xml是汉语系统跟Gwoyeu拼音系统的对照列表。格式参考如下,其实整理完这些之后就很容易实现了。

 


[html]  view plain copy
  1. <?xml version="1.0"?>  
  2. <pinyin_mapping>  
  3.  <item>  
  4.   <Hanyu>a</Hanyu>  
  5.   <Wade>a</Wade>  
  6.   <MPSII>a</MPSII>  
  7.   <Yale>a</Yale>  
  8.   <Tongyong>a</Tongyong>  
  9.  </item>  
  10.  <item>  
  11.   <Hanyu>ai</Hanyu>  
  12.   <Wade>ai</Wade>  
  13.   <MPSII>ai</MPSII>  
  14.   <Yale>ai</Yale>  
  15.   <Tongyong>ai</Tongyong>  
  16.  </item>  

[html]  view plain copy
  1. <pinyin_gwoyeu_mapping>  
  2.  <item>  
  3.   <Hanyu>a</Hanyu>  
  4.   <Gwoyeu_I>a</Gwoyeu_I>  
  5.   <Gwoyeu_II>ar</Gwoyeu_II>  
  6.   <Gwoyeu_III>aa</Gwoyeu_III>  
  7.   <Gwoyeu_IV>ah</Gwoyeu_IV>  
  8.   <Gwoyeu_V>.a</Gwoyeu_V>  
  9.  </item>  
  10.  <item>  
  11.   <Hanyu>ai</Hanyu>  
  12.   <Gwoyeu_I>ai</Gwoyeu_I>  
  13.   <Gwoyeu_II>air</Gwoyeu_II>  
  14.   <Gwoyeu_III>ae</Gwoyeu_III>  
  15.   <Gwoyeu_IV>ay</Gwoyeu_IV>  
  16.   <Gwoyeu_V>.ai</Gwoyeu_V>  
  17.  </item>  

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值