From 3d49ca9775358eb89f1365c8356cd75699eee50f Mon Sep 17 00:00:00 2001 From: Zac Herd Date: Wed, 6 Apr 2016 19:44:28 +0100 Subject: [PATCH] Decreased markov chain interval to 2, v0.10.9 --- bot.py | 2 +- markov.py | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/bot.py b/bot.py index dcfe5be..8b90879 100644 --- a/bot.py +++ b/bot.py @@ -25,7 +25,7 @@ from secret import email,pwd name = "Maki" # bot version -version = "v0.10.8" +version = "v0.10.9" # text shown by .help command helptext = """I am a bot written in Python by MrDetonia diff --git a/markov.py b/markov.py index f04face..e75491c 100644 --- a/markov.py +++ b/markov.py @@ -15,30 +15,30 @@ class Markov(object): words = data.split() return words - def triples(self): - if len(self.words) < 3: + def doubles(self): + if len(self.words) < 2: return - for i in range(len(self.words) - 2): - yield (self.words[i], self.words[i+1], self.words[i+2]) + for i in range(len(self.words) - 1): + yield (self.words[i], self.words[i+1]) def database(self): - for w1, w2, w3 in self.triples(): - key = (w1, w2) + for w1, w2 in self.doubles(): + key = w1 if key in self.cache: - self.cache[key].append(w3) + self.cache[key].append(w2) else: - self.cache[key] = [w3] + self.cache[key] = [w2] def generate_text(self, size=25): - seed = random.randint(0, self.word_size - 3) + seed = random.randint(0, self.word_size - 2) seed_word, next_word = self.words[seed], self.words[seed+1] w1, w2 = seed_word, next_word gen_words = [] for i in range(size): gen_words.append(w1) try: - w1, w2 = w2, random.choice(self.cache[(w1, w2)]) + w1, w2 = w2, random.choice(self.cache[w2]) except KeyError: break gen_words.append(w2)