title: Generating Ngrams (Unigrams,Bigrams etc) from a large corpus of .txt files and their Frequency
body: <p>I need to write a program in NLTK that breaks a corpus (a large collection of txt files) into unigrams, bigrams, trigrams, fourgrams and fivegrams. I have already written code to input my files into the program.</p>
  
  <p>The input is 300 .txt files written in English and I want the output in form of Ngrams and specially the frequency count. </p>
  
  <p>I know that NLTK has Bigram and Trigram modules : <a href="http://www.nltk.org/_modules/nltk/model/ngram.html" rel="noreferrer">http://www.nltk.org/_modules/nltk/model/ngram.html</a> </p>
  
  <p>but I am not that advanced to enter them into my program. </p>
  
  <p>input: txt files NOT single sentences</p>
  
  <p>output example:</p>
  
  <pre><code>Bigram [('Hi', 'How'), ('How', 'are'), ('are', 'you'), ('you', '?'), ('?', 'i'), ('i', 'am'), ('am', 'fine'), ('fine', 'and'), ('and', 'you')] 
  
  Trigram: [('Hi', 'How', 'are'), ('How', 'are', 'you'), ('are', 'you', '?'), ('you', '?', 'i'), ('?', 'i', 'am'), ('i', 'am', 'fine'), ('am', 'fine', 'and'), ('fine', 'and', 'you')]
  </code></pre>
  
  <p>My code up to now is: </p>
  
  <pre><code>from nltk.corpus import PlaintextCorpusReader
  corpus = 'C:/Users/jack3/My folder'
  files = PlaintextCorpusReader(corpus, '.*')
  ngrams=2
  
  def generate(file, ngrams):
      for gram in range(0, ngrams):
      print((file[0:-4]+"_"+str(ngrams)+"_grams.txt").replace("/","_"))
  
  
  for file in files.fileids():
  generate(file, ngrams)
  </code></pre>
  
  <p>Any help what should be done next? </p>