mirror of
https://github.com/Mikaela/Limnoria.git
synced 2025-01-11 12:42:34 +01:00
Added is_first field to database to make sure markov phrases start naturally.
This commit is contained in:
parent
78b44e7a1e
commit
fd4c20c258
@ -68,6 +68,7 @@ class Markov(callbacks.Privmsg, ChannelDBHandler):
|
||||
id INTEGER PRIMARY KEY,
|
||||
first TEXT,
|
||||
second TEXT,
|
||||
is_first BOOLEAN,
|
||||
UNIQUE (first, second) ON CONFLICT IGNORE
|
||||
)""")
|
||||
cursor.execute("""CREATE TABLE follows (
|
||||
@ -86,15 +87,22 @@ class Markov(callbacks.Privmsg, ChannelDBHandler):
|
||||
db = self.getDb(channel)
|
||||
cursor = db.cursor()
|
||||
words = msg.args[1].split()
|
||||
isFirst = True
|
||||
for (first, second, follower) in window(words, 3):
|
||||
cursor.execute("""INSERT INTO pairs VALUES (NULL, %s, %s)""",
|
||||
first, second)
|
||||
if isFirst:
|
||||
cursor.execute("""INSERT OR REPLACE
|
||||
INTO pairs VALUES (NULL, %s, %s, 1)""",
|
||||
first, second)
|
||||
isFirst = False
|
||||
else:
|
||||
cursor.execute("INSERT INTO pairs VALUES (NULL, %s, %s, 0)",
|
||||
first, second)
|
||||
cursor.execute("""SELECT id FROM pairs
|
||||
WHERE first=%s AND second=%s""", first, second)
|
||||
id = int(cursor.fetchone()[0])
|
||||
cursor.execute("""INSERT INTO follows VALUES (NULL, %s, %s)""",
|
||||
id, follower)
|
||||
cursor.execute("""INSERT INTO pairs VALUES (NULL, %s, %s)""",
|
||||
cursor.execute("""INSERT INTO pairs VALUES (NULL, %s, %s, 0)""",
|
||||
second, follower)
|
||||
cursor.execute("""SELECT id FROM pairs
|
||||
WHERE first=%s AND second=%s""", second, follower)
|
||||
@ -116,6 +124,7 @@ class Markov(callbacks.Privmsg, ChannelDBHandler):
|
||||
cursor = db.cursor()
|
||||
words = []
|
||||
cursor.execute("""SELECT id, first, second FROM pairs
|
||||
WHERE is_first=1
|
||||
ORDER BY random()
|
||||
LIMIT 1""")
|
||||
(id, first, second) = cursor.fetchone()
|
||||
|
Loading…
Reference in New Issue
Block a user