mozillazg / python-pinyin

汉字转拼音(pypinyin)
https://pypinyin.readthedocs.io
MIT License
4.89k stars 612 forks source link

自定义词库没有作用,需要enable吗?怎么做 #15

Closed jeremy886 closed 9 years ago

jeremy886 commented 9 years ago

from pypinyin import load_phrases_dict, lazy_pinyin, TONE2 lazy_pinyin('还没', style = TONE2) ['hua2n', 'me2i'] from pypinyin import load_phrases_dict, lazy_pinyin, TONE lazy_pinyin('还没', style = TONE) ['huán', 'méi'] load_phrases_dict({'还没': [['hái'], ['méi']]}) lazy_pinyin('还没', style = TONE) ['huán', 'méi']

mozillazg commented 9 years ago

@jeremy886 抱歉,回复晚了,最近没上网。这个涉及到分词的问题。 如果你没有安装 jieba 分词模块,或者 还没 经过分词后不是一个词组的话,两种解决办法:

>>>  load_phrases_dict({'还没': [['hái'], ['méi']]})
>>> lazy_pinyin(['还没'], style=TONE2)            # 手动指定 “还没” 为一个词组
['ha2i', 'me2i']
>>> load_single_dict({ord('还'):'hái,huán'})      # 调整 ”还" 字的拼音顺序
>>> lazy_pinyin('还没', style=TONE2)
['ha2i', 'me2i']
jeremy886 commented 9 years ago

Hi, I fixed it by doing pip upgrade.

All is good now.