中文文本情绪统计
from cnsenti import Emotion
emotion = Emotion()
test_text = '我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心'
result = emotion.emotion_count(test_text)
print(result)
Run
{'words': 22,
'sentences': 2,
'好': 0,
'乐': 4,
'哀': 0,
'怒': 0,
'惧': 0,
'恶': 0,
'惊': 0}
3.4.2 Sentiment自定义词典参数
from cnsenti import Sentiment senti = Sentiment(pos='正面词自定义.txt', #正面词典txt文件相对路径 neg='负面词自定义.txt', #负面词典txt文件相对路径 merge=True, #融合cnsenti自带词典和用户导入的自定义词典 encoding='utf-8') #两txt均为utf-8编码 test_text = '这家公司是行业的引领者,是中流砥柱。今年的业绩非常好。' result1 = senti.sentiment_count(test_text) result2 = senti.sentiment_calculate(test_text) print('sentiment_count',result1) print('sentiment_calculate',result2)