Translate comments to English
This commit is contained in:
@@ -1058,7 +1058,7 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
result = KnowledgeGraph()
|
result = KnowledgeGraph()
|
||||||
visited_nodes = set()
|
visited_nodes = set()
|
||||||
visited_edges = set()
|
visited_edges = set()
|
||||||
visited_edge_pairs = set() # 用于跟踪已处理的边对(排序后的source_id, target_id)
|
visited_edge_pairs = set() # Used to track processed edge pairs (sorted source_id, target_id)
|
||||||
|
|
||||||
# Get the starting node's data
|
# Get the starting node's data
|
||||||
async with self._driver.session(
|
async with self._driver.session(
|
||||||
@@ -1160,12 +1160,12 @@ class Neo4JStorage(BaseGraphStorage):
|
|||||||
properties=dict(rel),
|
properties=dict(rel),
|
||||||
)
|
)
|
||||||
|
|
||||||
# 对source_id和target_id进行排序,确保(A,B)和(B,A)被视为同一条边
|
# Sort source_id and target_id to ensure (A,B) and (B,A) are treated as the same edge
|
||||||
sorted_pair = tuple(sorted([current_node.id, target_id]))
|
sorted_pair = tuple(sorted([current_node.id, target_id]))
|
||||||
|
|
||||||
# 检查是否已存在相同的边(考虑无向性)
|
# Check if the same edge already exists (considering undirectedness)
|
||||||
if sorted_pair not in visited_edge_pairs:
|
if sorted_pair not in visited_edge_pairs:
|
||||||
# 只有当目标节点已经在结果中或将被添加到结果中时,才添加边
|
# Only add the edge if the target node is already in the result or will be added
|
||||||
if target_id in visited_nodes or (
|
if target_id in visited_nodes or (
|
||||||
target_id not in visited_nodes
|
target_id not in visited_nodes
|
||||||
and current_depth < max_depth
|
and current_depth < max_depth
|
||||||
|
@@ -1083,7 +1083,7 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
if self.db is None:
|
if self.db is None:
|
||||||
self.db = await ClientManager.get_client()
|
self.db = await ClientManager.get_client()
|
||||||
|
|
||||||
# 分别执行每个语句,忽略错误
|
# Execute each statement separately and ignore errors
|
||||||
queries = [
|
queries = [
|
||||||
f"SELECT create_graph('{self.graph_name}')",
|
f"SELECT create_graph('{self.graph_name}')",
|
||||||
f"SELECT create_vlabel('{self.graph_name}', 'base');",
|
f"SELECT create_vlabel('{self.graph_name}', 'base');",
|
||||||
@@ -2053,7 +2053,6 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
KnowledgeGraph object containing nodes and edges, with an is_truncated flag
|
KnowledgeGraph object containing nodes and edges, with an is_truncated flag
|
||||||
indicating whether the graph was truncated due to max_nodes limit
|
indicating whether the graph was truncated due to max_nodes limit
|
||||||
"""
|
"""
|
||||||
# 初始化 kg 变量,确保在所有情况下都有定义
|
|
||||||
kg = KnowledgeGraph()
|
kg = KnowledgeGraph()
|
||||||
|
|
||||||
# Handle wildcard query - get all nodes
|
# Handle wildcard query - get all nodes
|
||||||
@@ -2099,7 +2098,7 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
nodes_dict = {}
|
nodes_dict = {}
|
||||||
edges_dict = {}
|
edges_dict = {}
|
||||||
for result in results:
|
for result in results:
|
||||||
# 处理节点 a
|
# Process node a
|
||||||
if result.get("a") and isinstance(result["a"], dict):
|
if result.get("a") and isinstance(result["a"], dict):
|
||||||
node_a = result["a"]
|
node_a = result["a"]
|
||||||
node_id = str(node_a["id"])
|
node_id = str(node_a["id"])
|
||||||
@@ -2110,7 +2109,7 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
properties=node_a["properties"],
|
properties=node_a["properties"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# 处理节点 b
|
# Process node b
|
||||||
if result.get("b") and isinstance(result["b"], dict):
|
if result.get("b") and isinstance(result["b"], dict):
|
||||||
node_b = result["b"]
|
node_b = result["b"]
|
||||||
node_id = str(node_b["id"])
|
node_id = str(node_b["id"])
|
||||||
@@ -2121,7 +2120,7 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
properties=node_b["properties"],
|
properties=node_b["properties"],
|
||||||
)
|
)
|
||||||
|
|
||||||
# 处理边 r
|
# Process edge r
|
||||||
if result.get("r") and isinstance(result["r"], dict):
|
if result.get("r") and isinstance(result["r"], dict):
|
||||||
edge = result["r"]
|
edge = result["r"]
|
||||||
edge_id = str(edge["id"])
|
edge_id = str(edge["id"])
|
||||||
@@ -2147,7 +2146,7 @@ class PGGraphStorage(BaseGraphStorage):
|
|||||||
f"Subgraph query successful | Node count: {len(kg.nodes)} | Edge count: {len(kg.edges)}"
|
f"Subgraph query successful | Node count: {len(kg.nodes)} | Edge count: {len(kg.edges)}"
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# 非通配符查询,使用 BFS 算法
|
# For non-wildcard queries, use the BFS algorithm
|
||||||
kg = await self._bfs_subgraph(node_label, max_depth, max_nodes)
|
kg = await self._bfs_subgraph(node_label, max_depth, max_nodes)
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Subgraph query for '{node_label}' successful | Node count: {len(kg.nodes)} | Edge count: {len(kg.edges)}"
|
f"Subgraph query for '{node_label}' successful | Node count: {len(kg.nodes)} | Edge count: {len(kg.edges)}"
|
||||||
|
Reference in New Issue
Block a user