Ranker
ranker
Symbol importance ranking via PageRank.
Scores every symbol in a package by "importance" using a PageRank-like
algorithm on the symbol reference graph. Symbols that are more imported,
exported (__all__), or inherited rank higher.
Example
from axm_ast.core.ranker import rank_symbols scores = rank_symbols(pkg) sorted(scores, key=scores.get, reverse=True)[:5]
['Calculator', 'greet', 'resolve_path', ...]
pagerank(graph, damping=0.85, iterations=30)
Compute PageRank scores for a directed graph.
Pure-Python implementation without external dependencies.
Edges go from source → target meaning source references target,
so target receives the rank boost.
Internal-public: callable from sibling modules and tests, but not
re-exported in the package root __all__ (kept out of the public
SDK surface — rank_symbols is the documented high-level API).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
dict[str, set[str]]
|
Adjacency dict (node → set of nodes it points to). |
required |
damping
|
float
|
Damping factor (typically 0.85). |
0.85
|
iterations
|
int
|
Number of power-iteration steps. |
30
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dict mapping node → importance score (sums to ~1.0). |
Source code in packages/axm-ast/src/axm_ast/core/ranker.py
rank_symbols(pkg)
Rank all symbols in a package by importance.
Uses PageRank on the symbol reference graph to score each function and class. Higher scores mean the symbol is more referenced/exported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pkg
|
PackageInfo
|
Analyzed package info. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dict mapping symbol name → importance score. |
Example
scores = rank_symbols(pkg) top = sorted(scores, key=scores.get, reverse=True) top[0] 'Calculator'