-
Notifications
You must be signed in to change notification settings - Fork 2
/
tool_irb_synthetic_forms.py
398 lines (369 loc) · 19.7 KB
/
tool_irb_synthetic_forms.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
import narrativehelper
import synthetichelper
import random
import settings
def riu_parse(data):
lines = data.splitlines(False)
state = 0
text = ''
mappings = []
stories = []
for line in lines:
if 'mapping:' in line:
if text:
stories.append((text,mappings))
text = ''
mappings = []
state = 1
elif state == 1 and line.strip().startswith('('):
mappings.append(line)
elif state ==1 and not line.strip():
state = 2
elif state in [2,3] and line.strip():
text+=line.strip()+'\n'
state = 3
elif state ==3 and not line.strip():
state= 4
else:
pass # ignore blank lines when state = 4
stories.append((text, mappings))
return [(riu_text_clean(text),riu_parse_mapping(mappings)) for text,mappings in stories]
def riu_text_clean(text):
return text
def riu_parse_mapping(text):
tokens = ' '.join(text).replace('(',' ').replace(')',' ').split()
if not text: return (0,[])
score = float(tokens[0])
mappings = zip(tokens[1::2],tokens[2::2])
return (score,mappings)
def get_stories_from_parsed_riu_output():
path = '/Users/josepvalls/voz2/sam-clisp-irb/'
story_data = synthetichelper.get_data(True,True)
story_sets = []
for story_id in range(40):
segment_text = story_data[story_id][0]
segment_text_0 = '\n'.join(i for i in segment_text[0][1])
segment_text = story_data[story_id][1]
segment_text_1 = '\n'.join(i for i in segment_text[0][1])
'''for segment_i,segment in enumerate(story_data[story_id]):
#print segment
segment_text = '\n'.join(i for i in segment[0][1])
#print segment_text'''
data = riu_parse(open(path+'voz-complete-%d-levinverb_nofunc_roleexp_prep_voz.lisp.txt' % (story_id+1)).read())
print 'START:\n'+segment_text_0
print 'GOOD:\n' + segment_text_1
print 'CONTINUE:\n'+data[0][0]
print data[0][1]
def get_story_sets(stories):
story_sets = []
story_ids = list(enumerate(stories))
for id,story in story_ids:
story_set = []
story_set.append((story[0][1],story[1][1]))
exclude = set([id])
for _ in range(4):
while True:
selected = random.choice(story_ids)
if selected[0] not in exclude: break
exclude.add(selected[0])
story_set.append((story[0][1], selected[1][1][1],'X%d'%_))
random.shuffle(story_set)
story_sets.append(story_set)
return story_sets
def get_story_sets_from_file():
story_sets = []
lines = open(settings.PATH_BASE +'stories/synthetic-results.tsv').readlines()
lines = [i.strip() for i in lines]
starts = lines[1::11]
goods = lines[3::11]
c_1 = lines[5::11]
c_2 = lines[7::11]
c_3 = lines[9::11]
for s,g,c1,c2,c3,i in zip(starts,goods,c_1,c_2,c_3,range(len(starts))):
story_sets.append([(s,g,'s%dc0'%i),(s,c1,'s%dc1'%i),(s,c2,'s%dc2'%i),(s,c3,'s%dc3'%i)])
return story_sets
def html_format_story_set(story_sets,template=1,sources=''):
html = ''
for id_, story_set in enumerate(story_sets):
html_options = ''
for cid_,option in enumerate(story_set):
text_set,text_cont,source = option
#text_set = ' '.join(text_set)
#text_cont = ' '.join(text_cont)
if template == 1:
template_form = TEMPLATE_HTML_FORM_1
template_form_options = TEMPLATE_HTML_FORM_1_OPTIONS
elif template == 2:
template_form = TEMPLATE_HTML_FORM_2
template_form_options = TEMPLATE_HTML_FORM_2_OPTIONS
elif template == 3:
template_form = TEMPLATE_HTML_FORM_2
template_form_options = TEMPLATE_HTML_FORM_3_OPTIONS
html_options += template_form_options.replace('%ID%',str(id_+1)).replace('%CID%',str(cid_+1)).replace('%CONTINUATION%',text_cont)
html += template_form.replace('%OPTIONS%',html_options).replace('%ID%',str(id_+1)).replace('%SETUP%',text_set).replace('%SOURCES%',sources)
html = TEMPLATE_HTML.replace('%FORM%',html)
return html
def get_html_form(randomize=False):
story_sets = get_story_sets_from_file()
if randomize:
story_sets_ = story_sets[1:]
else:
story_sets_ = story_sets[1:6]
random.shuffle(story_sets_)
story_sets = [story_sets[0]] + story_sets_[1:6]
for i in story_sets[1:]:
random.shuffle(i)
sources = ''
for i in story_sets:
for j in i:
sources += j[2] + ' '
sources = sources.strip()
print sources
return html_format_story_set(story_sets, 3, sources)
def main():
import pprint
pp = pprint.pprint
#get_stories_from_parsed_riu_output()
#return
stories = synthetichelper.get_data(do_segment=False)
for story in stories[0:5]:
#pprint.pprint(story)
print "SAMPLE STORY"
print story[0]
print "sets"
story_sets = get_story_sets(stories)[0:5]
pp(story_sets[0])
story_sets = get_story_sets_from_file()
pp(story_sets[0])
print "html"
with open("tool_irb_form_1.html",'w') as f:
f.write(html_format_story_set(story_sets,1))
with open("tool_irb_form_2.html",'w') as f:
f.write(html_format_story_set(story_sets,2))
with open("tool_irb_form_3.html",'w') as f:
f.write(html_format_story_set(story_sets,3))
with open("tool_irb_form_4.html",'w') as f:
f.write(get_html_form(False))
TEMPLATE_HTML = '''<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Evaluation of Automatic Story Generation Systems</title>
<link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
function is_touch_device() {
return 'ontouchstart' in window // works on most browsers
|| navigator.maxTouchPoints; // works on IE10/11 and Surface
};
$( document ).ready(function() {
if(!is_touch_device()){
$( function() {
$( "input:radio" ).checkboxradio({
icon: false
});
} );
$( function() {
$( document ).tooltip({
show: {
delay: 0
}
});
} );
$( function() {
$( "textarea.resizable" ).resizable({
handles: "se",
containment: "#questions",
minHeight: 40,
minWidth: 200
});
});
$('input:text, input:submit').addClass("ui-button ui-widget ui-widget-content ui-corner-all");
} else {
$( "#tooltips_note" ).remove();
}
$('input:radio').change(function() {
var formData = JSON.stringify($("#questions").serializeArray());
console.log(formData);
$.ajax({
type: "POST",
url: "/json",
data: formData,
dataType: "json",
contentType : "application/json"
});
});
$('textarea').blur(function() {
var formData = JSON.stringify($("#questions").serializeArray());
console.log(formData);
$.ajax({
type: "POST",
url: "/json",
data: formData,
dataType: "json",
contentType : "application/json"
});
});
});
</script>
<style type="text/css">
body { font-family: Arial,Helvetica,sans-serif; font-size: 1em; width: 50em; margin-left: auto; margin-right: auto;}
fieldset { margin-bottom: 1em;}
legend.continuation-title {font-size:1.5em;}
.ui-tooltip {background-color: #F0E68C;}
em, fieldset.rating label, label.rating {text-decoration-color: #9C911D; text-decoration-line: underline;}
em, fieldset.rating label, label.rating {-webkit-text-decoration: #9C911D underline wavy;}
li {border-bottom: 2px dashed #F0E68C;}
p.initial, p.continuation {padding: 0.5em;}
.initial { background-color: #AEBEE3;}
.continuation { background-color: #D0B2E3;}
p.continuation {margin-top: -1em;}
h2 small {font-style: italic;}
.ui-resizable-se { bottom: 17px;}
textarea.resizable {margin-top: 0.25em;}
</style>
</head>
<body>
<form action="/form2" method="POST" id="questions">
<h1>Evaluation of Automatic Story Generation Systems</h1>
<p>In this page we will show you several short story snippets.
We will show you multiple variations of each story. The different variations share a common initial setup (<span class="initial">highlighted in blue</span>) but vary in that each has a different continuation (<span class="continuation">highlighted in purple</span>).
We ask you to read each of them and rate each of the continuations in terms of how well they follows the initial setup and your overall satisfaction with the text.</p>
<p id="tooltips_note">Note that throughout this page, you will find pieces of <em title="This is an example of the additional explanations you may find throughout this page.">text in italics</em>. Feel free to hover your mouse cursor on them to obtain additional explanations.</p>
<p>When you are finished, please click the <strong>Submit</strong> button at the bottom of the page to save your answers.</p>
%FORM%
<hr/>
<p>Please review your answers, when you are finished, please click the <strong>Submit</strong> button below.</p>
<input type="hidden" name="form" value="f1"/>
<input type="hidden" name="uuid" value="%UUID%"/>
<input type="submit" name="submit" value="Submit"/>
<hr/>
<p>This research is conducted by a researcher who is a member of Drexel University.</p>
</form>
</body>
</html>'''
TEMPLATE_HTML_FORM_1 = '''
<h2>Story %ID%</h2>
<p>%SETUP%</p>
%OPTIONS%
'''
TEMPLATE_HTML_FORM_1_OPTIONS = '''
<fieldset>
<legend class="continuation-title">Continuation %ID% %CID%</legend>
<p>%CONTINUATION%</p>
<fieldset class="rating">
<legend>How do you rate this story?</legend>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-1" value="1"><label for="r%ID%-%CID%-1" title="The story makes no sense or there were major issues in the text that make it incomprehensible.">Awful</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-2" value="2"><label for="r%ID%-%CID%-2" title="The story makes little sense or issues in the text make it difficult to follow.">Bad</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-3" value="3"><label for="r%ID%-%CID%-3" title="There were major issues with the story and text.">Mediocre</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-4" value="4"><label for="r%ID%-%CID%-4" title="There were minor issues with the story and text.">Fair</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-5" value="5"><label for="r%ID%-%CID%-5" title="The story makes sense but there were minor issues in the text.">Good</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-6" value="6"><label for="r%ID%-%CID%-6" title="The story was well written and enjoyable.">Great</label>
</fieldset>
<fieldset>
<legend>Please, explain your rating</legend>
Did the continuation follow a reasonable <em title="The events described in the story.">plot</em> after the given initial story setup?
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-y" value="y"><label for="q%ID%-%CID%-1-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-n" value="n"><label for="q%ID%-%CID%-1-n">No</label>
<br/>
Were the <em title="Persons or animals portrayed in the story.">characters</em> mentioned in the continuation coherent with the initial story setup?
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-y" value="y"><label for="q%ID%-%CID%-2-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-n" value="n"><label for="q%ID%-%CID%-2-n">No</label>
<br/>
Was there any mismatch between the characters mentioned within the continuation?
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-y" value="y"><label for="q%ID%-%CID%-3-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-n" value="n"><label for="q%ID%-%CID%-3-n">No</label>
<br/>
Were there other issue in the text such as missing or extraneous words or punctuation?
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-y" value="y"><label for="q%ID%-%CID%-4-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-n" value="n"><label for="q%ID%-%CID%-4-n">No</label>
</fieldset>
</fieldset>
'''
TEMPLATE_HTML_FORM_2 = '''
<input type="hidden" name="sources" value="%SOURCES%">
%OPTIONS%
'''
TEMPLATE_HTML_FORM_2_OPTIONS = '''
<h2>Story %ID% - Variation %CID%</h2>
<p class="initial">%SETUP%</p>
<p class="continuation">%CONTINUATION%</p>
How do you rate this story?
(<em title="The story makes no sense or there were major issues in the text that make it incomprehensible.">worst</em>)
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-1"><label class="rating" for="r%ID%-%CID%-1" title="The story makes no sense or there were major issues in the text that make it incomprehensible.">1</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-2"><label class="rating" for="r%ID%-%CID%-2"title="The story makes little sense or issues in the text make it difficult to follow.">2</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-3"><label class="rating" for="r%ID%-%CID%-3"title="There were major issues with the story and text.">3</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-4"><label class="rating" for="r%ID%-%CID%-4"title="There were minor issues with the story and text.">4</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-5"><label class="rating" for="r%ID%-%CID%-5"title="The story makes sense but there were minor issues in the text.">5</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-6"><label class="rating" for="r%ID%-%CID%-6"title="The story was well written and enjoyable.">6</label>
(<em The story was well written and enjoyable.>best</em>)
<br/>
Did the <em title="The events described in the story.">plot</em> of this continuation follow reasonably from that of the initial setup?
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-y"><label for="q%ID%-%CID%-1-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-n"><label for="q%ID%-%CID%-1-n">No</label>
<br/>
Were the <em title="Persons or animals portrayed in the story.">characters</em> mentioned in the continuation coherent with the initial story setup?
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-y"><label for="q%ID%-%CID%-2-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-n"><label for="q%ID%-%CID%-2-n">No</label>
<br/>
Was there any mismatch between the characters mentioned within the continuation?
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-y"><label for="q%ID%-%CID%-3-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-n"><label for="q%ID%-%CID%-3-n">No</label>
<br/>
Were there other issues in the text such as missing or extraneous words or punctuation?
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-y"><label for="q%ID%-%CID%-4-y">Yes</label>
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-n"><label for="q%ID%-%CID%-4-n">No</label>
'''
TEMPLATE_HTML_FORM_3_OPTIONS = '''
<h2>Story %ID% <small>Variation %CID%</small></h2>
<p class="initial">%SETUP%</p>
<p class="continuation">%CONTINUATION%</p>
How do you rate this story considering both the <span class="initial">story setup</span> and the <span class="continuation">continuation</span>?<br/>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-1" value="1"><label for="r%ID%-%CID%-1" title="The story makes no sense or there were major issues in the text that make it incomprehensible.">Awful</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-2" value="2"><label for="r%ID%-%CID%-2" title="The story makes little sense or issues in the text make it difficult to follow.">Bad</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-3" value="3"><label for="r%ID%-%CID%-3" title="There were major issues with the story and text.">Mediocre</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-4" value="4"><label for="r%ID%-%CID%-4" title="There were minor issues with the story and text.">Fair</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-5" value="5"><label for="r%ID%-%CID%-5" title="The story makes sense but there were minor issues in the text.">Good</label>
<input type="radio" name="r%ID%-%CID%" id="r%ID%-%CID%-6" value="6"><label for="r%ID%-%CID%-6" title="The story was well written and enjoyable.">Great</label>
<br/>
<table><tr><td>
Did the <span class="continuation">continuation</span> follow a reasonable <em title="The events described in the story.">plot</em> after the given initial <span class="initial">story setup</span>?
</td><td>
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-y" value="y"><label for="q%ID%-%CID%-1-y">Yes</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-a" value="a"><label for="q%ID%-%CID%-1-a">Almost</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-1" id="q%ID%-%CID%-1-n" value="n"><label for="q%ID%-%CID%-1-n">No</label>
</td></tr><tr><td>
Did the <em title="Persons or animals portrayed in the story.">characters</em> mentioned in the continuation match the ones in the initial <span class="initial">story setup</span>?
</td><td>
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-y" value="y"><label for="q%ID%-%CID%-2-y">Yes</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-a" value="a"><label for="q%ID%-%CID%-2-a">Almost</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-2" id="q%ID%-%CID%-2-n" value="n"><label for="q%ID%-%CID%-2-n">No</label>
</td></tr><tr><td>
Looking only at the <span class="continuation">continuation</span>, was there any <em title="Such as disagreements in gender/number between the nouns and pronouns.">mismatch</em> between the characters mentioned?
</td><td>
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-y" value="y"><label for="q%ID%-%CID%-3-y">Yes</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-a" value="a"><label for="q%ID%-%CID%-3-a">Almost</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-3" id="q%ID%-%CID%-3-n" value="n"><label for="q%ID%-%CID%-3-n">No</label>
</td></tr><tr><td>
Did you notice any <em title="Such as missing or extraneous words or punctuation.">grammar</em> issues in the text of the continuation?
</td><td>
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-y" value="y"><label for="q%ID%-%CID%-4-y">Yes</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-a" value="a"><label for="q%ID%-%CID%-4-a">Almost</label>
</td><td>
<input type="radio" name="q%ID%-%CID%-4" id="q%ID%-%CID%-4-n" value="n"><label for="q%ID%-%CID%-4-n">No</label>
</td></tr>
<tr><td colspan="3">
Did you have any other issues or have any other comments you would like to share with us about this story?<br/>
<textarea name="o%ID%-%CID%" class="resizable ui-widget ui-state-default ui-corner-all"" rows="2" cols="30"></textarea>
</td></tr></table>
'''
if __name__=='__main__':
main()