feat: Phase 1 MVP 完成
- 实现实体和关系同时提取(LLM) - 添加 transcripts/mentions/relations 数据持久化 - 新增 API: 关系列表、转录列表、实体提及位置 - 前端实体高亮显示和图谱联动 - 添加 STATUS.md 跟踪开发进度
This commit is contained in:
@@ -221,9 +221,81 @@ class DatabaseManager:
|
||||
conn.close()
|
||||
return [EntityMention(**dict(r)) for r in rows]
|
||||
|
||||
# Transcript operations
|
||||
def save_transcript(self, transcript_id: str, project_id: str, filename: str, full_text: str):
|
||||
"""保存转录记录"""
|
||||
conn = self.get_conn()
|
||||
now = datetime.now().isoformat()
|
||||
conn.execute(
|
||||
"INSERT INTO transcripts (id, project_id, filename, full_text, created_at) VALUES (?, ?, ?, ?, ?)",
|
||||
(transcript_id, project_id, filename, full_text, now)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
def get_transcript(self, transcript_id: str) -> Optional[dict]:
|
||||
"""获取转录记录"""
|
||||
conn = self.get_conn()
|
||||
row = conn.execute("SELECT * FROM transcripts WHERE id = ?", (transcript_id,)).fetchone()
|
||||
conn.close()
|
||||
if row:
|
||||
return dict(row)
|
||||
return None
|
||||
|
||||
def list_project_transcripts(self, project_id: str) -> List[dict]:
|
||||
"""列出项目的所有转录"""
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM transcripts WHERE project_id = ? ORDER BY created_at DESC",
|
||||
(project_id,)
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
# Relation operations
|
||||
def create_relation(self, project_id: str, source_entity_id: str, target_entity_id: str,
|
||||
relation_type: str = "related", evidence: str = "", transcript_id: str = ""):
|
||||
"""创建实体关系"""
|
||||
conn = self.get_conn()
|
||||
relation_id = str(uuid.uuid4())[:8]
|
||||
now = datetime.now().isoformat()
|
||||
conn.execute(
|
||||
"""INSERT INTO entity_relations
|
||||
(id, project_id, source_entity_id, target_entity_id, relation_type, evidence, transcript_id, created_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
(relation_id, project_id, source_entity_id, target_entity_id, relation_type, evidence, transcript_id, now)
|
||||
)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return relation_id
|
||||
|
||||
def get_entity_relations(self, entity_id: str) -> List[dict]:
|
||||
"""获取实体的所有关系"""
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"""SELECT * FROM entity_relations
|
||||
WHERE source_entity_id = ? OR target_entity_id = ?
|
||||
ORDER BY created_at DESC""",
|
||||
(entity_id, entity_id)
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
def list_project_relations(self, project_id: str) -> List[dict]:
|
||||
"""列出项目的所有关系"""
|
||||
conn = self.get_conn()
|
||||
rows = conn.execute(
|
||||
"SELECT * FROM entity_relations WHERE project_id = ? ORDER BY created_at DESC",
|
||||
(project_id,)
|
||||
).fetchall()
|
||||
conn.close()
|
||||
return [dict(r) for r in rows]
|
||||
|
||||
|
||||
# Singleton instance
|
||||
_db_manager = None
|
||||
|
||||
|
||||
def get_db_manager() -> DatabaseManager:
|
||||
global _db_manager
|
||||
if _db_manager is None:
|
||||
|
||||
Reference in New Issue
Block a user