Okay, you want to filter both consulting the frequencies AND a word list. So, create a function that construct a filter that consults the scored dictionary and a defined list of words, like this:
def create_filter_minfreq_inwords(scored, words, minfreq):
def bigram_filter(w1, w2):
return (w1 not in words and w2 not in words) and (
(w1, w2) in scored and scored[w1, w2] <= minfreq)
return bigram_filter
Then, you need to create a dictionary with the frequencies first using finder.score_ngrams with BigramAssocMeasures.raw_freq, and use the above function to create the bigram filter. Here is an example, step by step:
import nltk
# create some text and tokenize it
text = "This is a text. Written for test purposes, this is a text."
tokens = nltk.wordpunct_tokenize(text)
# initialize finder object with the tokens
finder = nltk.collocations.BigramCollocationFinder.from_words(tokens)
# build a dictionary with bigrams and their frequencies
bigram_measures = nltk.collocations.BigramAssocMeasures()
scored = dict(finder.score_ngrams(bigram_measures.raw_freq))
# build a word list
words = ['test', 'This']
# create the filter...
myfilter = create_filter_minfreq_inwords(scored, words, 0.1)
print 'Before filter:\n', list(finder.score_ngrams(bigram_measures.raw_freq))
# apply filter
finder.apply_ngram_filter(myfilter)
print '\nAfter filter:\n', list(finder.score_ngrams(bigram_measures.raw_freq))