Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Bash scripts for vocabulary building (with images and pictures)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Gwern Branwen  
View profile  
 More options Feb 6 2011, 11:59 pm
From: Gwern Branwen <gwe...@gmail.com>
Date: Sun, 6 Feb 2011 23:59:32 -0500
Local: Sun, Feb 6 2011 11:59 pm
Subject: Bash scripts for vocabulary building (with images and pictures)
Thought people here might find this interesting; recently, I've been
revising hundreds/thousands of my vocabulary flashcards to include
audio pronunciation and also images (because I've found they help an
awful lot with remembering the card and also, obviously, being able to
pronounce words correctly). I started off doing it by hand but
realized that that was unsustainable in the long-term and I needed to
script various things.

Here's the first function, 'vocab'. You call it like '$ vocab
discursion' to use Wiktionary's current word. It opens up the
definition/pronunciation (if it exists) on Wikitionary, AWAD,
Merriam-Webster, and Forvo. You write the card with definitions,
examples, and so on. Then you use the 'mig' and 'mog' scripts to
handle images and sound files (described later). Vocab's source:

function vocab {
    if (( $# == 2 )) # TODO: figure out how to do this in general someday
    then
        local -r FIRST="$(perl -MURI::Escape -e 'print
uri_escape($ARGV[0]);' $1)"
        local -r SECOND="$(perl -MURI::Escape -e 'print
uri_escape($ARGV[0]);' $2)"
        local -r ESCAPED=`echo $FIRST%20$SECOND`
    else
        local -r ESCAPED="$(perl -MURI::Escape -e 'print
uri_escape($ARGV[0]);' "$@")"
    fi
    firefox "http://en.wiktionary.org/wiki/"$ESCAPED
    firefox "http://www.merriam-webster.com/dictionary/"$ESCAPED
    firefox "http://dictionary.reference.com/browse/"$ESCAPED
    firefox "http://wordsmith.org/awad/search.html?cx=partner-pub-0068747404870456..."$ESCAPED"+-anagrams&sa=Search&siteurl=wordsmith.org%2Fawad%2Fsearch.html#1 453"
    firefox "http://www.forvo.com/search/"$ESCAPED"/"; }

Now you have the card for a word, but no images. Well, you punch the
search term into Google Images, and right-click on 4 of them, say, and
using C-v, download them into ~/. Once they've downloaded, you open a
terminal, and punch in... say, '$ mig discursion', to continue the
example. It spits out '<img src="images/discursion_1.jpg"><img
src="images/discursion_2.jpg"><img src="images/discursion_3.jpg"><img
src="images/discursion_4.jpg">', and you paste that into the card. The
images have already been converted into JPG, shrunk down to 200px, and
moved into ~/.mnemosyne/images/.

Mig's source code:

function mig {
    function migConvert {
        local -r NEW=$BASE"_"$2
        convert $1 -scale 200 ~/.mnemosyne/images/$NEW.jpg && rm $1 &&
echo -n '<img src="images/'$NEW.jpg'"/>'; }

    if (( $# == 0 ));
    then return 1;
    else local -r BASE=$1
        shift
        local ARGS=$@
        if (( $# == 0 )); # if just the basename was supplied, default
to all in ./
        then fmt
            ARGS=`ls *.jpg *.gif *.png *.bmp 2> /dev/null`
        fi
        local -i COUNTER=1
        for FILE in $ARGS;
        do  migConvert $FILE $COUNTER
            COUNTER=$(($COUNTER+1))
        done; echo
    fi; }

Mog is pretty much the same thing. (The names are short for 'mnemosyne
ogg' or 'mnemosyne image'. It made sense to me at the time.) You run
something like '$ mog discursion' and with no other arguments, it
defaults to moving all the WAVs and OGGs and MP3s in the working
directory into OGG files inside ~/.mnemosyne/english/ and printing out
the necessary <sound> tags for you to copy-paste into Mnemosyne. The
source is basically that of mig:

function mog {
    function mogConvert {
        local -r NEW=$BASE"_"$2
        case $1 in
            *.mp3) mpg123 --quiet $1 -w $NEW && oggenc --quiet $NEW -o
~/.mnemosyne/english/$NEW.ogg && rm $1 $NEW;;
            *.ogg) mv $1 ~/.mnemosyne/english/$NEW.ogg;;
            *)     (oggenc --quiet $1 -o ~/.mnemosyne/english/$NEW.ogg
&>/dev/null) && rm $1;;
        esac
        echo -n '<sound src="english/'$NEW.ogg'"/>'; }

    if (( $# == 0 ));
    then return 1;
    else local -r BASE=$1
        shift
        local -i COUNTER=1
        local ARGS=$@
        if (( $# == 0 )); # if just the basename was supplied, default
to all in ./
        then fmt
            ARGS=`ls *.ogg *.mp3 2> /dev/null`
            ARGS=$ARGS" "`file *|grep RIFF|cut -d ':' -f 1`
        fi
        echo -n " "
        for FILE in $ARGS;
        do  mogConvert $FILE $COUNTER
            COUNTER=$(($COUNTER+1))
        done; echo
    fi; }

Obviously, these scripts may not work for your exact needs, and
require a number of libraries/apps installed, like a Perl library in
'vocab' (or Firefox), or the ogg tools or ImageMagick. But they may be
useful as examples, and certainly have saved me an awful lot of time
already. I regret not writing them long ago.

--
gwern
http://www.gwern.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »