Markov: unicode fixes and improvements
This commit is contained in:
parent
8f5b6d96c2
commit
2b0b7abd58
@ -406,7 +406,7 @@ class Markov(Module):
|
||||
if gen_words[-1] == self.stop:
|
||||
gen_words = gen_words[:-1]
|
||||
|
||||
return ' '.join(gen_words).encode('utf-8', 'ignore')
|
||||
return ' '.join(gen_words)
|
||||
|
||||
def _retrieve_chains_for_key(self, k1, k2, context_id):
|
||||
"""Get the value(s) for a given key (a pair of strings)."""
|
||||
@ -425,11 +425,13 @@ class Markov(Module):
|
||||
else:
|
||||
query = ('SELECT v FROM markov_chain WHERE k1 = ? AND k2 = ? AND '
|
||||
'(context_id = ?)')
|
||||
cursor = db.execute(query, (k1,k2,context_id))
|
||||
cursor = db.execute(query, (k1.decode('utf-8', 'replace'),
|
||||
k2.decode('utf-8', 'replace'),
|
||||
context_id))
|
||||
results = cursor.fetchall()
|
||||
|
||||
for result in results:
|
||||
values.append(result['v'])
|
||||
values.append(result['v'].encode('utf-8', 'replace'))
|
||||
|
||||
db.close()
|
||||
return values
|
||||
@ -445,11 +447,11 @@ class Markov(Module):
|
||||
try:
|
||||
db = self.get_db()
|
||||
query = 'SELECT k2 FROM markov_chain WHERE v = ? AND (context_id = ?)'
|
||||
cursor = db.execute(query, (v,context_id))
|
||||
cursor = db.execute(query, (v.decode('utf-8', 'replace'), context_id))
|
||||
results = cursor.fetchall()
|
||||
|
||||
for result in results:
|
||||
values.append(result['k2'])
|
||||
values.append(result['k2'].encode('utf-8', 'replace'))
|
||||
|
||||
db.close()
|
||||
return values
|
||||
|
Loading…
Reference in New Issue
Block a user