topos.functors.probes.uast.compare¶
UAST Comparison Module¶
Cross-language structural comparison built on top of UAST kind values.
The existing topos.metrics.distance module is grammar-specific because it consumes raw tree-sitter node types. This module is the language-agnostic counterpart: every distance here operates on normalized UAST kinds, so two implementations of the same algorithm in different languages can be compared on a single axis.
- class topos.functors.probes.uast.compare.UASTComparison(kind_distance, edit_distance, control_flow_delta, summary_delta, source_summary, target_summary)[source]
Bases:
objectAggregate cross-language comparison between two UAST roots.
- kind_distance
- edit_distance
- control_flow_delta
- summary_delta
- source_summary
- target_summary
- property detects_difference
True if any structural difference was found.
- topos.functors.probes.uast.compare.uast_kind_distance(source, target, *, include_unknown=True)[source]
L1 distance between normalized UAST kind histograms.
Both histograms are normalized to probability distributions so the result lies in [0, 1] regardless of program size. A return value of 0.0 means both programs use the same mix of UAST kinds; 1.0 means they share no kinds at all.
- topos.functors.probes.uast.compare.uast_edit_distance(source, target, *, include_unknown=True)[source]
Tree edit distance over UAST kind sequences (DFS pre-order).
Reuses the Wagner-Fischer implementation from topos.metrics.distance so the operation accounting stays consistent with the tree-sitter variant.
- topos.functors.probes.uast.compare.compare_uast(source, target, *, include_unknown=True)[source]
Run the full UAST comparison suite for a single pair of roots.