【问题标题】:Simplest method to get the dictionary definitions of a list of words in a text file获取文本文件中单词列表的字典定义的最简单方法
【发布时间】:2009-10-21 06:50:42
【问题描述】:

文件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"

【问题讨论】:

    标签: linux unix dictionary awk cat


    【解决方案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
    

    【讨论】:

      【解决方案2】:

      请参阅Dictionary API or Library 了解多种解决方案。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-17
        • 2011-06-08
        • 1970-01-01
        • 1970-01-01
        • 2012-12-06
        • 1970-01-01
        • 1970-01-01
        • 2023-03-26
        相关资源
        最近更新 更多