一、cnsenti
中文情感分析库(Chinese Sentiment))可对文本进行情绪分析、正负情感分析。对了,强调一下,这是大邓出品的python第三方包^_^,大家可以通过pip实现安装。
github地址
https://github.com/thunderhit/cnsenti
pypi地址
https://pypi.org/project/cnsenti/
特性
情感分析默认使用的知网Hownet
情感分析可支持导入自定义txt情感词典(pos和neg)
情绪分析使用大连理工大学情感本体库,可以计算文本中的七大情绪词分布
二、安装
方法一
由于pip默认从pypi站点下载cnsenti安装包,速度会比较慢,这样容易出现安装失败,多试几次即可。
pip install cnsenti
方法二
更改到国内镜像,可以加速下载安装。由于是新上传的库,可能短时间内国内镜像没有收录,等一两天即可。
pip install cnsenti -i https://pypi.tuna.tsinghua.edu.cn/simple/
三、快速上手
中文文本情感词正负情感词统计
from cnsenti import Sentiment
senti = Sentiment()
test_text= '我好开心啊,非常非常非常高兴!今天我得了一百分,我很兴奋开心,愉快,开心'
result = senti.sentiment_count(test_text)
print(result)
Run
{'words': 24,
'sentences': 2,
'pos': 4,
'neg': 0}
中文文本情绪统计
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}