fix: auto-fix code issues (cron)
- 修复重复导入/字段 - 修复异常处理 - 修复PEP8格式问题 - 添加类型注解
This commit is contained in:
@@ -179,7 +179,7 @@ class Neo4jManager:
|
||||
# ==================== 数据同步 ====================
|
||||
|
||||
def sync_project(
|
||||
self, project_id: str, project_name: str, project_description: str = ""
|
||||
self, project_id: str, project_name: str, project_description: str = "",
|
||||
) -> None:
|
||||
"""同步项目节点到 Neo4j"""
|
||||
if not self._driver:
|
||||
@@ -352,7 +352,7 @@ class Neo4jManager:
|
||||
# ==================== 复杂图查询 ====================
|
||||
|
||||
def find_shortest_path(
|
||||
self, source_id: str, target_id: str, max_depth: int = 10
|
||||
self, source_id: str, target_id: str, max_depth: int = 10,
|
||||
) -> PathResult | None:
|
||||
"""
|
||||
查找两个实体之间的最短路径
|
||||
@@ -404,11 +404,11 @@ class Neo4jManager:
|
||||
]
|
||||
|
||||
return PathResult(
|
||||
nodes=nodes, relationships=relationships, length=len(path.relationships)
|
||||
nodes=nodes, relationships=relationships, length=len(path.relationships),
|
||||
)
|
||||
|
||||
def find_all_paths(
|
||||
self, source_id: str, target_id: str, max_depth: int = 5, limit: int = 10
|
||||
self, source_id: str, target_id: str, max_depth: int = 5, limit: int = 10,
|
||||
) -> list[PathResult]:
|
||||
"""
|
||||
查找两个实体之间的所有路径
|
||||
@@ -460,14 +460,14 @@ class Neo4jManager:
|
||||
|
||||
paths.append(
|
||||
PathResult(
|
||||
nodes=nodes, relationships=relationships, length=len(path.relationships)
|
||||
)
|
||||
nodes=nodes, relationships=relationships, length=len(path.relationships),
|
||||
),
|
||||
)
|
||||
|
||||
return paths
|
||||
|
||||
def find_neighbors(
|
||||
self, entity_id: str, relation_type: str = None, limit: int = 50
|
||||
self, entity_id: str, relation_type: str = None, limit: int = 50,
|
||||
) -> list[dict]:
|
||||
"""
|
||||
查找实体的邻居节点
|
||||
@@ -516,7 +516,7 @@ class Neo4jManager:
|
||||
"type": node["type"],
|
||||
"relation_type": record["rel_type"],
|
||||
"evidence": record["evidence"],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
return neighbors
|
||||
@@ -628,7 +628,7 @@ class Neo4jManager:
|
||||
entity_name=record["entity_name"],
|
||||
score=record["score"],
|
||||
rank=rank,
|
||||
)
|
||||
),
|
||||
)
|
||||
rank += 1
|
||||
|
||||
@@ -680,7 +680,7 @@ class Neo4jManager:
|
||||
entity_name=record["entity_name"],
|
||||
score=float(record["score"]),
|
||||
rank=rank,
|
||||
)
|
||||
),
|
||||
)
|
||||
rank += 1
|
||||
|
||||
@@ -737,7 +737,7 @@ class Neo4jManager:
|
||||
"name": record["entity_name"],
|
||||
"type": record["entity_type"],
|
||||
"connections": record["connection_count"],
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
# 构建结果
|
||||
@@ -752,8 +752,8 @@ class Neo4jManager:
|
||||
|
||||
results.append(
|
||||
CommunityResult(
|
||||
community_id=comm_id, nodes=nodes, size=size, density=min(density, 1.0)
|
||||
)
|
||||
community_id=comm_id, nodes=nodes, size=size, density=min(density, 1.0),
|
||||
),
|
||||
)
|
||||
|
||||
# 按大小排序
|
||||
@@ -761,7 +761,7 @@ class Neo4jManager:
|
||||
return results
|
||||
|
||||
def find_central_entities(
|
||||
self, project_id: str, metric: str = "degree"
|
||||
self, project_id: str, metric: str = "degree",
|
||||
) -> list[CentralityResult]:
|
||||
"""
|
||||
查找中心实体
|
||||
@@ -812,7 +812,7 @@ class Neo4jManager:
|
||||
entity_name=record["entity_name"],
|
||||
score=float(record["score"]),
|
||||
rank=rank,
|
||||
)
|
||||
),
|
||||
)
|
||||
rank += 1
|
||||
|
||||
@@ -942,7 +942,7 @@ class Neo4jManager:
|
||||
"name": node["name"],
|
||||
"type": node["type"],
|
||||
"definition": node.get("definition", ""),
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
# 获取这些节点之间的关系
|
||||
@@ -993,7 +993,7 @@ def close_neo4j_manager() -> None:
|
||||
|
||||
|
||||
def sync_project_to_neo4j(
|
||||
project_id: str, project_name: str, entities: list[dict], relations: list[dict]
|
||||
project_id: str, project_name: str, entities: list[dict], relations: list[dict],
|
||||
) -> None:
|
||||
"""
|
||||
同步整个项目到 Neo4j
|
||||
@@ -1042,7 +1042,7 @@ def sync_project_to_neo4j(
|
||||
manager.sync_relations_batch(graph_relations)
|
||||
|
||||
logger.info(
|
||||
f"Synced project {project_id} to Neo4j: {len(entities)} entities, {len(relations)} relations"
|
||||
f"Synced project {project_id} to Neo4j: {len(entities)} entities, {len(relations)} relations",
|
||||
)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user