2013年(92)
分类: 信息化
2013-03-04 05:30:58
[代码] [Java]代码 package quartz; import java.util.ArrayList; import java.util.List; import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; import net.sourceforge.pinyin4j.format.HanyuPinyinToneType; import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType; /** * 多个汉字转换成拼音、有多音时组成不一样的拼音组合 * @author CheWenliang * */ public class CoverHanZiToPinY { private static List pinyinList = new ArrayList(); public static void main(String[] args) { coverChineseToPinYin("车文亮"); for(String str : pinyinList){ System.out.println(str); } } // public static void coverChineseToPinYin(String chinese){ char[] ch = chinese.toCharArray(); Listlist = new ArrayList
(); HanyuPinyinOutputFormat defaultFormat = new HanyuPinyinOutputFormat(); //设置是用“U”仍是用“V”,这里为"V" defaultFormat.setVCharType(HanyuPinyinVCharType.WITH_V); //能否腔调腔调,这里操控不输出腔调 // defaultFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE); for(char c : ch){ List listC = new ArrayList(); String[] pinyinHead = PinyinHelper.toHanyuPinyinStringArray(c, defaultFormat); for(String strP : pinyinHead){ listC.add(strP); } list.add(listC); } //递归调用办法 combine(list); } //组合,组合成不一样的拼音,递归调用 ,直到list里只要一个停止 public static void combine(List
list){ if(list.size()>=2){ List strA1 = list.get(0); List strA2 = list.get(1); List comBL = new ArrayList(); if(strA1.size()>0