-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutil.py
74 lines (69 loc) · 2.48 KB
/
util.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
class Classifier(object):
def get_num_class(self):
raise Exception("Not implemented yet")
def get_string(self,emotion):
raise Exception("Not implemented yet")
def get_class(self,string):
raise Exception("Not implemented yet")
class SevenEmotionsClassifier(Classifier):
def __init__(self):
self.EMOTIONS = {
0 : "anger",
1 : "disgust",
2 : "fear",
3 : "happy",
4 : "sad",
5 : "surprise",
6 : "neutral"
}
def get_num_class(self):
return len(self.EMOTIONS)
def get_string(self,emotion):
return self.EMOTIONS[emotion]
def get_class(self,string):
for emotion in self.EMOTIONS:
if self.EMOTIONS[emotion] == string:
return emotion
raise Exception("Emotion "+str(string) +" is not recognized")
class PositiveNeutralClassifier(Classifier):
def __init__(self):
self.EMOTION_STATE = {
"happy" : 1,
"surprise": 1,
"neutral": 0
}
def get_num_class(self):
return 2
def get_string(self,emotion):
assert emotion in [0,1],"Emotion value must be either 0 or 1 for Positive neutral classifier"
if emotion == 0:
return "neutral"
elif emotion == 1:
return "positive"
def get_class(self,string):
assert string in ["happy","neutral","surprise"],"Emotion must be either happy, neutral or surprise for Positive neutral classifier"
return self.EMOTION_STATE[string]
class PositiveNegetiveClassifier(Classifier):
def __init__(self):
self.EMOTION_STATE = {
"happy" : 1,
"surprise": 1,
"neutral": 0,
"anger": 2,
"disgust":2,
"sad": 2,
"fear":2
}
def get_num_class(self):
return 3
def get_string(self,emotion):
assert emotion in [0,1,2],"Emotion value must be either 0,1 or 2 for Positive negative classifier"
if emotion == 0:
return "neutral"
elif emotion == 1:
return "positive"
elif emotion == 2:
return "negative"
def get_class(self,string):
assert string in ["happy","neutral","surprise","anger","disgust","fear","sad"],"Emotion must be either happy, neutral,sad, fear,disgust,sad or surprise for Positive negative classifier"
return self.EMOTION_STATE[string]