文件1:
hello
world
我不知道从文本文件中提取单词列表、找到它们的定义并将它们粘贴到输出文本文件中的最佳方法。我一直在考虑使用 WordNet - 但不知道如何使该过程自动化。
有没有人有任何想法(也许是 google/APIs/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"
最佳答案
虽然 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
关于linux - 获取文本文件中单词列表的字典定义的最简单方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1599116/