nlp/generate_random.py

17 lines
327 B
Python
Raw Permalink Normal View History

2015-06-07 20:27:59 +00:00
import nltk
import random
TEXT = nltk.corpus.genesis.words('english-kjv.txt')
def main():
bigrams = nltk.bigrams(TEXT)
cfdist = nltk.ConditionalFreqDist(bigrams)
word = random.choice(bigrams)[0]
for i in range(15):
print word,
word = cfdist[word].max()
if __name__ == '__main__':
main()