markov: don't append punctuation to nothingness

this is an attempt to fix bss/dr.botzo#10
This commit is contained in:
Brian S. Stephan 2016-12-04 10:50:02 -06:00
parent 6e21416791
commit ed66246f14
1 changed files with 3 additions and 2 deletions

View File

@ -21,8 +21,9 @@ def generate_line(context, topics=None, min_words=15, max_words=30, sentence_bia
if len(line) >= min_words:
return line
else:
if line[-1][-1] not in [',', '.', '!', '?', ':']:
line[-1] += random.choice(['?', '.', '!'])
if len(line) > 0:
if line[-1][-1] not in [',', '.', '!', '?', ':']:
line[-1] += random.choice(['?', '.', '!'])
tries += 1