diff --git a/dr_botzo/markov/ircplugin.py b/dr_botzo/markov/ircplugin.py index 8bcfb9c..732767f 100644 --- a/dr_botzo/markov/ircplugin.py +++ b/dr_botzo/markov/ircplugin.py @@ -55,12 +55,10 @@ class Markov(Plugin): topics = [x for x in line.split(' ') if len(x) >= 3] return self.bot.reply(event, " ".join(markovlib.generate_line(context, topics=topics, - min_words=min_size, max_words=max_size, - max_sentences=1))) + min_words=min_size, max_words=max_size))) else: return self.bot.reply(event, " ".join(markovlib.generate_line(context, min_words=min_size, - max_words=max_size, - max_sentences=1))) + max_words=max_size))) def handle_chatter(self, connection, event): """Learn from IRC chatter.""" @@ -98,17 +96,13 @@ class Markov(Plugin): topics = [x for x in addressed_re.match(what).group(1).split(' ') if len(x) >= 3] return self.bot.reply(event, "{0:s}: {1:s}" - "".format(nick, " ".join(markovlib.generate_line(context, - topics=topics, - max_sentences=1)))) + "".format(nick, " ".join(markovlib.generate_line(context, topics=topics)))) else: # i wasn't addressed directly, so just respond topics = [x for x in what.split(' ') if len(x) >= 3] return self.bot.reply(event, "{0:s}" - "".format(" ".join(markovlib.generate_line(context, - topics=topics, - max_sentences=1)))) + "".format(" ".join(markovlib.generate_line(context, topics=topics)))) plugin = Markov diff --git a/dr_botzo/markov/lib.py b/dr_botzo/markov/lib.py index 03f9010..9198ef4 100644 --- a/dr_botzo/markov/lib.py +++ b/dr_botzo/markov/lib.py @@ -9,19 +9,15 @@ from markov.models import MarkovContext, MarkovState, MarkovTarget log = logging.getLogger('markov.lib') -def generate_line(context, topics=None, min_words=15, max_words=30, max_sentences=3, max_tries=5): +def generate_line(context, topics=None, min_words=15, max_words=30, sentence_bias=2, max_tries=5): """String multiple sentences together into a coherent sentence.""" tries = 0 - sentences = 0 line = [] - min_words_per_sentence = min_words / max_sentences + min_words_per_sentence = min_words / sentence_bias while tries < max_tries: line += generate_longish_sentence(context, topics=topics, min_words=min_words_per_sentence, max_words=max_words, max_tries=max_tries) - sentences += 1 - if sentences >= max_sentences: - return line if len(line) >= min_words: return line else: