fxsjy / jieba

结巴中文分词
MIT License
33.39k stars 6.73k forks source link

用pseg分词标注词性时,如何加载自定义词典 #1017

Open dyspnea opened 5 months ago

dyspnea commented 5 months ago

import jieba import jieba.posseg as pseg txt='Wi-Fi是个好东西' jieba.load_userdict('user_dict.txt') a = pseg.cut(txt)

a =jieba.cut(txt)

print(list(a))

实际运行时,加载的用户词典,对jieba.cut生效,对pseg.cut无效,如何增加自定义词典呢? 词典内容是: Wi-Fi

dyspnea commented 5 months ago

import jieba jieba.load_userdict('user_dict.txt') import jieba.posseg as pseg txt='Wi-Fi是个好东西' a = pseg.cut(txt) print(list(a))

改成这样也不行,Wi-Fi 在pseg.cut时会被拆开,但加载字典后,jieba.cut会把Wi-Fi当做一个整体 Python3.10.9,win11