NLTK コロケーションは 2 グラムと 3 グラムを超えて実行できないという質問と回答が複数見られます。
この例 - Python nltkでnグラムのコロケーションと関連付けを取得する方法は?
と呼ばれるものがあることがわかりました
nltk.QuadgramCollocationFinder
に似ている
nltk.BigramCollocationFinder および nltk.TrigramCollocationFinder
しかし同時に、次のようなものを見ることはできません
nltk.collocations.QuadgramAssocMeasures()
nltk.collocations.BigramAssocMeasures() および nltk.collocations.TrigramAssocMeasures() と同様
nltk.QuadgramCollocationFinder の目的は、bi および tri グラムを超える n-gram を (ハックなしで) 見つけることができない場合です。
多分私は何かが欠けています。
ありがとう、
コードを追加し、Alvas からの入力に従って質問を更新すると、これが機能するようになりました
import nltk
from nltk.collocations import *
from nltk.corpus import PlaintextCorpusReader
from nltk.metrics.association import QuadgramAssocMeasures
bigram_measures = nltk.collocations.BigramAssocMeasures()
trigram_measures = nltk.collocations.TrigramAssocMeasures()
quadgram_measures = QuadgramAssocMeasures()
the_filter = lambda *w: 'crazy' not in w
finder = BigramCollocationFinder.from_words(corpus)
finder.apply_freq_filter(3)
finder.apply_ngram_filter(the_filter)
print (finder.nbest(bigram_measures.likelihood_ratio, 10))
finder = QuadgramCollocationFinder.from_words(corpus)
finder.apply_freq_filter(3)
finder.apply_ngram_filter(the_filter)
print(finder.nbest(quadgram_measures.likelihood_ratio,10))