我有一個英文單詞列表(大約10000),我想根據它們在文學,報紙,博客等中的使用情況對它們進行排序。我可以使用Python還是其他語言?我聽說NLTK
這是我認識的可以幫助的最接近的圖書館。或者這是其他工具的任務嗎?按照其用法排序詞
謝謝
我有一個英文單詞列表(大約10000),我想根據它們在文學,報紙,博客等中的使用情況對它們進行排序。我可以使用Python還是其他語言?我聽說NLTK
這是我認識的可以幫助的最接近的圖書館。或者這是其他工具的任務嗎?按照其用法排序詞
謝謝
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。
您可以使用collections.Counter
。該代碼是那麼容易,因爲:
l = get_iterable_or_list_of_words() # That is up to you
c = collections.Counter(l)
print(c.most_common())
我正在尋找一些庫,它將查找可供下載或在線使用的某些數據庫中的單詞,並具有統計用法(因爲我沒有統計信息)。 – xralf
我不知道很多關於自然語言處理,但我認爲Python是供您使用爲目的的理想語言。
一個谷歌搜索 「Python的自然語言」 發現:
一個搜索StackOverflow上發現這樣的回答:
Python or Java for text processing (text mining, information retrieval, natural language processing)
這又與圖案:
http://www.clips.ua.ac.be/pages/pattern
您可能想看看Pattern,看起來很有希望。
祝你好運,玩得開心!
這些工具很有用,但它們是按照我的要求做的嗎? – xralf
謝謝你,這正是我所尋找的。 – xralf