12 lines
323 B
Python
12 lines
323 B
Python
|
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]
|