-
Notifications
You must be signed in to change notification settings - Fork 2
/
extract.py
52 lines (30 loc) · 1.16 KB
/
extract.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
def extract_score(emotion_word,synset_to_match): #actual implementation of emotion extraction
import nltk
from nltk.corpus import wordnet as wn
from simplenlp import get_nl
#emotions=["happy","sad","anger","fear","disgust","surprise"]
result_score=[]
temp_score=-1
# temp_emotion=""
our_word_synsets=wn.synsets(emotion_word)
if (len(our_word_synsets)==0):
temp_score=-100
#return temp_score
# for i in emotions:
# syn=wn.synsets(i)
else:
for our_word_synset in our_word_synsets:
if (our_word_synset.pos!=synset_to_match.pos):
continue;
score=our_word_synset.wup_similarity(synset_to_match) # have to use better heuristics to find similarity between synsets
if (score>temp_score):
temp_score=score
# return temp_score
# temp_emotion=emotion
#else:
# return temp_score
return temp_score
#def test_result(emotion_word):
# e=extract(emotion_word)
# print emotion_word + " -> (closely related to emotion) -> " + e
#test_result("fear");