-
Notifications
You must be signed in to change notification settings - Fork 3
/
moduleeng.py
36 lines (26 loc) · 1.01 KB
/
moduleeng.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
from nltk.corpus import sentiwordnet as swn
def polarity( a,b ):
score = 0;
if((b=='VB')and(len(swn.senti_synsets(a,'v'))>0)):
for i in swn.senti_synsets(a,'v'):
score+=(i).pos_score()-(i).neg_score()
score=score/len(swn.senti_synsets(a,'v'))
return score
if((b=='NN')and(len(swn.senti_synsets(a,'n'))>0)):
for i in swn.senti_synsets(a,'n'):
score+=(i).pos_score()-(i).neg_score()
score=score/len(swn.senti_synsets(a,'n'))
return score
if((b=='JJ')and(len(swn.senti_synsets(a,'a'))>0)):
for i in swn.senti_synsets(a,'a'):
score+=(i).pos_score()-(i).neg_score()
score=score/len(swn.senti_synsets(a,'a'))
return score
if((b=='RB')and(len(swn.senti_synsets(a,'r'))>0)):
for i in swn.senti_synsets(a,'r'):
score+=(i).pos_score()-(i).neg_score()
score=score/len(swn.senti_synsets(a,'r'))
return score
if(score==0):
return 'NF'