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
This commit is contained in:
Brian S. Stephan 2016-06-30 23:26:04 -05:00
parent 9b5e8445bf
commit 8fded6ba6c
2 changed files with 6 additions and 16 deletions

View File

@ -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

View File

@ -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: