Structural
structural
Pure AST structural-similarity helpers (Jaccard over statement-sets).
Moved verbatim from axm-audit's duplicate_tests rule (AXM-2172 / E5):
the similarity primitives are corpus-agnostic and 100% structural — they parse
an ast.FunctionDef, normalize away constant/identifier identity, and compare
the resulting statement-sets with Jaccard. No embedding backend is involved and
torch is never imported on this path (it lives behind the optional neural
extra, used only by :mod:axm_echo.embedding).
The audit duplicate_tests rule imports these helpers directly (a ~50ms pure
structural import, no torch → a legitimate direct import, not axm_call).
flatten_body(body)
Flatten compound statements (with/if/for/while/try) into their inner body.
Source code in packages/axm-echo/src/axm_echo/structural.py
jaccard_similarity(a, b)
Jaccard similarity between two sets (1.0 when both are empty).
Source code in packages/axm-echo/src/axm_echo/structural.py
normalize_dump(stmt)
Normalized single-statement dump (constants + name ids replaced).
Source code in packages/axm-echo/src/axm_echo/structural.py
statement_set(node)
Normalized stmt shapes (constants + name ids replaced) as a set.