1
我已经编写了一个程序来查找Python中单词的频率。我被困在一个地方,我需要找到bigrams的频率而不考虑词序。这意味着“在...中”应该与“在...中”相同。 代码找到二元频率:Python中没有词序的Bigram频率
txt = open('txt file', 'r')
finder1 = BigramCollocationFinder.from_words(txt.read().split(),window_size = 3)
finder1.apply_freq_filter(3)
bigram_measures = nltk.collocations.BigramAssocMeasures()
for k,v in sorted(list(combinations((set(finder1.ngram_fd.items())),2)),key=lambda t:t[-1], reverse=True)[:10]:
print(k,v)
谢谢你的抬头。我会改变它使用'frozenzet'。我同意OP似乎使用'nltk',但我似乎无法在那里找到无序的bigram功能,所以我提供了一个替代方案。 –