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"
|
name = "Maki"
|
||||||
|
|
||||||
# bot version
|
# bot version
|
||||||
version = "v0.10.8"
|
version = "v0.10.9"
|
||||||
|
|
||||||
# text shown by .help command
|
# text shown by .help command
|
||||||
helptext = """I am a bot written in Python by MrDetonia
|
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()
|
words = data.split()
|
||||||
return words
|
return words
|
||||||
|
|
||||||
def triples(self):
|
def doubles(self):
|
||||||
if len(self.words) < 3:
|
if len(self.words) < 2:
|
||||||
return
|
return
|
||||||
|
|
||||||
for i in range(len(self.words) - 2):
|
for i in range(len(self.words) - 1):
|
||||||
yield (self.words[i], self.words[i+1], self.words[i+2])
|
yield (self.words[i], self.words[i+1])
|
||||||
|
|
||||||
def database(self):
|
def database(self):
|
||||||
for w1, w2, w3 in self.triples():
|
for w1, w2 in self.doubles():
|
||||||
key = (w1, w2)
|
key = w1
|
||||||
if key in self.cache:
|
if key in self.cache:
|
||||||
self.cache[key].append(w3)
|
self.cache[key].append(w2)
|
||||||
else:
|
else:
|
||||||
self.cache[key] = [w3]
|
self.cache[key] = [w2]
|
||||||
|
|
||||||
def generate_text(self, size=25):
|
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]
|
seed_word, next_word = self.words[seed], self.words[seed+1]
|
||||||
w1, w2 = seed_word, next_word
|
w1, w2 = seed_word, next_word
|
||||||
gen_words = []
|
gen_words = []
|
||||||
for i in range(size):
|
for i in range(size):
|
||||||
gen_words.append(w1)
|
gen_words.append(w1)
|
||||||
try:
|
try:
|
||||||
w1, w2 = w2, random.choice(self.cache[(w1, w2)])
|
w1, w2 = w2, random.choice(self.cache[w2])
|
||||||
except KeyError:
|
except KeyError:
|
||||||
break
|
break
|
||||||
gen_words.append(w2)
|
gen_words.append(w2)
|
||||||
|
Loading…
Reference in New Issue
Block a user