cloze - create cloze deletion texts

Submitted scripts and programs
Forum rules
Your own work only.
machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

cloze - create cloze deletion texts

Unread post by machinebacon » Thu Apr 23, 2015 10:18 am

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 
..gnutella..

User avatar
rhowaldt
Dog
Posts: 4565
Joined: Wed Oct 17, 2012 9:01 am
Contact:

Re: cloze - create cloze deletion texts

Unread post by rhowaldt » Thu Apr 23, 2015 11:32 am

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!
All statements are true in some sense, false in some sense, meaningless in some sense, true and false in some sense, true and meaningless in some sense, false and meaningless in some sense, and true and false and meaningless in some sense.

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: cloze - create cloze deletion texts

Unread post by GekkoP » Thu Apr 23, 2015 12:43 pm

Oh yes, very useful for some classroom/home practice. Thanks.

User avatar
dkeg
Configurator
Posts: 3782
Joined: Sun Nov 18, 2012 9:23 pm
Location: Mid-Atlantic Grill

Re: cloze - create cloze deletion texts

Unread post by dkeg » Thu Apr 23, 2015 1:02 pm

I immediately thought of the usefulness for GP. Cool!

Work hard; Complain less

machinebacon
Baconator
Posts: 10253
Joined: Thu Sep 16, 2010 11:03 am
Location: Pfälzerwald
Contact:

Re: cloze - create cloze deletion texts

Unread post by machinebacon » Thu Apr 23, 2015 1:05 pm

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
..gnutella..

User avatar
GekkoP
Emacs Sancho Panza
Posts: 5877
Joined: Tue Sep 03, 2013 7:05 am

Re: cloze - create cloze deletion texts

Unread post by GekkoP » Thu Apr 23, 2015 1:10 pm

^ didn't know about that!

User avatar
wuxmedia
Grasshopper
Posts: 6445
Joined: Wed Oct 17, 2012 11:32 am
Location: Back in Blighty
Contact:

Re: cloze - create cloze deletion texts

Unread post by wuxmedia » Thu Apr 23, 2015 1:18 pm

took me ten minutes to work out what was going on there... very cool.
"Seek, and Ye shall find"
"Github | Chooons | Site"

Post Reply