File1中:
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"
答案 0 :(得分:1)
虽然API或库可能是可行的方法(here是一些Perl的东西),但下面的Bash脚本非常粗略可能会给你一些想法:< / p>
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
答案 1 :(得分:0)
有关多种解决方案,请参阅Dictionary API or Library。