-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
使用DUTIR词典报错 #5
Comments
你的数据中text可能有纯文数字或者缺失值字段
…---原始邮件---
发件人: ***@***.***>
发送时间: 2022年7月6日(周三) 中午12:47
收件人: ***@***.***>;
抄送: ***@***.***>;
主题: [hiDaDeng/cntext] 使用DUTIR词典报错 (Issue #5)
运行代码
import cntext as ct text = '我今天得奖了,很高兴,我要将快乐分享大家。' ct.sentiment(text=text, diction=ct.load_pkl_dict('DUTIR.pkl')['DUTIR'], lang='chinese')
报错
Traceback (most recent call last): File "d:\PythonProject\test\test_cntext.py", line 5, in <module> ct.sentiment(text=text, File "D:\Miniconda3\envs\py38\lib\site-packages\cntext\stats.py", line 159, in sentiment jieba.add_word(w) File "D:\Miniconda3\envs\py38\lib\site-packages\jieba\__init__.py", line 426, in add_word word = strdecode(word) File "D:\Miniconda3\envs\py38\lib\site-packages\jieba\_compat.py", line 79, in strdecode sentence = sentence.decode('utf-8') AttributeError: 'int' object has no attribute 'decode'
如果不使用DUTIR词典,使用其他词典,则可以正常运行,如:
import cntext as ct text = '我今天得奖了,很高兴,我要将快乐分享大家。' ct.sentiment(text=text, diction=ct.load_pkl_dict('HOWNET.pkl')['HOWNET'], lang='chinese')
运行结果
{'deny_num': 0, 'ish_num': 0, 'more_num': 0, 'neg_num': 0, 'pos_num': 3, 'very_num': 1, 'stopword_num': 8, 'word_num': 14, 'sentence_num': 1}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
抱歉,没仔细看问题。我觉得如果DUTIR换成Hownet就ok,那应该是词典问题。
词典问题的话,先保证导入的词典符合统一的字典样式。cntext仓库中有关于标准字典样式的词典小案例。
…---原始邮件---
发件人: ***@***.***>
发送时间: 2022年7月6日(周三) 中午12:47
收件人: ***@***.***>;
抄送: ***@***.***>;
主题: [hiDaDeng/cntext] 使用DUTIR词典报错 (Issue #5)
运行代码
import cntext as ct text = '我今天得奖了,很高兴,我要将快乐分享大家。' ct.sentiment(text=text, diction=ct.load_pkl_dict('DUTIR.pkl')['DUTIR'], lang='chinese')
报错
Traceback (most recent call last): File "d:\PythonProject\test\test_cntext.py", line 5, in <module> ct.sentiment(text=text, File "D:\Miniconda3\envs\py38\lib\site-packages\cntext\stats.py", line 159, in sentiment jieba.add_word(w) File "D:\Miniconda3\envs\py38\lib\site-packages\jieba\__init__.py", line 426, in add_word word = strdecode(word) File "D:\Miniconda3\envs\py38\lib\site-packages\jieba\_compat.py", line 79, in strdecode sentence = sentence.decode('utf-8') AttributeError: 'int' object has no attribute 'decode'
如果不使用DUTIR词典,使用其他词典,则可以正常运行,如:
import cntext as ct text = '我今天得奖了,很高兴,我要将快乐分享大家。' ct.sentiment(text=text, diction=ct.load_pkl_dict('HOWNET.pkl')['HOWNET'], lang='chinese')
运行结果
{'deny_num': 0, 'ish_num': 0, 'more_num': 0, 'neg_num': 0, 'pos_num': 3, 'very_num': 1, 'stopword_num': 8, 'word_num': 14, 'sentence_num': 1}
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
您好,感谢您的回复。按照您的提示进行修改,仍报错。 我使用的python版本:3.8.5 我的完整代码如下 import cntext as ct
print(ct.__version__)
# 导入pkl词典文件,
ct.load_pkl_dict('DUTIR.pkl')
text = '我今天得奖了,很高兴,我要将快乐分享大家。'
ct.sentiment(text=text,
diction=ct.load_pkl_dict('DUTIR.pkl')['DUTIR'],
lang='chinese')
|
我又新建了一个python3.7.9的环境,运行相同的代码,还是同样的报错。 |
更新至于1.7.5 pip3 install cntext==1.7.6 |
成功解决。非常感谢! |
运行代码
报错
如果不使用
DUTIR
词典,使用其他词典,则可以正常运行,如:运行结果
The text was updated successfully, but these errors were encountered: