2009-10-21 73 views
1

文件1:最简单的方法来获取单词列表的字典定义在一个文本文件

hello 
world 

我不知道最好的方法来提取文本文件中的单词列表,找到自己的定义并将它们粘贴到输出文本文件中。我一直在考虑使用WordNet,但不知道如何自动化这个过程。

有没有人有任何想法(也许谷歌/ API/Linux应用程序),可以用来找到单词的定义,然后将其粘贴到文本文件?

文件2:

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" 

回答

1

尽管API或库可能是要走(here的一些Perl的东西)的方式,下面的bash脚本,这是非常粗糙可能给你一些想法:

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 

如果您有一个文件中的单词列表,将一个单词改为一行,将第一个for和最后一个done行的脚本更改为:

while read -r w 
    # . . . 
done < wordlist 
相关问题