コード例 #1
0
def sentiment_analyze(text):
    if isinstance(text, float) and math.isnan(text):
        text = ''

    text = HanziConv.toSimplified(text)

    senti = Sentiment()
    sentiment_result = senti.sentiment_count(text)

    emotion = Emotion()
    emotion_result = emotion.emotion_count(text)
    emotion_result['樂'] = emotion_result.pop('乐')
    emotion_result['懼'] = emotion_result.pop('惧')
    emotion_result['惡'] = emotion_result.pop('恶')
    emotion_result['驚'] = emotion_result.pop('惊')

    return sentiment_result, emotion_result
コード例 #2
0
import pandas as pd
from matplotlib import pyplot as plt
import pickle
import jieba
from wordcloud import WordCloud
from cnsenti import Emotion
from cnsenti import Sentiment
# data= data[0:5]
senti = Sentiment()
emotion = Emotion()
#显示所有列
pd.set_option('display.max_columns', None)
#显示所有行
pd.set_option('display.max_rows', None)
#设置value的显示长度为100,默认为50
pd.set_option('max_colwidth', 100)
# stopword_list_cn = [k.strip() for k in open('../../data/cn_stopwords.txt', encoding='utf8').readlines() if k.strip() != '']
# stopword_list_hit = [k.strip() for k in open('../..//data/hit_stopwords.txt', encoding='utf8').readlines() if k.strip() != '']
# stopword_list_scu = [k.strip() for k in open('../../data/scu_stopwords.txt', encoding='utf8').readlines() if k.strip() != '']
# stopword_list = stopword_list_cn+stopword_list_scu+stopword_list_hit


def emotion_sentiment_convert(x):
    result = emotion.emotion_count(x)
    result_senti = senti.sentiment_count(x)

    return result['好'], result['乐'], result['哀'], result['怒'], result[
        '惧'], result['恶'], result['惊'], result_senti['pos'], result_senti[
            'neg']

コード例 #3
0
ファイル: 代码.py プロジェクト: hughzeng-x/cnsenti
from cnsenti import Sentiment

senti = Sentiment(pos='正面词自定义.txt',  #正面词典txt文件相对路径
                  neg='负面词自定义.txt',  #负面词典txt文件相对路径
                  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)
コード例 #4
0
import jieba
# from snownlp import SnowNLP
# from snownlp import sentiment
from cnsenti import Emotion
from cnsenti import Sentiment

senti = Sentiment()
emotion = Emotion()
test_text = '来得时-甘精胰岛素说明书'
print(jieba.lcut(test_text))
result = emotion.emotion_count(test_text)
result_o = senti.sentiment_count(test_text)
print(result)
print(result_o)
print(senti.sentiment_calculate(test_text))
# print(result['好'])
import pathlib
import pickle


def read_dict(file):
    pathchain = ['dictionary', 'dutir', file]
    mood_dict_filepath = pathlib.Path(__file__).parent.joinpath(*pathchain)
    dict_f = open(mood_dict_filepath, 'rb')
    words = pickle.load(dict_f)
    return words


print(
    read_dict(
        'C:/Users\Thinkpad\Anaconda3\Lib\site-packages\cnsenti\dictionary\dutir\惧.pkl'
コード例 #5
0
from cnsenti import Sentiment

senti = Sentiment(
    pos='正面词自定义.txt',  #正面词典txt文件相对路径
    neg='负面词自定义.txt',  #负面词典txt文件相对路径
    merge=True,  #merge=True融合自定义词典和cnsenti自带词典;merge=False只使用自定义词典
    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)