【发布时间】:2019-05-19 06:24:42
【问题描述】:
我知道可以从以下链接的示例中找到具有特定单词的二元组:
finder = BigramCollocationFinder.from_words(text.split())
word_filter = lambda w1, w2: "man" not in (w1, w2)
finder.apply_ngram_filter(word_filter)
bigram_measures = nltk.collocations.BigramAssocMeasures()
raw_freq_ranking = finder.nbest(bigram_measures.raw_freq, 10) #top-10
>>>
nltk: how to get bigrams containing a specific word
但如果我需要包含预定义的两个单词的二元组,我不确定如何应用它。
例子:
我的句子:"hello, yesterday I have seen a man walking. On the other side there was another man yelling: "who are you, man?"
给定一个列表:["yesterday", "other", "I", "side"]
如何获得给定单词的二元组列表。 IE:
[("yesterday", "I"), ("other", "side")]?
【问题讨论】: