当前位置:   article > 正文

Python做文本情感分析之情感极性分析_python情感极性分析有哪些常用方法 (1)_python怎么分析几个中文句子的感情倾向

python怎么分析几个中文句子的感情倾向

`“”"
2. 情感定位
“”"
def classifyWords(wordDict):

(1) 情感词

senList = readLines(‘BosonNLP_sentiment_score.txt’)
senDict = defaultdict()
for s in senList:
senDict[s.split(’ ‘)[0]] = s.split(’ ')[1]

(2) 否定词

notList = readLines(‘notDict.txt’)

(3) 程度副词

degreeList = readLines(‘degreeDict.txt’)
degreeDict = defaultdict()
for d in degreeList:
degreeDict[d.split(‘,’)[0]] = d.split(‘,’)[1]

senWord = defaultdict()
notWord = defaultdict()
degreeWord = defaultdict()

for word in wordDict.keys():
if word in senDict.keys() and word not in notList and word not in degreeDict.keys():
senWord[wordDict[word]] = senDict[word]
elif word in notList and word not in degreeDict.keys():
notWord[wordDict[word]] = -1
elif word in degreeDict.keys():
degreeWord[wordDict[word]] = degreeDict[word]
return senWord, notWord, degreeWord`


###### 1.3.2 计算句子得分



> 
> 在此,简化的情感分数计算逻辑:**所有情感词语组的分数之和**
> 
> 
> 


定义一个**情感词语组**:两情感词之间的所有否定词和程度副词与这两情感词中的后一情感词构成一个情感词组,即`notWords + degreeWords + sentiWords`,例如`不是很交好`,其中`不是`为否定词,`很`为程度副词,`交好`为情感词,那么这个情感词语组的分数为:  
`finalSentiScore = (-1) ^ 1 * 1.25 * 0.747127733968`  
其中`1`指的是一个否定词,`1.25`是程度副词的数值,`0.747127733968`为`交好`的情感分数。


伪代码如下:  
`finalSentiScore = (-1) ^ (num of notWords) * degreeNum * sentiScore`  
`finalScore = sum(finalSentiScore)`



  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

`“”"
3. 情感聚合
“”"
def scoreSent(senWord, notWord, degreeWord, segResult):
W = 1
score = 0

存所有情感词的位置的列表

senLoc = senWord.keys()
notLoc = notWord.keys()
degreeLoc = degreeWord.keys()
senloc = -1

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/721310
推荐阅读
相关标签
  

闽ICP备14008679号