Page 1 of 1

cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 10:18 am
by machinebacon
As the title says - there must be many other ways (sed, awk, perl), I just took the easiest one. It drops the replaced words into a randomized list. Hope it helps foreign language students :)

Code: Select all

#!/bin/bash
usage() {
        echo 'cloze: cloze deletion test generator'
        echo 'usage: cloze count filename'
        echo 'example: cloze 5 /etc/motd'
        exit 1
}

[[ -z $1 ]] && usage
[[ -z $2 ]] && usage
[[ ! -e $2 ]] && echo "file $2 does not exist" && usage
i=0
for word in `cat $2`; do
        ((++i))
        if [[ $i -eq $1 ]]; then
        i=0
        echo "$word  " >> ~/.wordlist
        printf "____ "
        else
        printf "$word "
        fi
done
echo
echo "Word list:"
shuf ~/.wordlist | tr "\\n" " "
echo
rm ~/.wordlist
Example output:

Code: Select all

user@grill:~$ cloze 7 kreuzer 
Travellers left and entered our car ____ every stopping of the train. Three ____ however, remained, bound, like myself, for ____ farthest station: a lady neither young ____ pretty, smoking cigarettes, with a thin ____ a cap on her head, and ____ a semi-masculine outer garment; then her ____ a very loquacious gentleman of about ____ years, with baggage entirely new and ____ in an orderly manner; then a ____ who held himself entirely aloof, short ____ stature, very nervous, of uncertain age, ____ bright eyes, not pronounced in color, ____ extremely attractive,—eyes that darted with rapidity ____ one object to another. This gentleman, ____ almost all the journey thus far, ____ entered into conversation with no fellow-traveller, ____ if he carefully avoided all acquaintance. ____ spoken to, he answered curtly and ____ and began to look out of ____ car window obstinately. 
Word list:
as   face,   with   forty   at   had   wearing   When   companion,   persons,   nor   gentleman   arranged   the   in   during   from   the   decisively,   but 

Re: cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 11:32 am
by rhowaldt
wow, this is wonderful, i can totally use this for future teaching shit! i'm sure Gekko will rejoice, seeing how he's considering a similar career. thanks for posting Jules!

Re: cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 12:43 pm
by GekkoP
Oh yes, very useful for some classroom/home practice. Thanks.

Re: cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 1:02 pm
by dkeg
I immediately thought of the usefulness for GP. Cool!

Re: cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 1:05 pm
by machinebacon
I did think of him too, but thought: ah, he anyway does it with Emacs.

https://github.com/windley/emacs/blob/m ... g-drill.el

Re: cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 1:10 pm
by GekkoP
^ didn't know about that!

Re: cloze - create cloze deletion texts

Posted: Thu Apr 23, 2015 1:18 pm
by wuxmedia
took me ten minutes to work out what was going on there... very cool.