Markov: don't add chains if the context is null
that should only be possible on non-pub/privmsgs, or if there is a [subcommand] being analyzed. in any event, don't learn it.
This commit is contained in:
parent
74c03cff88
commit
df3de56c4c
@ -314,24 +314,27 @@ class Markov(Module):
|
||||
|
||||
context = target
|
||||
|
||||
words = line.split()
|
||||
if len(words) <= 0:
|
||||
return line
|
||||
# if there's no context, this is probably a sub-command. don't learn it
|
||||
if context:
|
||||
|
||||
try:
|
||||
db = self.get_db()
|
||||
cur = db.cursor()
|
||||
statement = 'INSERT INTO markov_chain (k1, k2, v, context) VALUES (?, ?, ?, ?)'
|
||||
for word in words:
|
||||
cur.execute(statement, (k1.decode('utf-8', 'replace').lower(), k2.decode('utf-8', 'replace').lower(), word.decode('utf-8', 'replace').lower(), context))
|
||||
k1, k2 = k2, word
|
||||
cur.execute(statement, (k1.decode('utf-8', 'replace').lower(), k2.decode('utf-8', 'replace').lower(), self.stop, context))
|
||||
words = line.split()
|
||||
if len(words) <= 0:
|
||||
return line
|
||||
|
||||
db.commit()
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
try:
|
||||
db = self.get_db()
|
||||
cur = db.cursor()
|
||||
statement = 'INSERT INTO markov_chain (k1, k2, v, context) VALUES (?, ?, ?, ?)'
|
||||
for word in words:
|
||||
cur.execute(statement, (k1.decode('utf-8', 'replace').lower(), k2.decode('utf-8', 'replace').lower(), word.decode('utf-8', 'replace').lower(), context))
|
||||
k1, k2 = k2, word
|
||||
cur.execute(statement, (k1.decode('utf-8', 'replace').lower(), k2.decode('utf-8', 'replace').lower(), self.stop, context))
|
||||
|
||||
db.commit()
|
||||
except sqlite3.Error as e:
|
||||
db.rollback()
|
||||
print("sqlite error: " + str(e))
|
||||
raise
|
||||
|
||||
def _generate_line(self, target, line='', min_size=15, max_size=100):
|
||||
"""Reply to a line, using some text in the line as a point in the chain."""
|
||||
|
Loading…
Reference in New Issue
Block a user