-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsimilar_hash_classify.py
168 lines (140 loc) · 7.23 KB
/
similar_hash_classify.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
'''
disaster_array = ["napa_earthquake", "michigan_storm", "california_fire", "washington_mudslide", "iowa_stf", "iowa_storm", "jersey_storm",
"oklahoma_storm", "iowa_stf_2", "vermont_storm", "virginia_storm", "texas_storm", "washington_storm",
"washington_wildfire", "newyork_storm"]
'''
disaster_array = ["napa_earthquake", "michigan_storm", "newyork_storm", "texas_storm", "iowa_stf", "iowa_stf_2", "iowa_storm", "washington_storm", "jersey_storm", "california_fire", "washington_mudslide"]
for ij in xrange(len(disaster_array)):
print "\n\n", disaster_array[ij]
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_affected_filtered_conv_hash.txt") as f:
affect_filter = sum(1 for _ in f)
print 'the number of affected hash filtered tweets', affect_filter
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_unaffected_filtered_conv_hash.txt") as f:
unaffect_filter = sum(1 for _ in f)
print 'the number of unaffected hash filtered tweets', unaffect_filter
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_affected_filtered_classify.txt") as f:
affect_filter_related = sum(1 for _ in f)
print 'the number of affected_' + 'classification_related tweets', affect_filter_related
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_unaffected_filtered_classify.txt") as f:
unaffect_filter_related = sum(1 for _ in f)
print 'the number of unaffected_' + 'classification_related tweets', unaffect_filter_related
#print "Total tweets: ", disaster_array[ij], ": ", affect_unfilter + unaffect_unfilter
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_affected_filtered_conv_hash.txt") as f:
#affect_filter = sum(1 for _ in f)
#print 'the number of affected_filtered tweets', affect_filter
affected_filter_arr = []
for line in f:
a = [x.strip() for x in line.split(',')]
#print len(a)
if len(a) > 5:
st = ""
for i in xrange(0, len(a) - 4):
if i == len(a) - 5:
st += a[i]
else:
st += a[i] + ", "
affected_filter_arr.append(st)
#for i in xrange(len(a) - 4, len(a)):
# arr.append(a[i])
else:
affected_filter_arr.append(a[0])
#print len(arr)
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_unaffected_filtered_conv_hash.txt") as f:
#unaffect_filter = sum(1 for _ in f)
#print 'the number of unaffected_filtered tweets', unaffect_filter
unaffected_filter_arr = []
for line in f:
a = [x.strip() for x in line.split(',')]
#print len(a)
if len(a) > 5:
st = ""
for i in xrange(0, len(a) - 4):
if i == len(a) - 5:
st += a[i]
else:
st += a[i] + ", "
unaffected_filter_arr.append(st)
#for i in xrange(len(a) - 4, len(a)):
# arr.append(a[i])
else:
unaffected_filter_arr.append(a[0])
#print len(arr)
#print "Total tweets: ", disaster_array[ij], ": ", affect_unfilter + unaffect_unfilter
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_affected_filtered_classify.txt") as f:
#affect_filter_related = sum(1 for _ in f)
#print 'the number of affected_' + 'classification_related tweets', affect_filter_related
affected_related_arr = []
for line in f:
a = [x.strip() for x in line.split(',')]
# print len(a)
if len(a) > 5:
st = ""
for i in xrange(0, len(a) - 4):
if i == len(a) - 5:
st += a[i]
else:
st += a[i] + ", "
affected_related_arr.append(st)
# for i in xrange(len(a) - 4, len(a)):
# arr.append(a[i])
else:
affected_related_arr.append(a[0])
with open("./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_unaffected_filtered_classify.txt") as f:
#unaffect_filter_related = sum(1 for _ in f)
#print 'the number of unaffected_' + 'classification_related tweets', unaffect_filter_related
unaffected_related_arr = []
for line in f:
a = [x.strip() for x in line.split(',')]
# print len(a)
if len(a) > 5:
st = ""
for i in xrange(0, len(a) - 4):
if i == len(a) - 5:
st += a[i]
else:
st += a[i] + ", "
unaffected_related_arr.append(st)
# for i in xrange(len(a) - 4, len(a)):
# arr.append(a[i])
else:
unaffected_related_arr.append(a[0])
affected_output = "./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_affected_intersection.txt"
unaffected_output = "./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_unaffected_intersection.txt"
affected_unrelated_output = "./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_affected_unrelated_intersection.txt"
unaffected_unrelated_output = "./data/disasters/" + disaster_array[ij] + "/" + disaster_array[ij] + "_unaffected_unrelated_intersection.txt"
count_filter = 0
with open(affected_unrelated_output, "wb") as f3:
with open(affected_output, "wb") as f2:
for i in affected_filter_arr:
#print i
if i in affected_related_arr:
f2.write(i[1:] + "\n")
count_filter += 1
else:
f3.write(i[1:] + "\n")
print disaster_array[ij], " Affected Intersection: ", count_filter
count_unfilter = 0
with open(unaffected_unrelated_output, "wb") as f3:
with open(unaffected_output, "wb") as f2:
for i in unaffected_filter_arr:
# print i
if i in unaffected_related_arr:
f2.write(i[1:] + "\n")
count_unfilter += 1
else:
f3.write(i[1:] + "\n")
print disaster_array[ij], " Unaffected Intersection: ", count_unfilter
'''
for i in affected_related_arr:
# print i
if i in affected_filter_arr:
continue
else:
print i
'''
print count_unfilter
print "Recall hash affected :", (count_filter / (affect_filter * 1.0)) * 100
print "Recall classify affected :", (count_filter / (affect_filter_related * 1.0)) * 100
print "Recall hash unaffected :", (count_unfilter / (unaffect_filter * 1.0)) * 100
print "Recall classify unaffected :", (count_unfilter / (unaffect_filter_related * 1.0)) * 100
#print "Total tweets: ", disaster_array[ij], ": ", affect_unfilter + unaffect_unfilter