-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanalyze_events.py
144 lines (123 loc) · 4.98 KB
/
analyze_events.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
import sys
import codecs
#parse qualtrics files
qualtrics_csx = codecs.open(sys.argv[1],"r","utf-8")
qualtrics_cs = codecs.open(sys.argv[2],"r","utf-8")
qualtrics_ngram = codecs.open(sys.argv[3],"r","utf-8")
qualtrics_csx_str = qualtrics_csx.read()
qualtrics_cs_str = qualtrics_cs.read()
qualtrics_ngram_str = qualtrics_ngram.read()
qualtrics_csx.close()
qualtrics_cs.close()
qualtrics_ngram.close()
cs_events = []
ngram_events = []
csx = qualtrics_csx_str.split("[[Question:MC:SingleAnswer:Vertical]]")[1:501]
cs = qualtrics_cs_str.split("[[Question:MC:SingleAnswer:Vertical]]")[1:501]
ngram = qualtrics_ngram_str.split("[[Question:MC:SingleAnswer:Vertical]]")[1:501]
for event in range(0,500,2):
events_dict = {}
tweets_csx = csx[event].split("<br />\n\t\t\t<br />\n\t\t\t")
tweet_csx1 = tweets_csx[0].split("<b>")[-1]
tweets_csxfinal = [tweet_csx1] + tweets_csx[1:-1]
events_dict["tweets"] = tweets_csxfinal
terms_csx = [x.split("<b>")[-1] for x in csx[event+1].split("</b>")[:-1]]
events_dict["terms+"] = terms_csx
terms_cs = [x.split("<b>")[-1] for x in cs[event+1].split("</b>")[:-1]]
events_dict["terms"] = terms_cs
cs_events.append(events_dict)
ngram_dict = {}
tweets_ngram = ngram[event].split("<br />\n\t\t\t<br />\n\t\t\t")
tweet_ngram1 = tweets_ngram[0].split("<b>")[-1]
tweets_ngramfinal = [tweet_ngram1] + tweets_ngram[1:-1]
ngram_dict["tweets"] = tweets_ngramfinal
terms_ngram = [x.split("<b>")[-1] for x in ngram[event+1].split("</b>")[:-1]]
ngram_dict["terms"] = terms_ngram
ngram_events.append(ngram_dict)
#add human assessments
annotations_cs_csx = open(sys.argv[4])
annotations_ngram = open(sys.argv[5])
lines_cs_csx = annotations_cs_csx.readlines()
lines_ngram = annotations_ngram.readlines()
annotations_ngram.close()
annotations_cs_csx.close()
for i,line in enumerate(lines_cs_csx):
event = cs_events[i]
ass = line.strip().split("\t")
if ass.count('1') == 4:
event["assessment"] = "event"
if ass.count('1') == 3:
event["assessment"] = "75"
if ass.count('1') == 2:
event["assessment"] = "50"
if ass.count('1') == 1:
event["assessment"] = "25"
if ass.count('1') == 0:
event["assessment"] = "no_event"
for i,line in enumerate(lines_ngram):
event = ngram_events[i]
ass = line.strip().split("\t")
if ass.count('1') == 2:
event["assessment"] = "event"
if ass.count('1') == 1:
event["assessment"] = "50"
if ass.count('1') == 0:
event["assessment"] = "no_event"
terms_cs = open(sys.argv[6])
terms_csx = open(sys.argv[7])
terms_ngram = open(sys.argv[8])
lines_cs = terms_cs.readlines()
lines_csx = terms_csx.readlines()
lines_ngram = terms_ngram.readlines()
terms_cs.close()
terms_csx.close()
terms_ngram.close()
print len(lines_cs),len(lines_csx),len(lines_ngram)
for i,line in enumerate(lines_cs):
event = cs_events[i]
ass = line.strip().split("\t")
if ass.count('3') == 2 or ass.count('3') == 1 and "miss" in ass:
event["termassess_cs"] = "GOOD"
elif ass.count('1') == 2 or ass.count('1') == 1 and "miss" in ass:
event["termassess_cs"] = "BAD"
elif ass.count('2') == 2 or ass.count('2') == 1 and "miss" in ass:
event["termassess_cs"] = "MED"
elif ass.count('miss') == 2:
event["termassess_cs"] = "MISS"
else:
event["termassess_cs"] = "MIXED"
for i,line in enumerate(lines_csx):
event = cs_events[i]
ass = line.strip().split("\t")
if ass.count('3') == 2 or ass.count('3') == 1 and "miss" in ass:
event["termassess_csx"] = "GOOD"
elif ass.count('1') == 2 or ass.count('1') == 1 and "miss" in ass:
event["termassess_csx"] = "BAD"
elif ass.count('2') == 2 or ass.count('2') == 1 and "miss" in ass:
event["termassess_csx"] = "MED"
elif ass.count('miss') == 2:
event["termassess_csx"] = "MISS"
else:
event["termassess_csx"] = "MIXED"
for i,line in enumerate(lines_ngram):
event = ngram_events[i]
ass = line.strip().split("\t")
if ass.count('3') == 2 or ass.count('3') == 1 and "miss" in ass:
event["termassess"] = "GOOD"
elif ass.count('1') == 2 or ass.count('1') == 1 and "miss" in ass:
event["termassess"] = "BAD"
elif ass.count('2') == 2 or ass.count('2') == 1 and "miss" in ass:
event["termassess"] = "MED"
elif ass.count('miss') == 2:
event["termassess"] = "MISS"
else:
event["termassess"] = "MIXED"
#write to file
cs_csx_out = codecs.open(sys.argv[9],"w","utf-8")
ngram_out = codecs.open(sys.argv[10],"w","utf-8")
for i,event in enumerate(cs_events):
cs_csx_out.write('\t'.join([str(i),"LINEBREAK".join(event["tweets"]),event["assessment"],",".join(event["terms"]),",".join(event["terms+"]),event["termassess_cs"],event["termassess_csx"]]) + "\n")
for i,event in enumerate(ngram_events):
ngram_out.write('\t'.join([str(i),"LINEBREAK".join(event["tweets"]),event["assessment"],",".join(event["terms"]),event["termassess"]]) + "\n")
cs_csx_out.close()
ngram_out.close()