Fix linting
This commit is contained in:
@@ -208,7 +208,9 @@ class NetworkXStorage(BaseGraphStorage):
|
|||||||
# Handle special case for "*" label
|
# Handle special case for "*" label
|
||||||
if node_label == "*":
|
if node_label == "*":
|
||||||
# For "*", return the entire graph including all nodes and edges
|
# For "*", return the entire graph including all nodes and edges
|
||||||
subgraph = self._graph.copy() # Create a copy to avoid modifying the original graph
|
subgraph = (
|
||||||
|
self._graph.copy()
|
||||||
|
) # Create a copy to avoid modifying the original graph
|
||||||
else:
|
else:
|
||||||
# Find nodes with matching node id (partial match)
|
# Find nodes with matching node id (partial match)
|
||||||
nodes_to_explore = []
|
nodes_to_explore = []
|
||||||
@@ -228,11 +230,15 @@ class NetworkXStorage(BaseGraphStorage):
|
|||||||
if len(subgraph.nodes()) > max_graph_nodes:
|
if len(subgraph.nodes()) > max_graph_nodes:
|
||||||
origin_nodes = len(subgraph.nodes())
|
origin_nodes = len(subgraph.nodes())
|
||||||
node_degrees = dict(subgraph.degree())
|
node_degrees = dict(subgraph.degree())
|
||||||
top_nodes = sorted(node_degrees.items(), key=lambda x: x[1], reverse=True)[:max_graph_nodes]
|
top_nodes = sorted(node_degrees.items(), key=lambda x: x[1], reverse=True)[
|
||||||
|
:max_graph_nodes
|
||||||
|
]
|
||||||
top_node_ids = [node[0] for node in top_nodes]
|
top_node_ids = [node[0] for node in top_nodes]
|
||||||
# Create new subgraph with only top nodes
|
# Create new subgraph with only top nodes
|
||||||
subgraph = subgraph.subgraph(top_node_ids)
|
subgraph = subgraph.subgraph(top_node_ids)
|
||||||
logger.info(f"Reduced graph from {origin_nodes} nodes to {max_graph_nodes} nodes by degree (depth={max_depth})")
|
logger.info(
|
||||||
|
f"Reduced graph from {origin_nodes} nodes to {max_graph_nodes} nodes by degree (depth={max_depth})"
|
||||||
|
)
|
||||||
|
|
||||||
# Add nodes to result
|
# Add nodes to result
|
||||||
for node in subgraph.nodes():
|
for node in subgraph.nodes():
|
||||||
@@ -253,9 +259,7 @@ class NetworkXStorage(BaseGraphStorage):
|
|||||||
|
|
||||||
result.nodes.append(
|
result.nodes.append(
|
||||||
KnowledgeGraphNode(
|
KnowledgeGraphNode(
|
||||||
id=str(node),
|
id=str(node), labels=[str(node)], properties=node_properties
|
||||||
labels=[str(node)],
|
|
||||||
properties=node_properties
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
seen_nodes.add(str(node))
|
seen_nodes.add(str(node))
|
||||||
|
Reference in New Issue
Block a user