我想找出一个语料库的三叉戟,但限制是,至少有两个词的曲线图不是专有名词。到目前为止这是我的密码。
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)其中属性名词是语料库中所有专有名词的列表。
问题是,我的最后一个词过滤,应该确保我没有超过我的限制。有什么想法吗?
发布于 2018-09-30 21:45:15
这应该是你想要的
finder.apply_ngram_filter(lambda w1, w2, w3: sum([w1 n propernouns, w2 in propernouns, w3 in propernouns]) >= 2)https://stackoverflow.com/questions/52580262
复制相似问题