漢字轉拼音

2022-02-16 10:38:15 字數 1223 閱讀 3144

from:

網上有很多說自己整理的漢字轉拼音是完美的,但使用後才發現都是半吊的瓶子,問題多多。

常見的生僻字,或多音字識別,轉換後簡直讓人感覺可怕。

主流的轉換有三種:hash匹配,npinyin,微軟pinyinconverter。

但單用這三個,都沒法做到完美,為什麼沒人考慮融合呢?

我的方案:npinyin+微軟pinyinconverter(首選npinyin)

微軟pinyinconverter

為什麼:微軟pinyinconverter很強大,但在多音字面前,犯了傳統的錯誤,按拼音字母排序。如【強】微軟居然優先【jiang】而不是】【qiang】

所以不能優選 pinyinconverter。

npinyin

很人性,很不錯的第三方庫,在傳統多音字前優先使用率較高的,但在生僻字面前有點無法轉換。(getinitials(strchinese)  有bug  如【洺】無法識別,但getpinyin可以正常轉換。)

總結:優先npinyin  翻譯失敗的使用微軟pinyinconverter。目測完美。

上**:

public class pingyinhelper

return fullspell.tostring().toupper();}}

catch (exception e)

return string.empty;

}/// /// 漢字轉首字母

///

///

///

public static string getfirstspell(string strchinese)

return fullspell.tostring().toupper();}}

catch (exception e)

return string.empty;

}private static string getspell(char chr)}}

return coverchr;}}

抽了幾個常見錯字和姓名

測試如下:

[testmethod]

public void pingyintest(),,

,,,,

,};

foreach (var keyval in dict)

}

漢字轉拼音

region 漢字轉拼音 漢字轉拼音類 用法 crazycoderpinyin.covent 漢字 長度 using system.text.regularexpressions build date 20030610 public class crazycoderpinyin 定義陣列 priva...

漢字轉拼音

工具pinyin4j 2.5.0.jar 整理了3個方法,1.漢字轉拼音 2.返回中文姓 中文名 英文姓 last name 英文名 first name 3.返回首字母 public class pinyin4jdemo char hanzi word.tochararray string t2 ...

漢字轉拼音

ios mac os x 漢字轉拼音 網路流行的漢字轉拼音方案是帶乙個拼音碼表,速度快。其實core foundation也提供了一種方案,而且還帶聲調!nsmutablestring ms nsmutablestring alloc initwithstring 我是中國人 if cfstring...