From 2917ea96260b84b255652bb30f372ec9337ebcc6 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Sat, 3 May 2014 20:56:33 -0500 Subject: [PATCH] Markov: indicate # sentences we want in a line before we were just adding words until we hit the min/max, now let's also count the number of sentences and have a cutoff there, if we don't want the whole appending thing no matter what --- markov/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/markov/views.py b/markov/views.py index a5a5690..7a45f43 100644 --- a/markov/views.py +++ b/markov/views.py @@ -148,13 +148,17 @@ def _generate_longish_sentence(context, topics=None, min_words=4, max_words=30): return _generate_sentence(context) -def _generate_line(context, topics=None, min_words=15, max_words=30): +def _generate_line(context, topics=None, min_words=15, max_words=30, max_sentences=3): """String multiple sentences together into a coherent sentence.""" tries = 0 + sentences = 0 line = [] while tries < 5: line += _generate_longish_sentence(context, topics=topics, max_words=max_words) + sentences += 1 + if sentences >= max_sentences: + return line if len(line) >= min_words: return line else: