私は次のコードを持っています。私はapply_freq_filter
機能を使用して、頻度カウントよりも小さいコロケーションを除外できることを知っています。しかし、フィルタリングのためにどの周波数を設定するかを決める前に、ドキュメント内のすべてのn-gramタプル(私の場合はバイグラム)の頻度を取得する方法はわかりません。ご覧のとおり、nltkコロケーションクラスを使用しています。Python nltkのn-gram頻度を数えて
import nltk
from nltk.collocations import *
line = ""
open_file = open('a_text_file','r')
for val in open_file:
line += val
tokens = line.split()
bigram_measures = nltk.collocations.BigramAssocMeasures()
finder = BigramCollocationFinder.from_words(tokens)
finder.apply_freq_filter(3)
print finder.nbest(bigram_measures.pmi, 100)
あなたは ')(' finder.ngram_fd.viewitemsを試してみました動作しますか? –
ありがとうございますfinder.ngram_fd.viewitems()作品! – Rkz