【发布时间】:2019-12-19 21:12:43
【问题描述】:
我一直在尝试从文件中返回唯一单词列表,并使用 NLTK 按字母顺序对它们进行排序,但尽管我使用了几种不同的方法,但它不起作用。这是我的代码:
import nltk
from nltk import FreqDist
def get_vocabulary(self):
with open(self.path, "r") as file:
split = [line.split('\n') for line in file]
fdist1 = FreqDist(split)
unique_words = fdist1.hapaxes()
return sorted(set(unique_words))
还有错误:
TypeError: unhashable type: 'list'
我尝试过的其他类似方法也引发了类似的错误。该解决方案不必包含 nltk,但如果您能告诉我我在自己的解决方案中犯了哪些错误,我将不胜感激。
【问题讨论】:
标签: list nltk word-frequency