mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-31 17:55:01 +00:00
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:
parent
f46feda846
commit
349bcf6973
1 changed files with 7 additions and 2 deletions
|
@ -5,6 +5,7 @@ import subprocess
|
||||||
import tiktoken
|
import tiktoken
|
||||||
import tempfile
|
import tempfile
|
||||||
from collections import defaultdict, Counter
|
from collections import defaultdict, Counter
|
||||||
|
import networkx as nx
|
||||||
|
|
||||||
from aider import prompts, utils
|
from aider import prompts, utils
|
||||||
from aider.dump import dump
|
from aider.dump import dump
|
||||||
|
@ -263,8 +264,6 @@ def call_map():
|
||||||
edges[name] += num_refs / num_defs
|
edges[name] += num_refs / num_defs
|
||||||
labels[name].append(ident)
|
labels[name].append(ident)
|
||||||
|
|
||||||
import networkx as nx
|
|
||||||
|
|
||||||
G = nx.DiGraph()
|
G = nx.DiGraph()
|
||||||
|
|
||||||
for edge, weight in edges.items():
|
for edge, weight in edges.items():
|
||||||
|
@ -273,6 +272,11 @@ def call_map():
|
||||||
|
|
||||||
ranked = nx.pagerank(G, weight="weight")
|
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
|
# drop low weight edges for plotting
|
||||||
edges_to_remove = [
|
edges_to_remove = [
|
||||||
(node1, node2) for node1, node2, data in G.edges(data=True) if data["weight"] < 1
|
(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)
|
G.remove_edges_from(edges_to_remove)
|
||||||
# Remove isolated nodes (nodes with no edges)
|
# Remove isolated nodes (nodes with no edges)
|
||||||
G.remove_nodes_from(list(nx.isolates(G)))
|
G.remove_nodes_from(list(nx.isolates(G)))
|
||||||
|
'''
|
||||||
|
|
||||||
max_rank = max(ranked.values())
|
max_rank = max(ranked.values())
|
||||||
min_rank = min(ranked.values())
|
min_rank = min(ranked.values())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue