【情感提取+情感计算+词频统计】python情感分析--网盘链接已更新

目录

1、情感分析介绍

2、基于大连理工情感词汇方法

2.1加载大连理工情感词典,程度副词典,否定词典,停用词典

2.2译文断章切句

2.3提取情感词并计算情感值

2.4统计词频

2.5调用实现



1、情感分析介绍

情感分析是一种自然语言处理技术,旨在识别文本中的情感并将其分类为积极、消极或中性。它通过使用机器学习算法和自然语言处理技术来自动分析文本中的情感,从而帮助人们更好地理解文本的情感含义。

本文以某译本new_deepl_translated.txt为分析对象,通过对译文断章切句,进而对每一个句子情感词提取、情感值计算,以及词频统计,最后保存为excel文件。

new_deepl_translated.txt部分内容如下:

情感值计算结果:

词频统计结果:

2、基于大连理工情感词汇方法

2.1加载大连理工情感词典,程度副词典,否定词典,停用词典

各词典大家可以从网上进行下载,顶部我放了一个资源包可以直接拿来用,或者直接网盘提取:
链接: https://pan.baidu.com/s/1Cke-6qyB0dzgNxBwxgL_6Q 提取码: pi7

定义一个类sa,用于加载情感词典、程度副词典、否定词典、停用词典,以及分词和去除停用词。针对大连理工情感词典,我只需要加载词语、情感分类、强度、极性这4列内容。

class sa:
    # 加载情感词典、程度副词典、否定词典、停用词典
    def __init__(self, senti_dict_path, degree_dict_path, not_dict_path, stopword_path):
        self.senti_dict = self.load_dict(senti_dict_path)
        self.degree_dict = self.load_degree_dict(degree_dict_path)
        self.not_dict = self.load_not_dict(not_dict_path)
        self.stopwords = self.load_stopwords(stopword_path)

    # 加载情感词典
    def load_dict(self, path):
        with open(path, 'r', encoding='utf-8') as f:
            lines = f.readlines()
        word_dict = {}
        for line in lines:
            items = line.strip().split('\t')
            if len(items) >= 7:               
                word = items[0]  #情词
                emotion = items[4]  #情词类别
                strength = int(items[5])  #情词强度
                polarity = int(items[6])  #情词极性
                word_dict[word] = {'emotion': emotion, 'strength': strength, 'polarity': polarity}
        return word_dict
    
     # 加载程度副词词典
    def load_degree_dict(self, path):
        with open(path, 'r', encoding='utf-8') as f:
            lines = f.readlines()
        degree_dict = {}
        for line in lines:
            items = line.strip().split('\t')
            if len(items) >= 2:
                degree_word = items[0]  #副词
                degree_value = float(items[1])   #副词权值
                degree_dict[degree_word] = degree_value
        return degree_dict
    
    # 加载否定词词典
    def load_not_dict(self, path):
        with open(path, 'r', encoding='utf-8') as f:
            lines = f.readlines()
        not_dict = {}
        for line in lines:
            items = line.strip().split('\t')
            if len(items) >= 1:
                not_word = items[0]  #否定词
         
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值