汉字转换 汉字转换拼音( 二 )


strict– 是否严格遵照《汉语拼音方案》来处理声母和韵母,详见 strict 参数的影响
import pypinyinfrom pypinyin import Stylepypinyin.slug('我是中国人')'wo-shi-zhong-guo-ren'pypinyin.slug('我是中国人', separator=' ')'wo shi zhong guo ren'pypinyin.slug('中国人2020雄起', separator=' ')#遇到数字等非汉字不注音'zhong guo ren 2020 xiong qi'pypinyin.slug('中国人2020雄起', style=Style.FIRST_LETTER)'z-g-r-2020-x-q'pypinyin.slug('我是中国人', style=Style.CYRILLIC)'во3-ши4-чжун1-го2-жэнь'【汉字转换 汉字转换拼音】
4、 pypinyin.load_single_dict功能:载入用户自定义的单字拼音库
语法:pypinyin.load_single_dict(pinyin_dict, style='default')
参数:
pinyin_dict(dict) – 单字拼音库 。比如: {0x963F: u"ā,ē"}
style– pinyin_dict 参数值的拼音库风格. 支持 ‘default’, ‘tone2’
5、 pypinyin.load_phrases_dict功能:载入用户自定义的词语拼音库
语法:pypinyin.load_phrases_dict(phrases_dict, style='default')
参数:
phrases_dict(dict) – 词语拼音库 。比如: {u"阿爸": [[u"ā"], [u"bà"]]}
style– phrases_dict 参数值的拼音库风格. 支持 ‘default’, ‘tone2’
五、一个案例假如需要找出一个垃圾评价的相似样本,用汉语相似性远远小于拼音,这个时候 , 拼音就能发挥很大的优势 。
当然转换成拼音后,把每个音节当一个词,进行深度学习,效果也是非常好的 。
S1 = '加公众号:小优惠,领券,便宜购买'S2 = '伽工仲号:小优惠,伶绻,便宜购买'#汉语相似simi_1 = len(set(S1).intersection(set(S2)))/len(set(S1).union(set(S2)))#相似不懂的可以看我前面集合的文章simi_10.5#转换成拼音后显示S1 = lazy_pinyin(S1)S2 = lazy_pinyin(S2)simi_2 = len(set(S1).intersection(set(S2)))/len(set(S1).union(set(S2)))simi_20.875Python学习交流群
为了让大家更加即时地沟通学习,我们建了一个Python学习交流群 , 有想入群的同学 , 可以添加下面小助手微信,他会拉大家入群哈~

推荐阅读