views:

212

answers:

2

File1:

hello
world

I don't know the best method to extract a list of words from a text file, find their definitions and paste them into an output textfile. I've been thinking of using WordNet - but don't know how to automate the process.

Does anyone have any ideas (perhaps google/APIs/linux applications) that one could use to find the definitions of words with, and then paste them into a text file?

File2:

an expression of greeting; "every morning they exchanged polite hellos" 
universe: everything that exists anywhere; "they study the evolution of the universe"; "the biggest tree in existence"
A: 

See Dictionary API or Library for several solutions.

Rob Napier
+1  A: 

Although an API or library is probably the way to go (here's some Perl stuff), the Bash script below, which is very rough might give you some ideas:

saveIFS="$IFS"
for w in hello goodbye bicycle world
do
    echo
    echo "------- $w -------"
    def=$(wn $w -over)
    IFS=$'\n'
    for line in $def
    do
        echo -e "\t${line}"
        IFS="$saveIFS"
        if [[ $line =~ ^[[:digit:]]*\. ]]
        then 
            for word in $line
            do
                echo -e "\t\t${word%*[,;]}"
            done
        fi
    done
    IFS="$saveIFS"
done

If you have a list of words in a file, one word to a line, change the first for and last done lines of the script above to:

while read -r w
    # . . .
done < wordlist
Dennis Williamson