title: NLTK text.generate(). Doing this with different ngram models
body: <p>I have to generate random sentences using nltk. However, it seems like text.generate() only gives us sentences with trigrams. Is there any way I can expand this to include unigrams as well as bigrams?</p>
  
  <p>My current code is:</p>
  
  <pre><code>exclude = set(string.punctuation)
  ln = ''.join(ch for ch in ln if ch not in exclude)
  
  
  words = nltk.word_tokenize(ln)
  my_bigrams = nltk.bigrams(words)
  my_trigrams = nltk.trigrams(words)
  
  
  tText = Text(words)
  tText1 = Text(my_bigrams)
  tText2 = Text(my_trigrams)
  print tText.generate()
  print tText1.generate()
  print tText2.generate()
  </code></pre>
  
  <p>Change in generate() function:</p>
  
  <pre><code>def generate(self, length=100, c=3):
      """
      Print random text, generated using a trigram language model.
  
      :param length: The length of text to generate (default=100)
      :type length: int
      :seealso: NgramModel
      """
      if '_trigram_model' not in self.__dict__:
          print "Building ngram index..."
          estimator = lambda fdist, bins: LidstoneProbDist(fdist, 0.2)
          self._trigram_model = NgramModel(c, self, estimator=estimator)
      text = self._trigram_model.generate(length)
      print tokenwrap(text)
  </code></pre>