-
Notifications
You must be signed in to change notification settings - Fork 7
/
LexTALE_nl.py
512 lines (489 loc) · 13.1 KB
/
LexTALE_nl.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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
from psychopy.visual import Window, TextStim, Rect
from psychopy.core import wait, Clock, quit
from psychopy.event import clearEvents, waitKeys, getKeys, Mouse
from psychopy.gui import Dlg
from time import gmtime, strftime
from codecs import open
testing = False # True for testing, False for real recording
if testing:
fullscreen = False
escape_key = 'escape'
instr_wait = 0.1
else:
escape_key = 'notallowed'
instr_wait = 0.5
fullscreen = True
instruction_color = '#9999FF'
lextale_data = {'corr_nonword': 0, 'corr_word': 0}
# EXECUTE all main functions here
def execute():
start_input() # prompt to input stuff
set_screen() # creates psychopy screen and stim objects
# window opens
create_file() # created output file
run_lextale() # begin task & run until finished
print("************** END OF EXPERIMENT **************")
ending() # saves demographic & final infos, gives feedback
waitKeys(keyList = ['b']) # press B to end the exp (prevents subject from closing window)
quit()
def ending():
lextale_score = (lextale_data['corr_word'] / 40 * 100 + lextale_data['corr_nonword'] / 20 * 100) / 2;
lex_sumup = 'correct_responses_to_words\t' + str(lextale_data['corr_word']) + '\ncorrect_responses_to_nonwords\t' + str(lextale_data['corr_nonword']) + '\nlextale_score\t' + str(lextale_score)
print(lex_sumup)
data_out.write(lex_sumup)
info = 'The LexTALE test is completed.'
data_out.close()
show_instruction( info )
def set_screen(): # screen properties
global win, start_text, left_label, right_label, center_disp, instruction_page, left_bg, right_bg, ok_button, ok_text
win = Window([1280, 1000], color='Black', fullscr = fullscreen, screen = 0, units = 'pix', allowGUI = True) # 1280 1024
text_left = 'nee'
text_right = 'ja'
h_dist = 80
v_dist = -190
left_bg = Rect(win, fillColor = 'red', pos = [-h_dist,v_dist-7], width = 130, height = 85)
right_bg = Rect(win, fillColor = 'green', pos = [h_dist,v_dist-7], width = 130, height = 85)
left_label = TextStim(win, color='white', font='Verdana', text = text_left, pos = [-h_dist,v_dist], height=50, alignHoriz='center')
right_label = TextStim(win, color='white', font='Verdana', text = text_right, pos = [h_dist,v_dist], height=50, alignHoriz='center')
center_disp = TextStim(win, color='white', font='Arial', text = '', height = 55)
instruction_page = TextStim(win, wrapWidth = 1200, pos = [0, 35], height = 28, font='Verdana', color = instruction_color)
ok_button = Rect(win, fillColor = 'black', lineColor = instruction_color, pos = [0,-345], width = 80, height = 50)
ok_text = TextStim(win, text = 'OK', bold = True, color=instruction_color, pos=(0,-345), height = 30)
def start_input():
global subj_id
input_box = Dlg(title=u'LexTALE start', labelButtonOK=u'OK', labelButtonCancel=u'Cancel')
input_box.addText(text=u'')
input_box.addField(label=u'Subject ID')
input_box.addText(text=u'')
input_box.show()
if input_box.OK:
subj_num = input_box.data[0]
subj_id = subj_num + "_" + str(strftime("%Y%m%d%H%M%S", gmtime()))
else:
quit()
# create output file, begin writing, reset parameters
def create_file():
global data_out
f_name = 'lextale_en_results_' + subj_id + '.txt'
data_out=open(f_name, 'a', encoding='utf-8')
data_out.write( '\t'.join( [ "subject_id", "trial_number", "stimulus_shown", "dummy", "real", "response_key", "rt_start", "incorrect", "date_in_ms" ] ) + "\n" )
print("File created:", f_name)
def add_resp():
data_out.write( '\t'.join( [ subj_id, str(trial_num+1), stim_text, str(stim_type), str(stim_status), response, str(rt_start*1000), str(incorrect), str(strftime("%Y%m%d%H%M%S", gmtime())) ] ) + '\n' )
print("resp key:", response, "for stim:", stim_text, "incorrect:", incorrect, "rt_start:", rt_start)
def draw_labels():
left_bg.draw()
right_bg.draw()
left_label.draw()
right_label.draw()
def show_instruction(instruction_text):
instruction_page.setText(instruction_text)
instruction_page.draw()
win.flip()
wait(instr_wait)
inst_resp = waitKeys(keyList = ['space', escape_key])
end_on_esc(inst_resp[0])
def run_lextale():
global trial_num, stim_text, stim_type, stim_status, incorrect, response, rt_start
print("len(blck_itms):", len(lextale_items))
maus = Mouse()
instruction_page.setText(lextale_instructions)
instruction_page.draw()
ok_button.draw()
ok_text.draw()
win.flip()
while not maus.isPressedIn( ok_button, buttons = [0] ):
pass
stopwatch = Clock()
for trial_num in range(len(lextale_items)): # go through all stimuli of current block
print("------- Trial number:", trial_num )
stim_current = lextale_items[trial_num]
stim_type = stim_current["dummy"]
stim_text = stim_current["word"]
stim_status = stim_current["wstatus"]
center_disp.setText(stim_text)
draw_labels()
center_disp.draw()
win.callOnFlip(stopwatch.reset)
clearEvents()
win.flip()
while True:
if maus.isPressedIn( right_bg, buttons = [0] ):
rt_start = stopwatch.getTime()
response = 'yes'
right_bg.fillColor = "darkgreen"
draw_labels()
center_disp.draw()
win.flip()
while maus.isPressedIn( right_bg, buttons = [0] ):
pass
right_bg.fillColor = "green"
if stim_status == 1:
incorrect = 0
if stim_type == 0:
lextale_data['corr_word'] = lextale_data['corr_word'] + 1
else:
incorrect = 1
break
elif maus.isPressedIn( left_bg, buttons = [0] ):
rt_start = stopwatch.getTime()
response = 'no'
left_bg.fillColor = "darkred"
draw_labels()
center_disp.draw()
win.flip()
while maus.isPressedIn( left_bg, buttons = [0] ):
pass
left_bg.fillColor = "red"
if stim_status == 0:
incorrect = 0
if stim_type == 0:
lextale_data['corr_nonword'] = lextale_data['corr_nonword'] + 1
else:
incorrect = 1
break
elif len(getKeys(keyList=[escape_key], timeStamped=stopwatch)) > 0:
end_on_esc(escape_key)
draw_labels()
center_disp.draw()
win.flip()
add_resp() # store trial data
# end session
def end_on_esc(escap):
if escap == escape_key : # escape
print("Trying to escape?")
instruction_page.setText('Sure you want to discontinue and quit the experiment?\n\nPress "y" to quit, or press "n" to continue.')
instruction_page.draw()
win.flip()
wait(instr_wait)
quit_resp = waitKeys(keyList = ['y', 'n'])
if quit_resp[0] == 'y':
print("************ ESCAPED ************")
data_out.close()
win.close()
quit()
else:
clearEvents()
print("Continuing...")
lextale_instructions = 'Deze test bestaat uit ongeveer 60 trials. Je krijgt steeds een letterreeks te zien. Jouw taak is om te beslissen of dit een bestaand Nederlands woord is of niet. Als je denkt dat het een bestaand Nederlands woord is klik je op "ja", als je denkt dat het geen bestaand Nederlands woord is klik je op "nee". \n\nAls je er zeker van bent dat het woord bestaat, ook als je niet precies weet wat het betekent, mag je toch met "ja" antwoorden. Maar als je twijfelt of het wel een bestaand woord is, kies dan "nee".\n\nJe hebt zoveel tijd als je wilt voor elke beslissing. Dit deel van het experiment duurt ongeveer 5 minuten. \n\nAls alles duidelijk is kun je het experiment nu starten.'
lextale_items = [{
'word': "pastitie",
'wstatus': 0,
'dummy': 1
},
{
'word': "scheur",
'wstatus': 1,
'dummy': 1
},
{
'word': "fobisch",
'wstatus': 1,
'dummy': 1
},
{
'word': "markatief",
'wstatus': 0,
'dummy': 0
},
{
'word': "laakbaar",
'wstatus': 1,
'dummy': 0
},
{
'word': "slaags",
'wstatus': 1,
'dummy': 0
},
{
'word': "riant",
'wstatus': 1,
'dummy': 0
},
{
'word': "joutbaag",
'wstatus': 0,
'dummy': 0
},
{
'word': "doornat",
'wstatus': 1,
'dummy': 0
},
{
'word': "woelig",
'wstatus': 1,
'dummy': 0
},
{
'word': "paviljoen",
'wstatus': 1,
'dummy': 0
},
{
'word': "doop",
'wstatus': 1,
'dummy': 0
},
{
'word': "starkatie",
'wstatus': 0,
'dummy': 0
},
{
'word': "onledig",
'wstatus': 1,
'dummy': 0
},
{
'word': "toetsing",
'wstatus': 1,
'dummy': 0
},
{
'word': "affiniteit",
'wstatus': 1,
'dummy': 0
},
{
'word': "mikken",
'wstatus': 1,
'dummy': 0
},
{
'word': "knullig",
'wstatus': 1,
'dummy': 0
},
{
'word': "streuren",
'wstatus': 0,
'dummy': 0
},
{
'word': "rups",
'wstatus': 1,
'dummy': 0
},
{
'word': "paars",
'wstatus': 1,
'dummy': 0
},
{
'word': "speven",
'wstatus': 0,
'dummy': 0
},
{
'word': "geraakt",
'wstatus': 1,
'dummy': 0
},
{
'word': "martelaar",
'wstatus': 1,
'dummy': 0
},
{
'word': "ontpelen",
'wstatus': 0,
'dummy': 0
},
{
'word': "stagnatie",
'wstatus': 1,
'dummy': 0
},
{
'word': "dronkenschap",
'wstatus': 1,
'dummy': 0
},
{
'word': "voornemen",
'wstatus': 1,
'dummy': 0
},
{
'word': "vertediseren",
'wstatus': 0,
'dummy': 0
},
{
'word': "normatief",
'wstatus': 1,
'dummy': 0
},
{
'word': "zetelen",
'wstatus': 1,
'dummy': 0
},
{
'word': "zolf",
'wstatus': 0,
'dummy': 0
},
{
'word': "publiekelijk",
'wstatus': 1,
'dummy': 0
},
{
'word': "vluk",
'wstatus': 0,
'dummy': 0
},
{
'word': "compromeet",
'wstatus': 0,
'dummy': 0
},
{
'word': "romig",
'wstatus': 1,
'dummy': 0
},
{
'word': "getint",
'wstatus': 1,
'dummy': 0
},
{
'word': "gelovig",
'wstatus': 1,
'dummy': 0
},
{
'word': "nopen",
'wstatus': 1,
'dummy': 0
},
{
'word': "kluiper",
'wstatus': 0,
'dummy': 0
},
{
'word': "geloei",
'wstatus': 1,
'dummy': 0
},
{
'word': "retorisch",
'wstatus': 1,
'dummy': 0
},
{
'word': "maliteit",
'wstatus': 0,
'dummy': 0
},
{
'word': "verspilling",
'wstatus': 1,
'dummy': 0
},
{
'word': "haperie",
'wstatus': 0,
'dummy': 0
},
{
'word': "proom",
'wstatus': 0,
'dummy': 0
},
{
'word': "fornuis",
'wstatus': 1,
'dummy': 0
},
{
'word': "exploitatie",
'wstatus': 1,
'dummy': 0
},
{
'word': "acteur",
'wstatus': 1,
'dummy': 0
},
{
'word': "hengel",
'wstatus': 1,
'dummy': 0
},
{
'word': "flajoen",
'wstatus': 0,
'dummy': 0
},
{
'word': "aanhekking",
'wstatus': 0,
'dummy': 0
},
{
'word': "kazerne",
'wstatus': 1,
'dummy': 0
},
{
'word': "avonturier",
'wstatus': 1,
'dummy': 0
},
{
'word': "leurig",
'wstatus': 0,
'dummy': 0
},
{
'word': "chagrijnig",
'wstatus': 1,
'dummy': 0
},
{
'word': "bretel",
'wstatus': 1,
'dummy': 0
},
{
'word': "klengel",
'wstatus': 0,
'dummy': 0
},
{
'word': "etaal",
'wstatus': 0,
'dummy': 0
},
{
'word': "matig",
'wstatus': 1,
'dummy': 0
},
{
'word': "futeur",
'wstatus': 0,
'dummy': 0
},
{
'word': "onbekwaam",
'wstatus': 1,
'dummy': 0
},
{
'word': "verguld",
'wstatus': 1,
'dummy': 0
}
]
# EXECUTE
execute()