導航:首頁 > 編程語言 > 拼音漢字轉換java

拼音漢字轉換java

發布時間:2022-11-02 08:36:35

java輸入漢語拼音,輸出匹配的漢字!

java輸入漢語拼音,輸出匹配的漢字,不藉助客戶的選擇,匹配完全正確是幾乎不可能的,尤其是人名,否則拼音輸入法早就演變成無需在輸入漢語拼音後還要選字選詞的操作方式了。

這個屬於自然語言處理的范疇:NLP,暫時還沒有看到過java上的相關應用。
但是,可以參考一下拼音輸入法,這個需求和輸入法很相似啊,不過,現在成熟的輸入法都不能夠完全做到一次性將拼音和漢字匹配成功,這個很有難度,頂多隻是匹配,盡量的匹配。

② java如何獲取漢字的拼音字母

獲取首字母需要對漢字表和字母表進行映射,如下示例代碼是以gb2312編碼為入手點,進行匹配的,也可以使用gbk、utf-8等編碼進行匹配,但代碼就完全不同了。

示例代碼如下:

public class FirstLetterUtils {

// 簡體中文的編碼范圍從B0A1(45217)一直到F7FE(63486)
private static int BEGIN = 45217;
private static int END = 63486;

// 按照聲 母表示,這個表是在GB2312中的出現的第一個漢字,也就是說「啊」是代表首字母a的第一個漢字。
// i, u, v都不做聲母, 自定規則跟隨前面的字母
private static char[] chartable = { '啊', '芭', '擦', '搭', '蛾', '發', '噶', '哈', '哈', '擊', '喀', '垃', '媽', '拿', '哦', '啪', '期', '然', '撒', '塌', '塌', '塌', '挖', '昔', '壓', '匝', };

// 二十六個字母區間對應二十七個端點
// GB2312碼漢字區間十進製表示
private static int[] table = new int[27];

// 對應首字母區間表
private static char[] initialtable = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'h', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 't', 't', 'w', 'x', 'y', 'z', };

// 初始化
static {
for (int i = 0; i < 26; i++) {
table[i] = gbValue(chartable[i]);// 得到GB2312碼的首字母區間端點表,十進制。
}
table[26] = END;// 區間表結尾
}

// ------------------------public方法區------------------------
// 根據一個包含漢字的字元串返回一個漢字拼音首字母的字元串 最重要的一個方法,思路如下:一個個字元讀入、判斷、輸出

public static String cn2py(String SourceStr) {
String Result = "";
int StrLength = SourceStr.length();
int i;
try {
for (i = 0; i < StrLength; i++) {
Result += Char2Initial(SourceStr.charAt(i));
}
} catch (Exception e) {
Result = "";
e.printStackTrace();
}
return Result;
}

// ------------------------private方法區------------------------
/**
* 輸入字元,得到他的聲母,英文字母返回對應的大寫字母,其他非簡體漢字返回 '0' *
*/
private static char Char2Initial(char ch) {
// 對英文字母的處理:小寫字母轉換為大寫,大寫的直接返回
if (ch >= 'a' && ch <= 'z') {
return (char) (ch - 'a' + 'A');
}
if (ch >= 'A' && ch <= 'Z') {
return ch;
}
// 對非英文字母的處理:轉化為首字母,然後判斷是否在碼表范圍內,
// 若不是,則直接返回。
// 若是,則在碼表內的進行判斷。
int gb = gbValue(ch);// 漢字轉換首字母
if ((gb < BEGIN) || (gb > END))// 在碼表區間之前,直接返回
{
return ch;
}
int i;
for (i = 0; i < 26; i++) {// 判斷匹配碼表區間,匹配到就break,判斷區間形如「[,)」
if ((gb >= table[i]) && (gb < table[i + 1])) {
break;
}
}
if (gb == END) {// 補上GB2312區間最右端
i = 25;
}
return initialtable[i]; // 在碼表區間中,返回首字母
}

/**
* 取出漢字的編碼 cn 漢字
*/
private static int gbValue(char ch) {// 將一個漢字(GB2312)轉換為十進製表示。
String str = new String();
str += ch;
try {
byte[] bytes = str.getBytes("GB2312");
if (bytes.length < 2) {
return 0;
}
return (bytes[0] << 8 & 0xff00) + (bytes[1] & 0xff);
} catch (Exception e) {
return 0;
}
}

public static void main(String[] args) throws Exception {
System.out.println(cn2py("這是一個獲取首字母的class"));
}
}

③ 求JAVA 漢字轉拼音代碼,謝謝!

import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Set;

public class ConverPinYin
{
private static LinkedHashMap spellMap = null;
static
{
if (spellMap == null)
{
spellMap = new LinkedHashMap(400);
}
initialize();
}

private static void spellPut(String spell, int ascii)
{
spellMap.put(spell, new Integer(ascii));
}

private static void initialize()
{
spellPut("a", -20319);
spellPut("ai", -20317);
spellPut("an", -20304);
spellPut("ang", -20295);
spellPut("ao", -20292);
spellPut("ba", -20283);
spellPut("", -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("", -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("", -18756);
spellPut("an", -18741);
spellPut("i", -18735);
spellPut("n", -18731);
spellPut("o", -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("", -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);
}

④ java中漢語轉換成拼音且可以分大小寫

例如:張三 我現在得到結果是 zhangsan 我想要的結果是ZhangSan

這個很簡單,你既然可以得到zhangsan了說明你已經有庫了,
那麼你就一個個漢字去讀庫啊

例如:先讀張,得到zhang,將第一個字元變為大寫就是Zhang了,再去庫里讀三得到san,再將S大寫,依次類推最後將所有字元串拼起來不就是ZhangSan了嗎。

⑤ 怎麼將拼音轉成漢字 Java

您好!

很高心為您會打這個問題,拼音轉換字的實現到時挺多的,但是需要庫,如果沒有三方庫的話,轉換就比較麻煩,恰好python是出了名的三方庫多,個人認為你可以通過java調用python進行轉換,使用PythonInterpreter類調用即可,然後至於python如何轉換,請參考開源代碼網頁鏈接,希望採納

⑥ java里怎麼輸入漢字,把它轉化為拼音求高手指點

這個是我所做項目中所涉及到的,希望能幫到你。

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

private static CharacterParser characterParser = new CharacterParser();

public static CharacterParser getInstance() {
return characterParser;
}

public String getResource() {
return resource;
}

public void setResource(String resource) {
this.resource = resource;
}

/**
* 漢字轉成ASCII碼
*
* @param chs
* @return
*/
private int getChsAscii(String chs) {
int asc = 0;
try {
byte[] bytes = chs.getBytes("gb2312");
if (bytes == null || bytes.length > 2 || bytes.length <= 0) { // 錯誤
throw new RuntimeException("illegal resource string");
}
if (bytes.length == 1) { // 英文字元
asc = bytes[0];
}
if (bytes.length == 2) { // 中文字元
int hightByte = 256 + bytes[0];
int lowByte = 256 + bytes[1];
asc = (256 * hightByte + lowByte) - 256 * 256;
}
} catch (Exception e) {
System.out
.println("ERROR:ChineseSpelling.class-getChsAscii(String chs)"
+ e);
}
return asc;
}

/**
* 單字解析
*
* @param str
* @return
*/
public String convert(String str) {
String result = null;
int ascii = getChsAscii(str);
if (ascii > 0 && ascii < 160) {
result = String.valueOf((char) ascii);
} else {
for (int i = (pyvalue.length - 1); i >= 0; i--) {
if (pyvalue[i] <= ascii) {
result = pystr[i];
break;
}
}
}
return result;
}

/**
* 片語解析
*
* @param chs
* @return
*/
public String getSelling(String chs) {
String key, value;
buffer = new StringBuilder();
for (int i = 0; i < chs.length(); i++) {
key = chs.substring(i, i + 1);
if (key.getBytes().length >= 2) {
value = (String) convert(key);
if (value == null) {
value = "unknown";
}
} else {
value = key;
}
buffer.append(value);
}
return buffer.toString();
}

public String getSpelling() {
return this.getSelling(this.getResource());
}

public static void main(String[] args) {
CharacterParser parser = CharacterParser.getInstance();
System.out.println(parser.getSelling("中華人民共和國"));
}
}

⑦ java的拼音字母檢索漢字

看看這個js的實現.
http://hi..com/134931/blog/item/311b82589e215add9c8204e5.html

我覺得,先實現漢字轉拼音的方法.
資料庫里加一個欄位存放這些拼音的簡寫, 每次插入數據的時候,調用這個方法.
這樣每個詞就有字典了. 最好是用拼音首字母.

⑧ java 怎麼將拼音轉換為漢字

一個漢字 只對應 一個拼音 ,但是一個拼音是對應多個漢字的, 你想要的功能,就好像一個輸入法,輸入一堆拼音,顯示對應的漢字。這個我不知道,有沒有輸入法提供這樣的介面,簡單點就是這樣,但是復雜點,根據你輸入的拼音顯示出足夠智能的漢字,這不簡單。java有把漢字轉拼音的架包,不是拼音轉漢字

⑨ java中怎麼實現將中文轉化為拼音

這個有很多成熟的jar包的,給你個地址看看吧,人家寫的很詳細。
http://www.cnblogs.com/DreamDrive/p/5762078.html

⑩ java如何實現拼音首字母檢索漢字

使用pinyin4j或者jpinyin的,先將漢字轉換為拼音,然後記錄拼音的首字母,具體的檢索過程可以用循環過濾,也可以用前綴樹 比如tire樹

參考鏈接:

網頁鏈接java實現漢字轉拼音

網頁鏈接tire樹

閱讀全文

與拼音漢字轉換java相關的資料

熱點內容
自動解壓失敗叫我聯系客服 瀏覽:482
易語言新手源碼 瀏覽:456
oa伺服器必須有固定ip地址 瀏覽:42
傳奇源碼分析是什麼 瀏覽:267
解放壓縮機支架 瀏覽:255
程序員禿頂搞笑相遇 瀏覽:6
IBM手機app商店叫什麼名字 瀏覽:834
jpeg壓縮質量 瀏覽:774
雲伺服器評測對比 瀏覽:145
java日期轉string 瀏覽:221
openfire源碼編譯 瀏覽:897
在線小工具箱引流網站源碼 瀏覽:337
非科班程序員自學 瀏覽:800
壓縮泡沫鞋底底材 瀏覽:219
程序員職場第一課2正確的溝通 瀏覽:679
遇到不合法app應該怎麼辦 瀏覽:91
匯編程序編譯後的文件 瀏覽:80
大智慧均線源碼 瀏覽:374
單片機排阻的作用 瀏覽:216
滴滴金融app被下架如何還款 瀏覽:212