仓酷云

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1080|回复: 20
打印 上一主题 下一主题

[学习教程] JAVA教程之用Java转化汉字为拼音全拼

[复制链接]
萌萌妈妈 该用户已被删除
跳转到指定楼层
楼主
发表于 2015-1-18 11:41:58 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
Java到底会发战成什么样,让我们拭目以待吧,我始终坚信着java会更好。以上都是俺个人看法,欢迎大家一起交流.汉字|拼音packagecom.easydozer.commons.util;

importjava.util.Iterator;
importjava.util.LinkedHashMap;
importjava.util.Set;

/**
*<pre>汉字转化为全拼</pre>
*<BR><DL><DT><B>JDK版本:</B></DT><BR><DD>1.4</DD></DL>
*@author谢计生
*@version1.0
*@see
*@since1.0
*/
publicclassCnToSpell
{
privatestaticLinkedHashMapspellMap=null;

static
{
if(spellMap==null){
spellMap=newLinkedHashMap(400);
}
initialize();
System.out.println("ChinesetransferSpellDone.");
}

privateCnToSpell()
{
}

privatestaticvoidspellPut(Stringspell,intascii)
{
spellMap.put(spell,newInteger(ascii));
}

privatestaticvoidinitialize()
{
spellPut("a",-20319);
spellPut("ai",-20317);
spellPut("an",-20304);
spellPut("ang",-20295);
spellPut("ao",-20292);
spellPut("ba",-20283);
spellPut("bai",-20265);
spellPut("ban",-20257);
spellPut("bang",-20242);
spellPut("bao",-20230);
spellPut("bei",-20051);
spellPut("ben",-20036);
spellPut("beng",-20032);
spellPut("bi",-20026);
spellPut("bian",-20002);
spellPut("biao",-19990);
spellPut("bie",-19986);
spellPut("bin",-19982);
spellPut("bing",-19976);
spellPut("bo",-19805);
spellPut("bu",-19784);
spellPut("ca",-19775);
spellPut("cai",-19774);
spellPut("can",-19763);
spellPut("cang",-19756);
spellPut("cao",-19751);
spellPut("ce",-19746);
spellPut("ceng",-19741);
spellPut("cha",-19739);
spellPut("chai",-19728);
spellPut("chan",-19725);
spellPut("chang",-19715);
spellPut("chao",-19540);
spellPut("che",-19531);
spellPut("chen",-19525);
spellPut("cheng",-19515);
spellPut("chi",-19500);
spellPut("chong",-19484);
spellPut("chou",-19479);
spellPut("chu",-19467);
spellPut("chuai",-19289);
spellPut("chuan",-19288);
spellPut("chuang",-19281);
spellPut("chui",-19275);
spellPut("chun",-19270);
spellPut("chuo",-19263);
spellPut("ci",-19261);
spellPut("cong",-19249);
spellPut("cou",-19243);
spellPut("cu",-19242);
spellPut("cuan",-19238);
spellPut("cui",-19235);
spellPut("cun",-19227);
spellPut("cuo",-19224);
spellPut("da",-19218);
spellPut("dai",-19212);
spellPut("dan",-19038);
spellPut("dang",-19023);
spellPut("dao",-19018);
spellPut("de",-19006);
spellPut("deng",-19003);
spellPut("di",-18996);
spellPut("dian",-18977);
spellPut("diao",-18961);
spellPut("die",-18952);
spellPut("ding",-18783);
spellPut("diu",-18774);
spellPut("dong",-18773);
spellPut("dou",-18763);
spellPut("du",-18756);
spellPut("duan",-18741);
spellPut("dui",-18735);
spellPut("dun",-18731);
spellPut("duo",-18722);
spellPut("e",-18710);
spellPut("en",-18697);
spellPut("er",-18696);
spellPut("fa",-18526);
spellPut("fan",-18518);
spellPut("fang",-18501);
spellPut("fei",-18490);
spellPut("fen",-18478);
spellPut("feng",-18463);
spellPut("fo",-18448);
spellPut("fou",-18447);
spellPut("fu",-18446);
spellPut("ga",-18239);
spellPut("gai",-18237);
spellPut("gan",-18231);
spellPut("gang",-18220);
spellPut("gao",-18211);
spellPut("ge",-18201);
spellPut("gei",-18184);
spellPut("gen",-18183);
spellPut("geng",-18181);
spellPut("gong",-18012);
spellPut("gou",-17997);
spellPut("gu",-17988);
spellPut("gua",-17970);
spellPut("guai",-17964);
spellPut("guan",-17961);
spellPut("guang",-17950);
spellPut("gui",-17947);
spellPut("gun",-17931);
spellPut("guo",-17928);
spellPut("ha",-17922);
spellPut("hai",-17759);
spellPut("han",-17752);
spellPut("hang",-17733);
spellPut("hao",-17730);
spellPut("he",-17721);
spellPut("hei",-17703);
spellPut("hen",-17701);
spellPut("heng",-17697);
spellPut("hong",-17692);
spellPut("hou",-17683);
spellPut("hu",-17676);
spellPut("hua",-17496);
spellPut("huai",-17487);
spellPut("huan",-17482);
spellPut("huang",-17468);
spellPut("hui",-17454);
spellPut("hun",-17433);
spellPut("huo",-17427);
spellPut("ji",-17417);
spellPut("jia",-17202);
spellPut("jian",-17185);
spellPut("jiang",-16983);
spellPut("jiao",-16970);
spellPut("jie",-16942);
spellPut("jin",-16915);
spellPut("jing",-16733);
spellPut("jiong",-16708);
spellPut("jiu",-16706);
spellPut("ju",-16689);
spellPut("juan",-16664);
spellPut("jue",-16657);
spellPut("jun",-16647);
spellPut("ka",-16474);
spellPut("kai",-16470);
spellPut("kan",-16465);
spellPut("kang",-16459);
spellPut("kao",-16452);
spellPut("ke",-16448);
spellPut("ken",-16433);
spellPut("keng",-16429);
spellPut("kong",-16427);
spellPut("kou",-16423);
spellPut("ku",-16419);
spellPut("kua",-16412);
spellPut("kuai",-16407);
spellPut("kuan",-16403);
spellPut("kuang",-16401);
spellPut("kui",-16393);
spellPut("kun",-16220);
spellPut("kuo",-16216);
spellPut("la",-16212);
spellPut("lai",-16205);
spellPut("lan",-16202);
spellPut("lang",-16187);
spellPut("lao",-16180);
spellPut("le",-16171);
spellPut("lei",-16169);
spellPut("leng",-16158);
spellPut("li",-16155);
spellPut("lia",-15959);
spellPut("lian",-15958);
spellPut("liang",-15944);
spellPut("liao",-15933);
spellPut("lie",-15920);
spellPut("lin",-15915);
spellPut("ling",-15903);
spellPut("liu",-15889);
spellPut("long",-15878);
spellPut("lou",-15707);
spellPut("lu",-15701);
spellPut("lv",-15681);
spellPut("luan",-15667);
spellPut("lue",-15661);
spellPut("lun",-15659);
spellPut("luo",-15652);
spellPut("ma",-15640);
spellPut("mai",-15631);
spellPut("man",-15625);
spellPut("mang",-15454);
spellPut("mao",-15448);
spellPut("me",-15436);
spellPut("mei",-15435);
spellPut("men",-15419);
spellPut("meng",-15416);
spellPut("mi",-15408);
spellPut("mian",-15394);
spellPut("miao",-15385);
spellPut("mie",-15377);
spellPut("min",-15375);
spellPut("ming",-15369);
spellPut("miu",-15363);
spellPut("mo",-15362);
spellPut("mou",-15183);
spellPut("mu",-15180);
spellPut("na",-15165);
spellPut("nai",-15158);
spellPut("nan",-15153);
spellPut("nang",-15150);
spellPut("nao",-15149);
spellPut("ne",-15144);
spellPut("nei",-15143);
spellPut("nen",-15141);
spellPut("neng",-15140);
spellPut("ni",-15139);
spellPut("nian",-15128);
spellPut("niang",-15121);
spellPut("niao",-15119);
spellPut("nie",-15117);
spellPut("nin",-15110);
spellPut("ning",-15109);
spellPut("niu",-14941);
spellPut("nong",-14937);
spellPut("nu",-14933);
spellPut("nv",-14930);
spellPut("nuan",-14929);
spellPut("nue",-14928);
spellPut("nuo",-14926);
spellPut("o",-14922);
spellPut("ou",-14921);
spellPut("pa",-14914);
spellPut("pai",-14908);
spellPut("pan",-14902);
spellPut("pang",-14894);
spellPut("pao",-14889);
spellPut("pei",-14882);
spellPut("pen",-14873);
spellPut("peng",-14871);
spellPut("pi",-14857);
spellPut("pian",-14678);
spellPut("piao",-14674);
spellPut("pie",-14670);
spellPut("pin",-14668);
spellPut("ping",-14663);
spellPut("po",-14654);
spellPut("pu",-14645);
spellPut("qi",-14630);
spellPut("qia",-14594);
spellPut("qian",-14429);
spellPut("qiang",-14407);
spellPut("qiao",-14399);
spellPut("qie",-14384);
spellPut("qin",-14379);
spellPut("qing",-14368);
spellPut("qiong",-14355);
spellPut("qiu",-14353);
spellPut("qu",-14345);
spellPut("quan",-14170);
spellPut("que",-14159);
spellPut("qun",-14151);
spellPut("ran",-14149);
spellPut("rang",-14145);
spellPut("rao",-14140);
spellPut("re",-14137);
spellPut("ren",-14135);
spellPut("reng",-14125);
spellPut("ri",-14123);
spellPut("rong",-14122);
spellPut("rou",-14112);
spellPut("ru",-14109);
spellPut("ruan",-14099);
spellPut("rui",-14097);
spellPut("run",-14094);
spellPut("ruo",-14092);
spellPut("sa",-14090);
spellPut("sai",-14087);
spellPut("san",-14083);
spellPut("sang",-13917);
spellPut("sao",-13914);
spellPut("se",-13910);
spellPut("sen",-13907);
spellPut("seng",-13906);
spellPut("sha",-13905);
spellPut("shai",-13896);
spellPut("shan",-13894);
spellPut("shang",-13878);
spellPut("shao",-13870);
spellPut("she",-13859);
spellPut("shen",-13847);
spellPut("sheng",-13831);
spellPut("shi",-13658);
spellPut("shou",-13611);
spellPut("shu",-13601);
spellPut("shua",-13406);
spellPut("shuai",-13404);
spellPut("shuan",-13400);
spellPut("shuang",-13398);
spellPut("shui",-13395);
spellPut("shun",-13391);
spellPut("shuo",-13387);
spellPut("si",-13383);
spellPut("song",-13367);
spellPut("sou",-13359);
spellPut("su",-13356);
spellPut("suan",-13343);
spellPut("sui",-13340);
spellPut("sun",-13329);
spellPut("suo",-13326);
spellPut("ta",-13318);
spellPut("tai",-13147);
spellPut("tan",-13138);
spellPut("tang",-13120);
spellPut("tao",-13107);
spellPut("te",-13096);
spellPut("teng",-13095);
spellPut("ti",-13091);
spellPut("tian",-13076);
spellPut("tiao",-13068);
spellPut("tie",-13063);
spellPut("ting",-13060);
spellPut("tong",-12888);
spellPut("tou",-12875);
spellPut("tu",-12871);
spellPut("tuan",-12860);
spellPut("tui",-12858);
spellPut("tun",-12852);
spellPut("tuo",-12849);
spellPut("wa",-12838);
spellPut("wai",-12831);
spellPut("wan",-12829);
spellPut("wang",-12812);
spellPut("wei",-12802);
spellPut("wen",-12607);
spellPut("weng",-12597);
spellPut("wo",-12594);
spellPut("wu",-12585);
spellPut("xi",-12556);
spellPut("xia",-12359);
spellPut("xian",-12346);
spellPut("xiang",-12320);
spellPut("xiao",-12300);
spellPut("xie",-12120);
spellPut("xin",-12099);
spellPut("xing",-12089);
spellPut("xiong",-12074);
spellPut("xiu",-12067);
spellPut("xu",-12058);
spellPut("xuan",-12039);
spellPut("xue",-11867);
spellPut("xun",-11861);
spellPut("ya",-11847);
spellPut("yan",-11831);
spellPut("yang",-11798);
spellPut("yao",-11781);
spellPut("ye",-11604);
spellPut("yi",-11589);
spellPut("yin",-11536);
spellPut("ying",-11358);
spellPut("yo",-11340);
spellPut("yong",-11339);
spellPut("you",-11324);
spellPut("yu",-11303);
spellPut("yuan",-11097);
spellPut("yue",-11077);
spellPut("yun",-11067);
spellPut("za",-11055);
spellPut("zai",-11052);
spellPut("zan",-11045);
spellPut("zang",-11041);
spellPut("zao",-11038);
spellPut("ze",-11024);
spellPut("zei",-11020);
spellPut("zen",-11019);
spellPut("zeng",-11018);
spellPut("zha",-11014);
spellPut("zhai",-10838);
spellPut("zhan",-10832);
spellPut("zhang",-10815);
spellPut("zhao",-10800);
spellPut("zhe",-10790);
spellPut("zhen",-10780);
spellPut("zheng",-10764);
spellPut("zhi",-10587);
spellPut("zhong",-10544);
spellPut("zhou",-10533);
spellPut("zhu",-10519);
spellPut("zhua",-10331);
spellPut("zhuai",-10329);
spellPut("zhuan",-10328);
spellPut("zhuang",-10322);
spellPut("zhui",-10315);
spellPut("zhun",-10309);
spellPut("zhuo",-10307);
spellPut("zi",-10296);
spellPut("zong",-10281);
spellPut("zou",-10274);
spellPut("zu",-10270);
spellPut("zuan",-10262);
spellPut("zui",-10260);
spellPut("zun",-10256);
spellPut("zuo",-10254);
}

/**
*取得单个汉字的Ascii.
*@paramcnchar
*汉字字符
*@returnint
*毛病前往0,不然前往ascii
*/
publicstaticintgetCnAscii(charcn)
{
byte[]bytes=(String.valueOf(cn)).getBytes();
if(bytes==null||bytes.length>2||bytes.length<=0){//毛病
return0;
}
if(bytes.length==1){//英笔墨符
returnbytes[0];
}
if(bytes.length==2){//中笔墨符
inthightByte=256+bytes[0];
intlowByte=256+bytes[1];

intascii=(256*hightByte+lowByte)-256*256;

//System.out.println("ASCII="+ascii);

returnascii;
}

return0;//毛病
}

/**
*依据ASCII码到SpellMap中查找对应的拼音
*@paramasciiint
*字符对应的ASCII
*@returnString
*拼音,起首判别ASCII是不是>0&<160,假如是前往对应的字符,
*<BR>不然到SpellMap中查找,假如没有找到拼音,则前往null,假如找到则前往拼音.
*/
publicstaticStringgetSpellByAscii(intascii)
{
if(ascii>0&&ascii<160){//单字符
returnString.valueOf((char)ascii);
}

if(ascii<-20319||ascii>-10247){//不晓得的字符
returnnull;
}

SetkeySet=spellMap.keySet();
Iteratorit=keySet.iterator();

Stringspell0=null;;
Stringspell=null;

intasciiRang0=-20319;
intasciiRang;
while(it.hasNext()){

spell=(String)it.next();
ObjectvalObj=spellMap.get(spell);
if(valObjinstanceofInteger){
asciiRang=((Integer)valObj).intValue();

if(ascii>=asciiRang0&&ascii<asciiRang){//区间找到
return(spell0==null)?spell:spell0;
}
else{
spell0=spell;
asciiRang0=asciiRang;
}
}
}

returnnull;

}

/**
*前往字符串的全拼,是汉字转化为全拼,别的字符不举行转换
*@paramcnStrString
*字符串
*@returnString
*转换玉成拼后的字符串
*/
publicstaticStringgetFullSpell(StringcnStr)
{
if(null==cnStr||"".equals(cnStr.trim())){
returncnStr;
}

char[]chars=cnStr.toCharArray();
StringBufferretuBuf=newStringBuffer();
for(inti=0,Len=chars.length;i<Len;i++){
intascii=getCnAscii(chars[i]);
if(ascii==0){//取ascii时堕落
retuBuf.append(chars[i]);
}
else{
Stringspell=getSpellByAscii(ascii);
if(spell==null){
retuBuf.append(chars[i]);
}
else{
retuBuf.append(spell);
}//endofifspell==null
}//endofifascii<=-20400
}//endoffor

returnretuBuf.toString();
}

publicstaticStringgetFirstSpell(StringcnStr)
{
returnnull;
}

publicstaticvoidmain(String[]args)
{
Stringstr=null;
str="谢海101普降喜雨";
System.out.println("Spell="+CnToSpell.getFullSpell(str));

str="耀武扬威》。,";
System.out.println("Spell="+CnToSpell.getFullSpell(str));

str="李鹏,光荣了局。";
System.out.println("Spell="+CnToSpell.getFullSpell(str));

str="猪油,猪八戒。";
System.out.println("Spell="+CnToSpell.getFullSpell(str));
}
}




你希望java的IDE整合。这个是没有必要的,重要的是你理解java有多深以及怎么组织你的代码,即使没有IDE,代码照样能够编译运行的。
简单生活 该用户已被删除
沙发
发表于 2015-1-19 16:31:11 | 只看该作者
你现在最缺的是实际的工作经验,而不是书本上那些凭空想出来的程序。
再见西城 该用户已被删除
板凳
发表于 2015-1-24 14:50:23 | 只看该作者
如果你学过HTML,那么事情要好办的多,如果没有,那你快去补一补HTML基础吧。其实JSP中的Java语法也不多,它更象一个脚本语言,有点象ASP。
谁可相欹 该用户已被删除
地板
发表于 2015-1-29 06:57:04 | 只看该作者
科学超级计算机、移动电话和互联网,同时拥有全球最大的开发者专业社群。
admin 该用户已被删除
5#
发表于 2015-1-30 12:56:48 | 只看该作者
如果你学过HTML,那么事情要好办的多,如果没有,那你快去补一补HTML基础吧。其实JSP中的Java语法也不多,它更象一个脚本语言,有点象ASP。
因胸联盟 该用户已被删除
6#
发表于 2015-2-1 17:31:47 | 只看该作者
设计模式是高级程序员真正掌握面向对象核心思想的必修课。设计模式并不是一种具体"技术",它讲述的是思想,它不仅仅展示了接口或抽象类在实际案例中的灵活应用和智慧
深爱那片海 该用户已被删除
7#
发表于 2015-2-6 02:22:52 | 只看该作者
其实说这种话的人就如当年小日本号称“三个月拿下中国”一样大言不惭。不是Tomjava泼你冷水,你现在只是学到了Java的骨架,却还没有学到Java的精髓。接下来你得研究设计模式了。
金色的骷髅 该用户已被删除
8#
发表于 2015-2-13 12:59:05 | 只看该作者
是一种突破用户端机器环境和CPU
愤怒的大鸟 该用户已被删除
9#
发表于 2015-2-14 15:49:41 | 只看该作者
你现在最缺的是实际的工作经验,而不是书本上那些凭空想出来的程序。
萌萌妈妈 该用户已被删除
10#
 楼主| 发表于 2015-2-16 21:41:28 | 只看该作者
让你能够真正掌握接口或抽象类的应用,从而在原来的Java语言基础上跃进一步,更重要的是,设计模式反复向你强调一个宗旨:要让你的程序尽可能的可重用。
灵魂腐蚀 该用户已被删除
11#
发表于 2015-2-24 02:23:47 | 只看该作者
不过,每次的执行编译后的字节码需要消耗一定的时间,这同时也在一定程度上降低了 Java 程序的运行效率。
第二个灵魂 该用户已被删除
12#
发表于 2015-3-6 14:58:34 | 只看该作者
所以现在应用最广泛又最好学的就是J2EE了。 J2EE又包括许多组件,如Jsp,Servlet,JavaBean,EJB,JDBC,JavaMail等。要学习起来可不是一两天的事。那么又该如何学习J2EE呢?当然Java语法得先看一看的,I/O包,Util包,Lang包你都熟悉了吗?然后再从JSP学起。
柔情似水 该用户已被删除
13#
发表于 2015-3-10 21:03:02 | 只看该作者
其实说这种话的人就如当年小日本号称“三个月拿下中国”一样大言不惭。不是Tomjava泼你冷水,你现在只是学到了Java的骨架,却还没有学到Java的精髓。接下来你得研究设计模式了。
若天明 该用户已被删除
14#
发表于 2015-3-14 20:35:53 | 只看该作者
你一定会高兴地说,哈哈,原来成为Java高手就这么简单啊!记得Tomjava也曾碰到过一个项目经理,号称Java很简单,只要三个月就可以学会。
蒙在股里 该用户已被删除
15#
发表于 2015-3-17 19:08:43 | 只看该作者
你现在最缺的是实际的工作经验,而不是书本上那些凭空想出来的程序。
莫相离 该用户已被删除
16#
发表于 2015-3-19 02:54:16 | 只看该作者
[url]http://www.jdon.com/[/url]去下载,或到同济技术论坛的服务器[url]ftp://nro.shtdu.edu.cn[/url]去下,安装上有什么问题,可以到论坛上去提问。
小女巫 该用户已被删除
17#
发表于 2015-3-23 23:06:11 | 只看该作者
是一种简化的C++语言 是一种安全的语言,具有阻绝计算机病毒传输的功能
不帅 该用户已被删除
18#
发表于 2015-4-4 23:12:37 | 只看该作者
Jive的资料在很多网站上都有,大家可以找来研究一下。相信你读完代码后,会有脱胎换骨的感觉。遗憾的是Jive从2.5以后就不再无条件的开放源代码,同时有licence限制。不过幸好还有中国一流的Java程序员关注它,外国人不开源了,中国人就不能开源吗?这里向大家推荐一个汉化的Jive版本—J道。Jive(J道版)是由中国Java界大名 鼎鼎的banq在Jive 2.1版本基础上改编而成, 全中文,增加了一些实用功能,如贴图,用户头像和用户资料查询等,而且有一个开发团队在不断升级。你可以访问banq的网站
冷月葬花魂 该用户已被删除
19#
发表于 2015-4-15 09:40:01 | 只看该作者
Java 不同于一般的编译执行计算机语言和解释执行计算机语言。它首先将源代码编译成二进制字节码(bytecode),然后依赖各种不同平台上的虚拟机来解释执行字节码。从而实现了“一次编译、到处执行”的跨平台特性。
只想知道 该用户已被删除
20#
发表于 2015-4-16 21:10:40 | 只看该作者
学Java必读的两个开源程序就是Jive和Pet Store.。 Jive是国外一个非常著名的BBS程序,完全开放源码。论坛的设计采用了很多先进的技术,如Cache、用户认证、Filter、XML等,而且论坛完全屏蔽了对数据库的访问,可以很轻易的在不同数据库中移植。论坛还有方便的安装和管理程序,这是我们平时编程时容易忽略的一部份(中国程序员一般只注重编程的技术含量,却完全不考虑用户的感受,这就是我们与国外软件的差距所在)。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|仓酷云 鄂ICP备14007578号-2

GMT+8, 2024-9-30 17:33

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表