Browse Source

fix: align knowledge query with relationship schema

lingfengQAQ 3 weeks ago
parent
commit
f175522c86

+ 1 - 1
webnovel-writer/scripts/data_modules/knowledge_query.py

@@ -48,7 +48,7 @@ class KnowledgeQuery:
         try:
             rows = conn.execute(
                 """
-                SELECT from_entity, to_entity, relationship_type, description, chapter
+                SELECT from_entity, to_entity, type AS relationship_type, description, chapter
                 FROM relationship_events
                 WHERE (from_entity = ? OR to_entity = ?) AND chapter <= ?
                 ORDER BY chapter ASC, id ASC

+ 9 - 3
webnovel-writer/scripts/data_modules/tests/test_knowledge_query.py

@@ -42,9 +42,15 @@ def setup_db(tmp_path):
             id INTEGER PRIMARY KEY AUTOINCREMENT,
             from_entity TEXT,
             to_entity TEXT,
-            relationship_type TEXT,
+            type TEXT NOT NULL,
+            action TEXT DEFAULT '',
+            polarity TEXT DEFAULT '',
+            strength REAL DEFAULT 0.0,
             description TEXT,
             chapter INTEGER,
+            scene_index INTEGER DEFAULT 0,
+            evidence TEXT DEFAULT '',
+            confidence REAL DEFAULT 1.0,
             created_at TEXT
         )
     """)
@@ -62,11 +68,11 @@ def setup_db(tmp_path):
         ("hanli", "realm", "筑基初期", "筑基中期", 50),
     )
     conn.execute(
-        "INSERT INTO relationship_events (from_entity, to_entity, relationship_type, chapter) VALUES (?, ?, ?, ?)",
+        "INSERT INTO relationship_events (from_entity, to_entity, type, chapter) VALUES (?, ?, ?, ?)",
         ("hanli", "陈巧倩", "同门", 20),
     )
     conn.execute(
-        "INSERT INTO relationship_events (from_entity, to_entity, relationship_type, chapter) VALUES (?, ?, ?, ?)",
+        "INSERT INTO relationship_events (from_entity, to_entity, type, chapter) VALUES (?, ?, ?, ?)",
         ("hanli", "陈巧倩", "合作", 45),
     )
     conn.commit()