From 349bcf6973207998761e6fa6f75df88c945c316b Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Fri, 26 May 2023 18:40:41 -0700 Subject: [PATCH] aider: Removed all the G nodes except the top 10 based on their PageRank. # Context: USER: do the todo ASSISTANT: I see a "todo" comment in the `call_map()` function. I will remove the comment and implement the functionality to keep only the top 10 nodes based on their PageRank. ```python aider/repomap.py <<<<<<< ORIGINAL # todo: remove all the G nodes except the top 10 ======= top_10_nodes = sorted(ranked, key=ranked.get, reverse=True)[:10] nodes_to_remove = [node for node in G.nodes if node not in top_10_nodes] G.remove_nodes_from(nodes_to_remove) >>>>>>> UPDATED ``` This change will keep only the top 10 nodes in the graph based on their PageRank and remove the rest. --- aider/repomap.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/aider/repomap.py b/aider/repomap.py index e491617f2..aa958a3d7 100644 --- a/aider/repomap.py +++ b/aider/repomap.py @@ -5,6 +5,7 @@ import subprocess import tiktoken import tempfile from collections import defaultdict, Counter +import networkx as nx from aider import prompts, utils from aider.dump import dump @@ -263,8 +264,6 @@ def call_map(): edges[name] += num_refs / num_defs labels[name].append(ident) - import networkx as nx - G = nx.DiGraph() for edge, weight in edges.items(): @@ -273,6 +272,11 @@ def call_map(): ranked = nx.pagerank(G, weight="weight") + top_10_nodes = sorted(ranked, key=ranked.get, reverse=True)[:10] + nodes_to_remove = [node for node in G.nodes if node not in top_10_nodes] + G.remove_nodes_from(nodes_to_remove) + + ''' # drop low weight edges for plotting edges_to_remove = [ (node1, node2) for node1, node2, data in G.edges(data=True) if data["weight"] < 1 @@ -280,6 +284,7 @@ def call_map(): G.remove_edges_from(edges_to_remove) # Remove isolated nodes (nodes with no edges) G.remove_nodes_from(list(nx.isolates(G))) + ''' max_rank = max(ranked.values()) min_rank = min(ranked.values())