我很困惑如何在一个文件中找到频繁的词对。我首先得到了双元组,但是如何从这里继续呢?我尝试在应用之前使用regexp删除标点符号nltk.bigrams公司在
raw=open("proj.txt","r").read()
tokens=nltk.word_tokenize(raw)
pairs=nltk.bigrams(tokens)
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
finder = BigramCollocationFinder.from_words(pairs)
finder.apply_freq_filter(3)
finder.nbest(bigram_measures.pmi, 10)
听起来你只需要单词对的列表。如果是这样的话,我想你的意思是使用
finder.score_ngrams
这样: 在还可以使用其他评分标准。听起来你只需要频率,但是其他通用ngram的评分指标在这里-http://nltk.googlecode.com/svn-/trunk/doc/api/nltk.metrics.association.NgramAssocMeasures-class.html
您似乎没有导入就调用了
BigramCollocationFinder
。正确的路径是nltk.collocations.BigramCollocationFinder
。所以你可以试试这个(确保你的文本文件有文本!)公司名称:相关问题 更多 >
编程相关推荐