mirror of
https://github.com/MrDetonia/Maki.git
synced 2024-11-10 23:53:29 -05:00
Decreased markov chain interval to 2, v0.10.9
This commit is contained in:
parent
34c85d833e
commit
3d49ca9775
2
bot.py
2
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
|
||||
|
20
markov.py
20
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)
|
||||
|
Loading…
Reference in New Issue
Block a user