将汉语转换成注音或拼音
chpronounce的Python项目详细描述
Ch发音
一种使用pkuseg(一种文本分割工具)和词典将中文句子转换为注音或拼音的工具
使用
fromchpronounceimportChPronouncechp=ChPronounce()# To print out segmentation result from pkuseg, use:# chp = ChPronounce(print_seg=True)# Convert to both pinyin and zhuyinprint(chp.get_duyin("吃飽了沒?"))# Convert to zhuyinprint(chp.get_zhuyin("吃飽了"))# Convert to pinyinprint(chp.get_pinyin("我能吃玻璃而不傷身體"))print(chp.get_duyin("我睡著了"))# Output:# [('chi', 'ㄔ', 1), ('bao', 'ㄅㄠ', 3), ('le', 'ㄌㄜ', 5), ('mei', 'ㄇㄟ', 2), ('?', '?', 0)]# [('ㄔ', 1), ('ㄅㄠ', 3), ('ㄌㄜ', 5)]# [('wo', 3), ('neng', 2), ('chi', 1), ('bo', 1), ('li', 5), ('er', 2), ('bu', 4), ('shang', 1), ('shen', 1), ('ti', 3)]# [('wo', 'ㄨㄛ', 3), ('shui', 'ㄕㄨㄟ', 4), ('zhao', 'ㄓㄠ', 2), ('le', 'ㄌㄜ', 5)]
编辑词典
^{pr2}$Toaccessormodifydictionary,use'dic'Tosave,usesave()Python3.7.7(default,Apr242020,09:08:39)[GCC9.3.0]onlinuxType"help","copyright","credits"or"license"formoreinformation.(InteractiveConsole)>>>dic[1]["好"]# Check the word "好"[(('hao','ㄏㄠ',3),'形副助叹动'),(('hao','ㄏㄠ',4),'动名')]>>>dic[1]["好"]=[(('hao','ㄏㄠ',3),'形副助叹动')]# Modify the word>>>dic[2]["你好"]# Check a phrase(['ni','hao'],['ㄋㄧ','ㄏㄠ'],[3,3])>>>dic[3]["好棒棒"]=(['hao','bang','bang'],['ㄏㄠ','ㄅㄤ','ㄅㄤ'],[3,4,4])# Create a phrase>>>save()# Write changes
Press
Ctrl+D
to exit the shell
字典结构:
dic├──1:(dict)│├──"數":[(list)││(('shu','ㄕㄨ',4),'名形'),││(('shu','ㄕㄨ',3),'动副')││]│├──...│├──2:(dict)│├──"你好":(['ni','hao'],['ㄋㄧ','ㄏㄠ'],[3,3])│├──...│├──3:(dict)│├──"計算機":(['ji','suan','ji'],['ㄐㄧ','ㄙㄨㄢ','ㄐㄧ'],[4,4,1])│├──...│├──4:...├──...dic=["",{"X":[(...),(...)]},{"XX":(...),"YY":(...)}]
参考文献
- 在
字典
在 - 在
文本分割工具
在 - 在
繁体中文到简体的转换
在
- 项目
标签: