我想知道在文档中计算单词的最佳方法。如果我有自己的“corp.txt”语料库设置,我想知道“students,trust,ayre”出现在“corp.txt”文件中的频率。我能用什么?
会不会是下列情况之一:
....
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.
谢谢, 雷
大多数人只使用默认字典(默认值为0)。每次看到一个单词,只需将该值增加一:
我建议你查一下收款柜台。尤其是对于大量的文本,这样做的诀窍,只有有限的可用内存。在一台拥有12Gb内存的电脑上,它一天半的时间就计算出300亿个代币。伪代码(变量字实际上是对文件或类似文件的引用):
完成后,单词会被放入字典my_counter中,然后可以将其写入磁盘或存储在其他地方(例如sqlite)。
你快到了!你可以用你感兴趣的词来索引FreqDist。 请尝试以下操作:
这将为您提供每个单词的出现次数。 你说的“频率”与发生次数不同,可能是这样的:
相关问题 更多 >
编程相关推荐