0
我有一个包含大量评论/句子的文本文件,我想以某种方式找到文档中重复出现的最常见短语。我试图与它摆弄了一下与NLTK,我发现这个线程:How to extract common/significant phrases from a series of text entries如何从文本文档中找到常用短语
然而,尝试之后,我得到奇怪的结果像这样:
>>> finder.apply_freq_filter(3)
>>> finder.nbest(bigram_measures.pmi, 10)
[('m', 'e'), ('t', 's')]
而在另一个文件,其中那句“这是有趣“是非常普遍的,我得到一个空的列表[]。
我应该怎么做呢?
这里是我的全码:
import nltk
from nltk.collocations import *
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
# change this to read in your data
finder = BigramCollocationFinder.from_words('MkXVM6ad9nI.txt')
# only bigrams that appear 3+ times
finder.apply_freq_filter(3)
# return the 10 n-grams with the highest PMI
print finder.nbest(bigram_measures.pmi, 10)
谢谢!这是我的问题。 –