Determination of word rate and NLTK

I have a file with different words that I want to count the frequency of each word in a document and plot it. However, my plot is showing no results. x-axis

should contain words and y-axis

frequency. I am using NLTK

, NumPy

andMatplotlib

Here is my code, maybe I did something wrong

def graph():
    f = open("file.txt", "r")
    inputfile = f.read()
    words = nltk.tokenize.word_tokenize(inputfile)
    count = set(words)
    dic = nltk.FreqDist(words)
    FreqDist(f).plot(50, cumulative=False)
    f.close()

      

Thanks in advance for your help

+5


source to share


1 answer


def graph():
  f = open("file.txt", "r")
  inputfile = f.read()
  tokens = nltk.tokenize.word_tokenize(inputfile)
  fd = nltk.FreqDist(tokens)
  fd.plot(30,cumulative=False)

      



You can play with the graph by changing the parameters on the graph ()

+6


source







All Articles