我想知道在文档中计算单词数量的最佳方法。如果我已经设置了自己的“corp.txt”语料库,并且我想知道文件“corp.txt”中“students,trust,ayre”的出现频率,我应该使用什么呢?
以下哪一个方法是正确的:
感谢您,Ray。
以下哪一个方法是正确的:
....
full=nltk.Text(mycorpus.words('FullReport.txt'))
>>> fdist= FreqDist(full)
>>> fdist
<FreqDist with 34133 outcomes>
// HOW WOULD I CALCULATE HOW FREQUENTLY THE WORDS
"students, trust, ayre" occur in full.
感谢您,Ray。
FreqDist
。fdist = FreqDist(); for word in tokenize.whitespace(sent): fdist.inc(word.lower())
。你可以在这里查看文档(http://nltk.googlecode.com/svn/trunk/doc/api/nltk.probability.FreqDist-class.html)。 - aayoubi