我想找出一个语料库的三元结构,但有一个限制,即至少有两个三元结构的单词不是专有名词。这是我目前的代码。
def collocation_finder(text,window_size):
ign = stopwords.words('english')
#Clean the text
finder = TrigramCollocationFinder.from_words(text, window_size)
finder.apply_freq_filter(2)
finder.apply_word_filter(lambda w: len(w) < 2 or w.lower() in ign)
finder.apply_word_filter(lambda w: next(iter(w)) in propernouns)
trig_mes = TrigramAssocMeasures()
#Get trigrams based on raw frequency
collocs = finder.nbest(trig_mes.raw_freq,10)
scores = finder.score_ngrams( trig_mes.raw_freq)
return(collocs)
其中propernouns是语料库中所有专有名词的列表。
问题是,我的最后一个字过滤的一个,应该是确保我不超过我的限制。有什么想法吗?