From 8fded6ba6c2898a7578a14e9ec7b03cfc16cde27 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Thu, 30 Jun 2016 23:26:04 -0500 Subject: [PATCH] markov: replace max_sentences with sentance_bias the theory here is that counting the number of sentences generated is kind of silly, if we're already specifying min/max word counts, we probably just want to fall into that range, and not really care how many sentences we get meanwhile, we were overloading max_sentences to also calculate how long any one sentence must be, which is kind of a weird thing to derive, so we're going to drop the max_sentences language and call this more what it is, a bias towards the number of sentences that might be seen --- dr_botzo/markov/ircplugin.py | 14 ++++---------- dr_botzo/markov/lib.py | 8 ++------ 2 files changed, 6 insertions(+), 16 deletions(-) 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: