资源简介
python情感分析代码 源码数据源都有 功能比较全 可以下载参考

代码片段和文件信息
# -*- coding: utf-8 -*-
“““
Created on Sat Feb 2 00:07:04 2019
@author: Administrator
“““
import os
os.chdir(‘d:\\pythonpath\\LDA‘)
##################情感分析
from collections import defaultdict
import re
import jieba
import codecs
import sys
##中文分词
def seg2word(comment_txt):
#调用jieba进行分词
segword1=jieba.cut(comment_txt)
#分词后的结果存为list类型
segword2=[]
for k in segword1:
segword2.append(k)
#调用reaLines读取停用词
stopwords=open(‘stopwords2.txt‘‘r‘encoding=‘UTF-8‘).readlines()
##如果是停用词就不保存到newSent
newSent=[]
for word in segword2:
if word+‘\n‘ in stopwords:
continue
else:
newSent.append(word)
return newSent ##返回newSent
##情感词定位
def words():
#读取情感词
senList=open(‘sentiment.txt‘‘r‘encoding=‘UTF-8‘).readlines()
senDict=defaultdict()
for s in senList:
senDict[s.split(‘‘)[0]]=s.split(‘‘)[1]
#读取否定词
notList=open(‘notDict.txt‘‘r‘encoding=‘UTF-8‘).readlines()
notDict=defaultdict()
for n in notList:
notDict[n.split(‘‘)[0]]=n.split(‘‘)[1]
#读取程度副词
degreeList=open(‘degreeDict.txt‘‘r‘encoding=‘UTF-8‘).readlines()
degreeDict=defaultdict()
for d in degreeList:
degreeDict[d.split(‘‘)[0]]=d.split(‘‘)[1]
return senDictnotDictdegreeDict
#列表转字典,对分词结果进行定位
def listToDist(wordlist):
data={}
#针对重复词汇,进行判断,采用复合键值
for x in range(0len(wordlist)):
if wordlist[x] not in data.keys():
data.setdafault(wordlist[x][x])
else:
data[wordlist[x]].append(x)
return data
def listToDist(wordlist):
“““将分词后的列表转为字典,key为单词,value为单词在列表中的索引,索引相当于词语在文档中出现的位置“““
data = {}
for x in range(0 len(wordlist)):
data[wordlist[x]] = x
return data
#根据情感定位获得句子得分
def classifyWords(wordDictsenDictnotDictdegreeDict):
senWord1=defaultdict()
notWord1=defaultdict()
degreeWord1=defaultdict()
for i in range(0len(wordDict[word])):
if word in senDict.keys() and word not in notDict.keys() and word not in degreeDict.key():
senWord1[wordDict[word][i]]=senDict[word]
elif word in notDict.keys() and word not in degreeDict.keys():
notWord1[wordDict[word][i]]=notDict[word]
elif word in degreeDict.keys():
degreeWord1[wordDict[word][i]]=degreeDict[word]
senWord1=sorted(senWord1.items()key=lambda asd:asd[0])
notWord1=sorted(notWord1.items()key=lambda asd:asd[0])
degreeWord1=sorted(degreeWord1.items()key=lambda asd:asd[0])
senWord=defaultdict()
for x in senWord1:
senWord[x[0]]=x[1]
notWord=defaultdict()
for y in notWord1:
notWord[y[0]]=y[1]
degreeWord=defaultdict()
for z in degreeWord1:
degreeWord[z[0]]=z[1]
return senWordnotWorddegreeWord
#情感聚合
def scoreSent(senWordnotWorddegre
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 471583 2019-02-28 22:12 情感分析代码修改\comments.txt
文件 2545 2019-02-28 18:11 情感分析代码修改\degreeDict.txt
文件 619 2019-02-28 18:15 情感分析代码修改\notDict.txt
文件 3 2019-02-28 22:25 情感分析代码修改\score.txt
文件 203101 2019-02-28 20:46 情感分析代码修改\sentiment.txt
文件 13710 2019-02-28 20:26 情感分析代码修改\stopwords2.txt
文件 7737 2019-02-28 23:02 情感分析代码修改\情感分析.py
目录 0 2019-02-28 23:35 情感分析代码修改
----------- --------- ---------- ----- ----
699298 8
相关资源
- 二级考试python试题12套(包括选择题和
- pywin32_python3.6_64位
- python+ selenium教程
- PycURL(Windows7/Win32)Python2.7安装包 P
- 英文原版-Scientific Computing with Python
- 7.图像风格迁移 基于深度学习 pyt
- 基于Python的学生管理系统
- A Byte of Python(简明Python教程)(第
- Python实例174946
- Python 人脸识别
- Python 人事管理系统
- 基于python-flask的个人博客系统
- 计算机视觉应用开发流程
- python 调用sftp断点续传文件
- python socket游戏
- 基于Python爬虫爬取天气预报信息
- python函数编程和讲解
- Python开发的个人博客
- 基于python的三层神经网络模型搭建
- python实现自动操作windows应用
- python人脸识别(opencv)
- python 绘图(方形、线条、圆形)
- python疫情卡UN管控
- python 连连看小游戏源码
- 基于PyQt5的视频播放器设计
- 一个简单的python爬虫
- csv文件行列转换python实现代码
- Python操作Mysql教程手册
- Python Machine Learning Case Studies
- python获取硬件信息
评论
共有 条评论