[open] Random Sentences followed by paired Question
Hi, I am doing a reading study where the participants read sentences (random order) and answer paired comprehension questions. I have currently extracted a list looking like this from a .csv file with all the sentences, questions, item number and answer.
import csv
image_path = exp.get_file('Sentences.csv')
with open(image_path, 'rU') as csvfile:
reader = csv.DictReader(csvfile, delimiter=',')
full_list = list(reader)
for row in full_list:
print row
{'Answer': 'y', 'Question': 'Was the roommate preparing himself?', 'Sentence Number': '6', 'Sentences': 'After the roommate prepared Kevin rapped his wine glass with his knife.'}
{'Answer': 'n', 'Question': 'Was Alec rushed?', 'Sentence Number': '7', 'Sentences': 'While Dale rushed Alec inspected some shirts at the department store.'}
{'Answer': 'n', 'Question': 'Was Kari raced?', 'Sentence Number': '8', 'Sentences': 'While the woman raced Kari strode ahead in the last lap around the track.'}
{'Answer': 'y', 'Question': 'Was the toy box messy?', 'Sentence Number': '9', 'Sentences': 'It was very hard to find the lorry inside of the messy toy box.'}
{'Answer': 'y', 'Question': 'Was Joel selling a dining set?', 'Sentence Number': '10', 'Sentences': 'Joel included a table in the dining set he was selling.'}
How to I go about looping over this list and presenting the sentences in random order, but maintaining the bond with the paired question and answer?
Comments
Hi,
The easiest thing will be to just put the questions on the same line as your sentences in the csv file. So one sentence may look like this: "While Dale rushed Alex inspected some shirts..Was Alex rushed?". These sentences can then be put in a list with the file.readlines() command (or in your case a dictionary). With the random.shuffle(full_list) command you randomize the order of appearance.
Now, to present the sentence, we first have to cut it in half. Note that ".." separated the sentence from the followup question, so:
Hope this helps.
Cheers,
Josh
Hi,
(Just before I wanted to send this response, I saw that Josh already answered. But anyway, I don't want to have typed this for nothing, so I'll post it as well, and you can choose whichever solution you prefer)
First you randomize the list:
Then, you have to create some sort of
loop
that repeats whatever should be happening during a trial. For this matter, I recommend using aloop
-sequence
structure (see the opensesame documentation, if you don't know what this means).In the
sequence
, you have to have aninline_script
, in which you pick the information that you are going to use on that specific trial. For example, by doing this:This will always take the first entry of your dictionary. Since you shuffled earlier, you don't need to worry about randomization any more. The following steps depend a lot on what exactly it is that you want to present. But as you have all relevant information in your dictionary trial_info, you should have everything that you need to make it work.
Good luck,
Eduard