Skip to content

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', ...]

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'

Source code in packages/axm-ast/src/axm_ast/core/ranker.py
def rank_symbols(pkg: PackageInfo) -> dict[str, float]:
    """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.

    Args:
        pkg: Analyzed package info.

    Returns:
        Dict mapping symbol name → importance score.

    Example:
        >>> scores = rank_symbols(pkg)
        >>> top = sorted(scores, key=scores.get, reverse=True)
        >>> top[0]
        'Calculator'
    """
    graph = _build_symbol_graph(pkg)
    all_scores = _pagerank(graph)

    # Filter to only function/class symbols (not module nodes)
    symbol_names = _collect_all_symbols(pkg)
    result = {name: score for name, score in all_scores.items() if name in symbol_names}

    return result