我有一个标有“all.txt”的文本文件它包含一个普通的英文段落
出于某种原因,当我运行此代码时:
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(('all.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)
我得到以下结果:
[('.', 't'), ('a', 'l'), ('l', '.'), ('t', 'x'), ('x', 't')]
我做错了什么,因为我只收到信件?我要找的是单词而不是字母!
这是“all.txt”中内容的一个示例,因此您可以了解正在处理的内容:“反对这个计划的不仅仅是民主党人。全国各地的美国人都表示反对这个计划。我的民主同事和我有一个更好的计划,将加强道德规则,以改善国会问责制并确保适当考虑立法。共和党计划未能填补允许在议员阅读之前考虑立法的漏洞。