我看到多個問題和答案,說NLTK搭配不能超越雙克和三克。nltk quadgram搭配發現者
例如,這一個 - How to get n-gram collocations and association in python nltk?
我看到有一個叫
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))
更新您的NLTK'PIP安裝-U nltk',你應該可以通過'from nltk.metrics.association import QuadgramAssocMeasures'獲得QuadgramAssocMeasures https://github.com/nltk/nltk/blob/develop/nltk/metrics/association.py#L2 98 – alvas
非常感謝陛下!這現在起作用。假設我已經擁有它,沒必要做pip安裝。爲什麼大家都在說,超越卦不起作用? NLTK更新了Quadgrams,因爲在stackoverflow上的其他問題也許現在NLTK也有Quadgrams? – Kumar
父親對我來說有點太過分了,叫我alvas'會做; P。是的,NLTK在過去的2-3年裏得到了巨大的改進。 'QuadgramCollocationFinder'和'QuadgramAssocMeasures'有點新鮮。但來自http://stackoverflow.com/questions/18672082/how-to-get-n-gram-collocations-and-association-in-python-nltk的其他答案是試圖說,是沒有簡單解決方案來實現一個通用的NgramCollocationFinder,'from_words(cls,words)'函數的公式對於ngram的每個順序都是不同的。 – alvas