Implement Task 16: Murphy Grammar Engine & Handwritten Journaling

This commit is contained in:
2026-10-06 15:42:10 +03:00
parent 3fae321322
commit 4d58002b48
11 changed files with 3267 additions and 10 deletions
+44
View File
@@ -256,6 +256,50 @@ def _migrate(conn: sqlite3.Connection):
except Exception:
pass
# Ensure grammar_units and grammar_progress tables exist
conn.execute("""
CREATE TABLE IF NOT EXISTS grammar_units (
id INTEGER PRIMARY KEY AUTOINCREMENT,
unit_num INTEGER UNIQUE NOT NULL,
level TEXT NOT NULL,
category TEXT NOT NULL,
title TEXT NOT NULL,
subtitle TEXT DEFAULT '',
golden_formula TEXT NOT NULL,
contrast_explanation_json TEXT NOT NULL,
journaling_prompt TEXT NOT NULL,
exercises_json TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
""")
conn.execute("CREATE INDEX IF NOT EXISTS idx_grammar_units_num ON grammar_units(unit_num);")
conn.execute("CREATE INDEX IF NOT EXISTS idx_grammar_units_level ON grammar_units(level);")
conn.execute("""
CREATE TABLE IF NOT EXISTS grammar_progress (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER NOT NULL,
unit_id INTEGER NOT NULL,
is_completed INTEGER DEFAULT 0,
score INTEGER DEFAULT 0,
handwritten_logged INTEGER DEFAULT 0,
handwritten_at TIMESTAMP,
completed_at TIMESTAMP,
FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
FOREIGN KEY (unit_id) REFERENCES grammar_units(id) ON DELETE CASCADE,
UNIQUE(user_id, unit_id)
);
""")
conn.execute("CREATE INDEX IF NOT EXISTS idx_grammar_prog_user_unit ON grammar_progress(user_id, unit_id);")
# Seed curated Murphy grammar units
try:
from app.grammar import seed_grammar_units
seed_grammar_units(conn)
except Exception:
pass
def _seed_offline_dictionary(conn: sqlite3.Connection):
"""Seeds the offline dictionary from data/offline_dict.tsv.gz if the table is empty."""