def generate_unigram_sentences(unigram_model, number): for i in range(number): sentence = "" word = None while word not in END_SENTENCE_PUNCT: word = weighted_random_pick(unigram_model) sentence, word = add_word_to_sentence(sentence, word) try: print sentence except: print "Could not print sentence due to an unrecognized character." print "\n"
def word_from_bigram_model_and_previous_word(bigram, word): word = weighted_random_pick(bigram[word]) return word
def word_from_trigram_model_and_previous_word(trigram, one, two): word = weighted_random_pick(trigram[one][two]) return word