fix: auto-fix code issues (cron)

- 修复重复导入/字段
- 修复异常处理
- 修复PEP8格式问题 (816+ 处)
- 添加缺失的导入 (json, re)
- 统一SQL查询格式
- 修复赋值语句空格问题

修复文件:
- db_manager.py (96处)
- search_manager.py (77处)
- ops_manager.py (66处)
- developer_ecosystem_manager.py (68处)
- growth_manager.py (60处)
- enterprise_manager.py (61处)
- tenant_manager.py (57处)
- plugin_manager.py (48处)
- subscription_manager.py (46处)
- security_manager.py (29处)
- workflow_manager.py (32处)
- localization_manager.py (31处)
- api_key_manager.py (20处)
- ai_manager.py (23处)
- performance_manager.py (24处)
- neo4j_manager.py (25处)
- collaboration_manager.py (33处)
- test_phase8_task8.py (16处)
- test_phase8_task6.py (4处)
- knowledge_reasoner.py (添加import json)
- llm_client.py (添加import json)
This commit is contained in:
AutoFix Bot
2026-03-03 00:11:51 +08:00
parent c695e99eaf
commit 2a0ed6af4d
23 changed files with 1160 additions and 947 deletions

View File

@@ -154,7 +154,7 @@ class DatabaseManager:
def get_project(self, project_id: str) -> Project | None:
conn = self.get_conn()
row = conn.execute("SELECT * FROM projects WHERE id = ?", (project_id,)).fetchone()
row = conn.execute("SELECT * FROM projects WHERE id = ?", (project_id,)).fetchone()
conn.close()
if row:
return Project(**dict(row))
@@ -194,8 +194,8 @@ class DatabaseManager:
"""通过名称查找实体(用于对齐)"""
conn = self.get_conn()
row = conn.execute(
"""SELECT * FROM entities WHERE project_id = ?
AND (name = ? OR canonical_name = ? OR aliases LIKE ?)""",
"""SELECT * FROM entities WHERE project_id = ?
AND (name = ? OR canonical_name = ? OR aliases LIKE ?)""",
(project_id, name, name, f'%"{name}"%'),
).fetchone()
conn.close()
@@ -211,7 +211,7 @@ class DatabaseManager:
"""查找相似实体"""
conn = self.get_conn()
rows = conn.execute(
"SELECT * FROM entities WHERE project_id = ? AND name LIKE ?",
"SELECT * FROM entities WHERE project_id = ? AND name LIKE ?",
(project_id, f"%{name}%"),
).fetchall()
conn.close()
@@ -227,8 +227,8 @@ class DatabaseManager:
"""合并两个实体"""
conn = self.get_conn()
target = conn.execute("SELECT * FROM entities WHERE id = ?", (target_id,)).fetchone()
source = conn.execute("SELECT * FROM entities WHERE id = ?", (source_id,)).fetchone()
target = conn.execute("SELECT * FROM entities WHERE id = ?", (target_id,)).fetchone()
source = conn.execute("SELECT * FROM entities WHERE id = ?", (source_id,)).fetchone()
if not target or not source:
conn.close()
@@ -239,21 +239,21 @@ class DatabaseManager:
target_aliases.update(json.loads(source["aliases"]) if source["aliases"] else [])
conn.execute(
"UPDATE entities SET aliases = ?, updated_at = ? WHERE id = ?",
"UPDATE entities SET aliases = ?, updated_at = ? WHERE id = ?",
(json.dumps(list(target_aliases)), datetime.now().isoformat(), target_id),
)
conn.execute(
"UPDATE entity_mentions SET entity_id = ? WHERE entity_id = ?", (target_id, source_id)
"UPDATE entity_mentions SET entity_id = ? WHERE entity_id = ?", (target_id, source_id)
)
conn.execute(
"UPDATE entity_relations SET source_entity_id = ? WHERE source_entity_id = ?",
"UPDATE entity_relations SET source_entity_id = ? WHERE source_entity_id = ?",
(target_id, source_id),
)
conn.execute(
"UPDATE entity_relations SET target_entity_id = ? WHERE target_entity_id = ?",
"UPDATE entity_relations SET target_entity_id = ? WHERE target_entity_id = ?",
(target_id, source_id),
)
conn.execute("DELETE FROM entities WHERE id = ?", (source_id,))
conn.execute("DELETE FROM entities WHERE id = ?", (source_id,))
conn.commit()
conn.close()
@@ -261,7 +261,7 @@ class DatabaseManager:
def get_entity(self, entity_id: str) -> Entity | None:
conn = self.get_conn()
row = conn.execute("SELECT * FROM entities WHERE id = ?", (entity_id,)).fetchone()
row = conn.execute("SELECT * FROM entities WHERE id = ?", (entity_id,)).fetchone()
conn.close()
if row:
data = dict(row)
@@ -272,7 +272,7 @@ class DatabaseManager:
def list_project_entities(self, project_id: str) -> list[Entity]:
conn = self.get_conn()
rows = conn.execute(
"SELECT * FROM entities WHERE project_id = ? ORDER BY updated_at DESC", (project_id,)
"SELECT * FROM entities WHERE project_id = ? ORDER BY updated_at DESC", (project_id,)
).fetchall()
conn.close()
@@ -297,18 +297,18 @@ class DatabaseManager:
values.append(kwargs[field])
if "aliases" in kwargs:
updates.append("aliases = ?")
updates.append("aliases = ?")
values.append(json.dumps(kwargs["aliases"]))
if not updates:
conn.close()
return self.get_entity(entity_id)
updates.append("updated_at = ?")
updates.append("updated_at = ?")
values.append(datetime.now().isoformat())
values.append(entity_id)
query = f"UPDATE entities SET {', '.join(updates)} WHERE id = ?"
query = f"UPDATE entities SET {', '.join(updates)} WHERE id = ?"
conn.execute(query, values)
conn.commit()
conn.close()
@@ -317,13 +317,13 @@ class DatabaseManager:
def delete_entity(self, entity_id: str) -> None:
"""删除实体及其关联数据"""
conn = self.get_conn()
conn.execute("DELETE FROM entity_mentions WHERE entity_id = ?", (entity_id,))
conn.execute("DELETE FROM entity_mentions WHERE entity_id = ?", (entity_id,))
conn.execute(
"DELETE FROM entity_relations WHERE source_entity_id = ? OR target_entity_id = ?",
"DELETE FROM entity_relations WHERE source_entity_id = ? OR target_entity_id = ?",
(entity_id, entity_id),
)
conn.execute("DELETE FROM entity_attributes WHERE entity_id = ?", (entity_id,))
conn.execute("DELETE FROM entities WHERE id = ?", (entity_id,))
conn.execute("DELETE FROM entity_attributes WHERE entity_id = ?", (entity_id,))
conn.execute("DELETE FROM entities WHERE id = ?", (entity_id,))
conn.commit()
conn.close()
@@ -352,7 +352,7 @@ class DatabaseManager:
def get_entity_mentions(self, entity_id: str) -> list[EntityMention]:
conn = self.get_conn()
rows = conn.execute(
"SELECT * FROM entity_mentions WHERE entity_id = ? ORDER BY transcript_id, start_pos",
"SELECT * FROM entity_mentions WHERE entity_id = ? ORDER BY transcript_id, start_pos",
(entity_id,),
).fetchall()
conn.close()
@@ -381,14 +381,14 @@ class DatabaseManager:
def get_transcript(self, transcript_id: str) -> dict | None:
conn = self.get_conn()
row = conn.execute("SELECT * FROM transcripts WHERE id = ?", (transcript_id,)).fetchone()
row = conn.execute("SELECT * FROM transcripts WHERE id = ?", (transcript_id,)).fetchone()
conn.close()
return dict(row) if row else 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",
"SELECT * FROM transcripts WHERE project_id = ? ORDER BY created_at DESC",
(project_id,),
).fetchall()
conn.close()
@@ -398,11 +398,11 @@ class DatabaseManager:
conn = self.get_conn()
now = datetime.now().isoformat()
conn.execute(
"UPDATE transcripts SET full_text = ?, updated_at = ? WHERE id = ?",
"UPDATE transcripts SET full_text = ?, updated_at = ? WHERE id = ?",
(full_text, now, transcript_id),
)
conn.commit()
row = conn.execute("SELECT * FROM transcripts WHERE id = ?", (transcript_id,)).fetchone()
row = conn.execute("SELECT * FROM transcripts WHERE id = ?", (transcript_id,)).fetchone()
conn.close()
return dict(row) if row else None
@@ -444,7 +444,7 @@ class DatabaseManager:
conn = self.get_conn()
rows = conn.execute(
"""SELECT * FROM entity_relations
WHERE source_entity_id = ? OR target_entity_id = ?
WHERE source_entity_id = ? OR target_entity_id = ?
ORDER BY created_at DESC""",
(entity_id, entity_id),
).fetchall()
@@ -454,7 +454,7 @@ class DatabaseManager:
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",
"SELECT * FROM entity_relations WHERE project_id = ? ORDER BY created_at DESC",
(project_id,),
).fetchall()
conn.close()
@@ -472,20 +472,20 @@ class DatabaseManager:
values.append(kwargs[field])
if updates:
query = f"UPDATE entity_relations SET {', '.join(updates)} WHERE id = ?"
query = f"UPDATE entity_relations SET {', '.join(updates)} WHERE id = ?"
values.append(relation_id)
conn.execute(query, values)
conn.commit()
row = conn.execute(
"SELECT * FROM entity_relations WHERE id = ?", (relation_id,)
"SELECT * FROM entity_relations WHERE id = ?", (relation_id,)
).fetchone()
conn.close()
return dict(row) if row else None
def delete_relation(self, relation_id: str) -> None:
conn = self.get_conn()
conn.execute("DELETE FROM entity_relations WHERE id = ?", (relation_id,))
conn.execute("DELETE FROM entity_relations WHERE id = ?", (relation_id,))
conn.commit()
conn.close()
@@ -494,12 +494,12 @@ class DatabaseManager:
def add_glossary_term(self, project_id: str, term: str, pronunciation: str = "") -> str:
conn = self.get_conn()
existing = conn.execute(
"SELECT * FROM glossary WHERE project_id = ? AND term = ?", (project_id, term)
"SELECT * FROM glossary WHERE project_id = ? AND term = ?", (project_id, term)
).fetchone()
if existing:
conn.execute(
"UPDATE glossary SET frequency = frequency + 1 WHERE id = ?", (existing["id"],)
"UPDATE glossary SET frequency = frequency + 1 WHERE id = ?", (existing["id"],)
)
conn.commit()
conn.close()
@@ -519,14 +519,14 @@ class DatabaseManager:
def list_glossary(self, project_id: str) -> list[dict]:
conn = self.get_conn()
rows = conn.execute(
"SELECT * FROM glossary WHERE project_id = ? ORDER BY frequency DESC", (project_id,)
"SELECT * FROM glossary WHERE project_id = ? ORDER BY frequency DESC", (project_id,)
).fetchall()
conn.close()
return [dict(r) for r in rows]
def delete_glossary_term(self, term_id: str) -> None:
conn = self.get_conn()
conn.execute("DELETE FROM glossary WHERE id = ?", (term_id,))
conn.execute("DELETE FROM glossary WHERE id = ?", (term_id,))
conn.commit()
conn.close()
@@ -539,10 +539,10 @@ class DatabaseManager:
s.name as source_name, t.name as target_name,
tr.filename as transcript_filename, tr.full_text as transcript_text
FROM entity_relations r
JOIN entities s ON r.source_entity_id = s.id
JOIN entities t ON r.target_entity_id = t.id
LEFT JOIN transcripts tr ON r.transcript_id = tr.id
WHERE r.id = ?""",
JOIN entities s ON r.source_entity_id = s.id
JOIN entities t ON r.target_entity_id = t.id
LEFT JOIN transcripts tr ON r.transcript_id = tr.id
WHERE r.id = ?""",
(relation_id,),
).fetchone()
conn.close()
@@ -550,7 +550,7 @@ class DatabaseManager:
def get_entity_with_mentions(self, entity_id: str) -> dict | None:
conn = self.get_conn()
entity_row = conn.execute("SELECT * FROM entities WHERE id = ?", (entity_id,)).fetchone()
entity_row = conn.execute("SELECT * FROM entities WHERE id = ?", (entity_id,)).fetchone()
if not entity_row:
conn.close()
return None
@@ -561,8 +561,8 @@ class DatabaseManager:
mentions = conn.execute(
"""SELECT m.*, t.filename, t.created_at as transcript_date
FROM entity_mentions m
JOIN transcripts t ON m.transcript_id = t.id
WHERE m.entity_id = ? ORDER BY t.created_at, m.start_pos""",
JOIN transcripts t ON m.transcript_id = t.id
WHERE m.entity_id = ? ORDER BY t.created_at, m.start_pos""",
(entity_id,),
).fetchall()
entity["mentions"] = [dict(m) for m in mentions]
@@ -571,9 +571,9 @@ class DatabaseManager:
relations = conn.execute(
"""SELECT r.*, s.name as source_name, t.name as target_name
FROM entity_relations r
JOIN entities s ON r.source_entity_id = s.id
JOIN entities t ON r.target_entity_id = t.id
WHERE r.source_entity_id = ? OR r.target_entity_id = ?
JOIN entities s ON r.source_entity_id = s.id
JOIN entities t ON r.target_entity_id = t.id
WHERE r.source_entity_id = ? OR r.target_entity_id = ?
ORDER BY r.created_at DESC""",
(entity_id, entity_id),
).fetchall()
@@ -586,7 +586,7 @@ class DatabaseManager:
conn = self.get_conn()
rows = conn.execute(
"""SELECT * FROM entities
WHERE project_id = ? AND
WHERE project_id = ? AND
(name LIKE ? OR definition LIKE ? OR aliases LIKE ?)
ORDER BY name""",
(project_id, f"%{query}%", f"%{query}%", f"%{query}%"),
@@ -602,31 +602,31 @@ class DatabaseManager:
def get_project_summary(self, project_id: str) -> dict:
conn = self.get_conn()
project = conn.execute("SELECT * FROM projects WHERE id = ?", (project_id,)).fetchone()
project = conn.execute("SELECT * FROM projects WHERE id = ?", (project_id,)).fetchone()
entity_count = conn.execute(
"SELECT COUNT(*) as count FROM entities WHERE project_id = ?", (project_id,)
"SELECT COUNT(*) as count FROM entities WHERE project_id = ?", (project_id,)
).fetchone()["count"]
transcript_count = conn.execute(
"SELECT COUNT(*) as count FROM transcripts WHERE project_id = ?", (project_id,)
"SELECT COUNT(*) as count FROM transcripts WHERE project_id = ?", (project_id,)
).fetchone()["count"]
relation_count = conn.execute(
"SELECT COUNT(*) as count FROM entity_relations WHERE project_id = ?", (project_id,)
"SELECT COUNT(*) as count FROM entity_relations WHERE project_id = ?", (project_id,)
).fetchone()["count"]
recent_transcripts = conn.execute(
"""SELECT filename, full_text, created_at FROM transcripts
WHERE project_id = ? ORDER BY created_at DESC LIMIT 5""",
WHERE project_id = ? ORDER BY created_at DESC LIMIT 5""",
(project_id,),
).fetchall()
top_entities = conn.execute(
"""SELECT e.name, e.type, e.definition, COUNT(m.id) as mention_count
FROM entities e
LEFT JOIN entity_mentions m ON e.id = m.entity_id
WHERE e.project_id = ?
LEFT JOIN entity_mentions m ON e.id = m.entity_id
WHERE e.project_id = ?
GROUP BY e.id ORDER BY mention_count DESC LIMIT 10""",
(project_id,),
).fetchall()
@@ -649,7 +649,7 @@ class DatabaseManager:
) -> str:
conn = self.get_conn()
row = conn.execute(
"SELECT full_text FROM transcripts WHERE id = ?", (transcript_id,)
"SELECT full_text FROM transcripts WHERE id = ?", (transcript_id,)
).fetchone()
conn.close()
if not row:
@@ -666,11 +666,11 @@ class DatabaseManager:
) -> list[dict]:
conn = self.get_conn()
conditions = ["t.project_id = ?"]
conditions = ["t.project_id = ?"]
params = [project_id]
if entity_id:
conditions.append("m.entity_id = ?")
conditions.append("m.entity_id = ?")
params.append(entity_id)
if start_date:
conditions.append("t.created_at >= ?")
@@ -685,8 +685,8 @@ class DatabaseManager:
f"""SELECT m.*, e.name as entity_name, e.type as entity_type, e.definition,
t.filename, t.created_at as event_date, t.type as source_type
FROM entity_mentions m
JOIN entities e ON m.entity_id = e.id
JOIN transcripts t ON m.transcript_id = t.id
JOIN entities e ON m.entity_id = e.id
JOIN transcripts t ON m.transcript_id = t.id
WHERE {where_clause} ORDER BY t.created_at, m.start_pos""",
params,
).fetchall()
@@ -721,8 +721,8 @@ class DatabaseManager:
daily_stats = conn.execute(
"""SELECT DATE(t.created_at) as date, COUNT(*) as count
FROM entity_mentions m
JOIN transcripts t ON m.transcript_id = t.id
WHERE t.project_id = ? GROUP BY DATE(t.created_at) ORDER BY date""",
JOIN transcripts t ON m.transcript_id = t.id
WHERE t.project_id = ? GROUP BY DATE(t.created_at) ORDER BY date""",
(project_id,),
).fetchall()
@@ -731,9 +731,9 @@ class DatabaseManager:
MIN(t.created_at) as first_mentioned,
MAX(t.created_at) as last_mentioned
FROM entities e
LEFT JOIN entity_mentions m ON e.id = m.entity_id
LEFT JOIN transcripts t ON m.transcript_id = t.id
WHERE e.project_id = ?
LEFT JOIN entity_mentions m ON e.id = m.entity_id
LEFT JOIN transcripts t ON m.transcript_id = t.id
WHERE e.project_id = ?
GROUP BY e.id ORDER BY mention_count DESC LIMIT 20""",
(project_id,),
).fetchall()
@@ -776,7 +776,7 @@ class DatabaseManager:
def get_attribute_template(self, template_id: str) -> AttributeTemplate | None:
conn = self.get_conn()
row = conn.execute(
"SELECT * FROM attribute_templates WHERE id = ?", (template_id,)
"SELECT * FROM attribute_templates WHERE id = ?", (template_id,)
).fetchone()
conn.close()
if row:
@@ -788,7 +788,7 @@ class DatabaseManager:
def list_attribute_templates(self, project_id: str) -> list[AttributeTemplate]:
conn = self.get_conn()
rows = conn.execute(
"""SELECT * FROM attribute_templates WHERE project_id = ?
"""SELECT * FROM attribute_templates WHERE project_id = ?
ORDER BY sort_order, created_at""",
(project_id,),
).fetchall()
@@ -824,10 +824,10 @@ class DatabaseManager:
values.append(kwargs[field])
if updates:
updates.append("updated_at = ?")
updates.append("updated_at = ?")
values.append(datetime.now().isoformat())
values.append(template_id)
query = f"UPDATE attribute_templates SET {', '.join(updates)} WHERE id = ?"
query = f"UPDATE attribute_templates SET {', '.join(updates)} WHERE id = ?"
conn.execute(query, values)
conn.commit()
@@ -836,7 +836,7 @@ class DatabaseManager:
def delete_attribute_template(self, template_id: str) -> None:
conn = self.get_conn()
conn.execute("DELETE FROM attribute_templates WHERE id = ?", (template_id,))
conn.execute("DELETE FROM attribute_templates WHERE id = ?", (template_id,))
conn.commit()
conn.close()
@@ -847,7 +847,7 @@ class DatabaseManager:
now = datetime.now().isoformat()
old_row = conn.execute(
"SELECT value FROM entity_attributes WHERE entity_id = ? AND template_id = ?",
"SELECT value FROM entity_attributes WHERE entity_id = ? AND template_id = ?",
(attr.entity_id, attr.template_id),
).fetchone()
old_value = old_row["value"] if old_row else None
@@ -876,12 +876,12 @@ class DatabaseManager:
VALUES (
COALESCE(
(SELECT id FROM entity_attributes
WHERE entity_id = ? AND template_id = ?), ?
WHERE entity_id = ? AND template_id = ?), ?
),
?, ?, ?,
COALESCE(
(SELECT created_at FROM entity_attributes
WHERE entity_id = ? AND template_id = ?), ?
WHERE entity_id = ? AND template_id = ?), ?
),
?)""",
(
@@ -907,8 +907,8 @@ class DatabaseManager:
rows = conn.execute(
"""SELECT ea.*, at.name as template_name, at.type as template_type
FROM entity_attributes ea
LEFT JOIN attribute_templates at ON ea.template_id = at.id
WHERE ea.entity_id = ? ORDER BY ea.created_at""",
LEFT JOIN attribute_templates at ON ea.template_id = at.id
WHERE ea.entity_id = ? ORDER BY ea.created_at""",
(entity_id,),
).fetchall()
conn.close()
@@ -935,7 +935,7 @@ class DatabaseManager:
conn = self.get_conn()
old_row = conn.execute(
"""SELECT value FROM entity_attributes
WHERE entity_id = ? AND template_id = ?""",
WHERE entity_id = ? AND template_id = ?""",
(entity_id, template_id),
).fetchone()
@@ -957,7 +957,7 @@ class DatabaseManager:
),
)
conn.execute(
"DELETE FROM entity_attributes WHERE entity_id = ? AND template_id = ?",
"DELETE FROM entity_attributes WHERE entity_id = ? AND template_id = ?",
(entity_id, template_id),
)
conn.commit()
@@ -971,10 +971,10 @@ class DatabaseManager:
params = []
if entity_id:
conditions.append("ah.entity_id = ?")
conditions.append("ah.entity_id = ?")
params.append(entity_id)
if template_id:
conditions.append("ah.template_id = ?")
conditions.append("ah.template_id = ?")
params.append(template_id)
where_clause = " AND ".join(conditions) if conditions else "1 = 1"
@@ -1005,7 +1005,7 @@ class DatabaseManager:
rows = conn.execute(
f"""SELECT ea.*, at.name as template_name
FROM entity_attributes ea
JOIN attribute_templates at ON ea.template_id = at.id
JOIN attribute_templates at ON ea.template_id = at.id
WHERE ea.entity_id IN ({placeholders})""",
entity_ids,
).fetchall()
@@ -1079,7 +1079,7 @@ class DatabaseManager:
def get_video(self, video_id: str) -> dict | None:
"""获取视频信息"""
conn = self.get_conn()
row = conn.execute("SELECT * FROM videos WHERE id = ?", (video_id,)).fetchone()
row = conn.execute("SELECT * FROM videos WHERE id = ?", (video_id,)).fetchone()
conn.close()
if row:
@@ -1098,7 +1098,7 @@ class DatabaseManager:
"""获取项目的所有视频"""
conn = self.get_conn()
rows = conn.execute(
"SELECT * FROM videos WHERE project_id = ? ORDER BY created_at DESC", (project_id,)
"SELECT * FROM videos WHERE project_id = ? ORDER BY created_at DESC", (project_id,)
).fetchall()
conn.close()
@@ -1153,7 +1153,7 @@ class DatabaseManager:
"""获取视频的所有帧"""
conn = self.get_conn()
rows = conn.execute(
"""SELECT * FROM video_frames WHERE video_id = ? ORDER BY timestamp""", (video_id,)
"""SELECT * FROM video_frames WHERE video_id = ? ORDER BY timestamp""", (video_id,)
).fetchall()
conn.close()
@@ -1205,7 +1205,7 @@ class DatabaseManager:
def get_image(self, image_id: str) -> dict | None:
"""获取图片信息"""
conn = self.get_conn()
row = conn.execute("SELECT * FROM images WHERE id = ?", (image_id,)).fetchone()
row = conn.execute("SELECT * FROM images WHERE id = ?", (image_id,)).fetchone()
conn.close()
if row:
@@ -1223,7 +1223,7 @@ class DatabaseManager:
"""获取项目的所有图片"""
conn = self.get_conn()
rows = conn.execute(
"SELECT * FROM images WHERE project_id = ? ORDER BY created_at DESC", (project_id,)
"SELECT * FROM images WHERE project_id = ? ORDER BY created_at DESC", (project_id,)
).fetchall()
conn.close()
@@ -1281,8 +1281,8 @@ class DatabaseManager:
rows = conn.execute(
"""SELECT m.*, e.name as entity_name
FROM multimodal_mentions m
JOIN entities e ON m.entity_id = e.id
WHERE m.entity_id = ? ORDER BY m.created_at DESC""",
JOIN entities e ON m.entity_id = e.id
WHERE m.entity_id = ? ORDER BY m.created_at DESC""",
(entity_id,),
).fetchall()
conn.close()
@@ -1296,8 +1296,8 @@ class DatabaseManager:
rows = conn.execute(
"""SELECT m.*, e.name as entity_name
FROM multimodal_mentions m
JOIN entities e ON m.entity_id = e.id
WHERE m.project_id = ? AND m.modality = ?
JOIN entities e ON m.entity_id = e.id
WHERE m.project_id = ? AND m.modality = ?
ORDER BY m.created_at DESC""",
(project_id, modality),
).fetchall()
@@ -1305,8 +1305,8 @@ class DatabaseManager:
rows = conn.execute(
"""SELECT m.*, e.name as entity_name
FROM multimodal_mentions m
JOIN entities e ON m.entity_id = e.id
WHERE m.project_id = ? ORDER BY m.created_at DESC""",
JOIN entities e ON m.entity_id = e.id
WHERE m.project_id = ? ORDER BY m.created_at DESC""",
(project_id,),
).fetchall()
@@ -1353,9 +1353,9 @@ class DatabaseManager:
rows = conn.execute(
"""SELECT l.*, e1.name as entity_name, e2.name as linked_entity_name
FROM multimodal_entity_links l
JOIN entities e1 ON l.entity_id = e1.id
JOIN entities e2 ON l.linked_entity_id = e2.id
WHERE l.entity_id = ? OR l.linked_entity_id = ?""",
JOIN entities e1 ON l.entity_id = e1.id
JOIN entities e2 ON l.linked_entity_id = e2.id
WHERE l.entity_id = ? OR l.linked_entity_id = ?""",
(entity_id, entity_id),
).fetchall()
conn.close()
@@ -1381,20 +1381,20 @@ class DatabaseManager:
# 视频数量
row = conn.execute(
"SELECT COUNT(*) as count FROM videos WHERE project_id = ?", (project_id,)
"SELECT COUNT(*) as count FROM videos WHERE project_id = ?", (project_id,)
).fetchone()
stats["video_count"] = row["count"]
# 图片数量
row = conn.execute(
"SELECT COUNT(*) as count FROM images WHERE project_id = ?", (project_id,)
"SELECT COUNT(*) as count FROM images WHERE project_id = ?", (project_id,)
).fetchone()
stats["image_count"] = row["count"]
# 多模态实体数量
row = conn.execute(
"""SELECT COUNT(DISTINCT entity_id) as count
FROM multimodal_mentions WHERE project_id = ?""",
FROM multimodal_mentions WHERE project_id = ?""",
(project_id,),
).fetchone()
stats["multimodal_entity_count"] = row["count"]
@@ -1402,7 +1402,7 @@ class DatabaseManager:
# 跨模态关联数量
row = conn.execute(
"""SELECT COUNT(*) as count FROM multimodal_entity_links
WHERE entity_id IN (SELECT id FROM entities WHERE project_id = ?)""",
WHERE entity_id IN (SELECT id FROM entities WHERE project_id = ?)""",
(project_id,),
).fetchone()
stats["cross_modal_links"] = row["count"]
@@ -1411,7 +1411,7 @@ class DatabaseManager:
for modality in ["audio", "video", "image", "document"]:
row = conn.execute(
"""SELECT COUNT(*) as count FROM multimodal_mentions
WHERE project_id = ? AND modality = ?""",
WHERE project_id = ? AND modality = ?""",
(project_id, modality),
).fetchone()
stats["modality_distribution"][modality] = row["count"]