两种方式
import nltk
words = 'Lorem ipsum dolor sit amet'# 自定义输入,可以随机输入一些字符串,但是结果可能就是不太好
tokens = nltk.word_tokenize(words)
text = nltk.Text(tokens)
print(text.generate())
result
amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet ipsum dolor
sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem
ipsum dolor sit amet Lorem ipsum dolor sit amet sit amet amet sit amet
sit amet amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet sit amet Lorem ipsum dolor sit amet Lorem
ipsum dolor sit amet Lorem ipsum dolor sit amet dolor sit amet dolor
sit amet sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit
amet ipsum dolor sit amet Lorem ipsum dolor
amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet ipsum dolor
sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet Lorem
ipsum dolor sit amet Lorem ipsum dolor sit amet sit amet amet sit amet
sit amet amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit amet
Lorem ipsum dolor sit amet sit amet Lorem ipsum dolor sit amet Lorem
ipsum dolor sit amet Lorem ipsum dolor sit amet dolor sit amet dolor
sit amet sit amet Lorem ipsum dolor sit amet Lorem ipsum dolor sit
amet ipsum dolor sit amet Lorem ipsum dolor
from random_words import RandomWords
from random_words import LoremIpsum
# 产生单词
rw = RandomWords()
words = rw.random_words(count=10)
print(words)
# 产生句子
li = LoremIpsum()
print(li.get_sentence())
print(li.get_sentences(5))
print(li.get_sentences_list(5))
[‘groom’, ‘brushes’, ‘suggestion’, ‘river’, ‘leadership’, ‘seas’, ‘soles’, ‘carriers’, ‘arts’, ‘taste’]
Sanctus enim mazim nequeetiam, enimnulla sit dis.
Conubia nostrud. Quis quisaenean elit augue liberoduis facer variuscras, at ac felissed massaphasellus lacusut libero esse. Condimentum diaminteger tellus. Kasd lacus. Aaenean diaminteger in leopraesent, nondonec posuere erat justocras soluta.
[‘Mattis quisque, dolores nonumy diaminteger veniam vel.’, ‘Porta natoque vero pulvinar ullamcorper facilisi, interdum aaenean nostrud sedfusce aenean montes consequatduis.’, ‘Consequatduis ea.’, ‘Lacus tincidunt nam libero.’, ‘Pretium urnapraesent facilisisat.’]