I'm fairly new to python and NLTK. I'm generating bigrams measured on PMI as per the tutorials here. I want to get the frequency of the generated bigrams in the text. This question here suggests using
finder.ngram_fd.viewitems()
My attempt for the same using collocations:
import string
import codecs
import nltk
from nltk.collocations import *
bigram_measures = nltk.collocations.BigramAssocMeasures()
data = ''
filename = input("Enter file name\n")
with open (filename, "r", encoding="utf8") as myfile:
for line in myfile:
data += line
tokens = nltk.wordpunct_tokenize(data)
finder = BigramCollocationFinder.from_words(tokens)
finder.apply_freq_filter(5)
scored = finder.score_ngrams(bigram_measures.pmi)
a = finder.ngram_fd.viewitems()
The last line gives an error:
AttributeError: 'FreqDist' object has no attribute 'viewitems'
Any idea what should be corrected here or if there's an alternate way to get the frequency when using collocations?