テキスト ファイル内の単語リストの辞書定義を取得する最も簡単な方法
-
22-09-2019 - |
質問
ファイル1:
hello
world
テキスト ファイルから単語のリストを抽出し、その定義を見つけて出力テキスト ファイルに貼り付ける最適な方法がわかりません。WordNet の使用を考えていますが、プロセスを自動化する方法がわかりません。
単語の定義を見つけてテキスト ファイルに貼り付けるために使用できるアイデア (おそらく Google/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"
解決
おそらく API またはライブラリが最適な方法ですが (ここは 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
ファイル内に単語のリストがあり、1 行に 1 つの単語が含まれている場合は、最初の単語を変更します。 for
そして最後 done
上記のスクリプトの行を次のように変更します。
while read -r w
# . . .
done < wordlist
所属していません StackOverflow