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.
This commit is contained in:
Paul Gauthier 2023-05-26 18:40:41 -07:00
parent f46feda846
commit 349bcf6973

View file

@ -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())