-
Notifications
You must be signed in to change notification settings - Fork 0
/
vectorToLabel.py
66 lines (62 loc) · 1.95 KB
/
vectorToLabel.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
# import vectorToLabel.py
# converter = vectorToLabel.Converter()
# for i in range(len(inputTestTweets)):
# print 'For tweet: %s' %(tweetsToBeTagged[i])
# print '\tPredicted: %s' %(predictions_list[i])
# for labeltype in labeltypes:
# labels = converter.convertToLabels(predictions_list[i])
# print '\tPredicted %s labels: %s' %(labeltype, labels[labeltype])
class Converter:
def __init__(self):
self.ordered_keys = ['s1', 's2', 's3', 's4', 's5',
'w1', 'w2', 'w3', 'w4',
'k1', 'k2', 'k3', 'k4', 'k5', 'k6', 'k7', 'k8',
'k9', 'k10', 'k11', 'k12', 'k13', 'k14', 'k15']
self.map = {
's1' : "I can't tell",
's2' : "Negative",
's3' : "Neutral / author is just sharing information",
's4' : "Positive",
's5' : "Tweet not related to weather condition",
'w1' : "current (same day) weather",
'w2' : "future (forecast)",
'w3' : "I can't tell",
'w4' : "past weather",
'k1' : "clouds",
'k2' : "cold",
'k3' : "dry",
'k4' : "hot",
'k5' : "humid",
'k6' : "hurricane",
'k7' : "I can't tell",
'k8' : "ice",
'k9' : "other",
'k10' : "rain",
'k11' : "snow",
'k12' : "storms",
'k13' : "sun",
'k14' : "tornado",
'k15' : "wind"
}
self.numKeys = len(self.map)
self.labeltypes = ['sentiment', 'time', 'event']
def convertToLabels(self, bitvector):
labels = { 'sentiment': [],
'event' : [],
'time' : []
}
keys = self.ordered_keys
for i in range(self.numKeys):
if bitvector[i] == 1:
if i >= 0 and i <=4: # append sentiment label
labels['sentiment'].append(self.map[keys[i]])
elif i >= 5 and i <= 8: # append time label
labels['time'].append(self.map[keys[i]])
else:
labels['event'].append(self.map[keys[i]])
return labels
def printLabels(self, fullbitvector):
print '\tfullbitvector: %s' %(fullbitvector)
for labeltype in self.labeltypes:
labels = self.convertToLabels(fullbitvector)
print '\t%s labels: %s' %(labeltype, labels[labeltype])