nlp/code_random_text.py

12 lines
323 B
Python
Raw Normal View History

2015-06-07 20:27:59 +00:00
import nltk
# Natural Language Toolkit: code_random_text
def generate_model(cfdist, word, num=15):
for i in range(num):
print word,
word = cfdist[word].max()
text = nltk.corpus.genesis.words('english-kjv.txt')
bigrams = nltk.bigrams(text)
cfd = nltk.ConditionalFreqDist(bigrams) # [_bigram-condition]