- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
while True:
prev_word = next_word
if next_word.is_empty():
next_word = random.choice(words)
else:
next_word = chain.get_next_word(next_word.root, lambda: Text.Word(''))
suffix = suffix_chain.get_next_word((prev_word.suffix, next_word.root), lambda: '')
if len(suffix) == 0:
suffix = next_word.suffix
punct = punct_chain.get_next_word(next_word.root, lambda: '')
if len(output_words) == 0 or output_words[-1].is_ending_word():
res_word = Text.PunctedWord(next_word.root.capitalize(), suffix, punct)
else:
res_word = Text.PunctedWord(next_word.root, suffix, punct)
output_words += [res_word]
generated_chars += len(res_word)
if chars_max_count > 0 and generated_chars > chars_max_count:
break
if words_max_count > 0 and len(output_words) > words_max_count:
break