【问题标题】:Sort words by their usage按用法对单词进行排序
【发布时间】:2011-12-07 12:46:16
【问题描述】:

我有一个英语单词列表(大约 10000 个),我想按照它们在文学、报纸、博客等中出现的用法对它们进行排序。我可以用 Python 或其他语言对它们进行排序吗?我听说过NLTK,这是我所知道的最近的可以提供帮助的图书馆。还是其他工具的任务?

谢谢

【问题讨论】:

    标签: python nltk


    【解决方案1】:

    您可以使用collections.Counter。代码就这么简单:

    l = get_iterable_or_list_of_words() # That is up to you
    c = collections.Counter(l)
    print(c.most_common())
    

    【讨论】:

    • 我正在寻找一些库,它会在一些可下载或在线的数据库中查找单词,并具有使用情况的统计信息(因为我没有统计信息)。跨度>
    【解决方案2】:

    我对自然语言处理知之甚少,但我认为 Python 是一种理想的语言,供您使用。

    在 Google 搜索中找到“Python 自然语言”:

    http://www.nltk.org/

    搜索 StackOverflow 找到了这个答案:

    Python or Java for text processing (text mining, information retrieval, natural language processing)

    这又与模式相关联:

    http://www.clips.ua.ac.be/pages/pattern

    您可能想看看 Pattern,这似乎很有希望。

    祝你好运,玩得开心!

    【讨论】:

    • 这些工具很有用,但它们能满足我的要求吗?
    【解决方案3】:

    Python 和 NLTK 是对单词表进行排序的完美工具,因为 NLTK 带有一些英语语料库,您可以从中提取频率信息。

    以下代码将按照棕色语料库中的词频顺序打印给定的wordlist

    import nltk
    from nltk.corpus import brown
    
    wordlist = ["corpus","house","the","Peter","asdf"]
    # collect frequency information from brown corpus, might take a few seconds
    freqs = nltk.FreqDist([w.lower() for w in brown.words()])
    # sort wordlist by word frequency
    wordlist_sorted = sorted(wordlist, key=lambda x: freqs[x.lower()], reverse=True)
    # print the sorted list
    for w in wordlist_sorted:
        print w
    

    输出:

    >>> 
    the
    house
    Peter
    corpus
    asdf
    

    如果您想使用不同的语料库或获取更多信息,您应该查看chapter 2 of the nltk book

    【讨论】:

    • 谢谢,这正是我想要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-12
    • 1970-01-01
    • 1970-01-01
    • 2016-02-08
    相关资源
    最近更新 更多