Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
refactor(296): remove the dead ConfusionMatrixCalculator methods
calculate_list_confusion_matrix, calculate_nested_field_metrics and
calculate_single_nested_field_metrics only called each other, and their
only way in was three StructuredModel wrappers that nothing calls. All
six had zero executed lines across the full suite. Remove them, the
HungarianHelper, NonMatchesHelper and List imports that only they used,
and the refactoring notes that listed the wrappers.

StructuredListComparator._calculate_nested_field_metrics is a separate,
live method with the same name and is untouched. So are
ConfusionMatrixCalculator.__init__, classify_field_for_confusion_matrix
and StructuredModel._classify_field_for_confusion_matrix, which
StructuredListComparator calls.

The 1e-10 threshold window that algorithms/README.md and the
HungarianMatcher.calculate_metrics docstring attribute to
ConfusionMatrixCalculator lived in the deleted
calculate_nested_field_metrics. The method that remains compares with a
bare >=, so both now name only ThresholdHelper and ComparisonHelper.

Also run ruff format on the calculator file, which only strips the
trailing whitespace from 9 blank docstring lines.

Closes #296
  • Loading branch information
Thanatos9404 committed Oct 15, 2026
commit ad19ac845dd22c03f151d52000f9e69abff38f52
5 changes: 1 addition & 4 deletions docs/structured_model_REFACTORING.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class StructuredModel(BaseModel):

### Legacy private methods are kept as delegating shims

Older callers (and many tests) reach for private methods on `StructuredModel` such as `_dispatch_field_comparison`, `compare_recursive`, `_calculate_list_confusion_matrix`, `_calculate_nested_field_metrics`, `_collect_enhanced_non_matches`, `_add_derived_metrics_to_result`, `_format_for_evaluator`, etc. These were **not removed** — they now exist as one-line wrappers that build the appropriate component and forward the call. They are retained for backward compatibility; new code should call the component directly.
Older callers (and many tests) reach for private methods on `StructuredModel` such as `_dispatch_field_comparison`, `compare_recursive`, `_collect_enhanced_non_matches`, `_add_derived_metrics_to_result`, `_format_for_evaluator`, etc. These were **not removed** — they now exist as one-line wrappers that build the appropriate component and forward the call. They are retained for backward compatibility; new code should call the component directly.

## Component Responsibilities

Expand Down Expand Up @@ -375,9 +375,6 @@ These methods still exist on `StructuredModel` as thin delegating shims for back
| `compare_recursive` | `ComparisonEngine.compare_recursive` |
| `compare_with` | `ComparisonEngine.compare_with` |
| `_classify_field_for_confusion_matrix`| `ConfusionMatrixCalculator.classify_field_for_confusion_matrix` |
| `_calculate_list_confusion_matrix` | `ConfusionMatrixCalculator.calculate_list_confusion_matrix` |
| `_calculate_nested_field_metrics` | `ConfusionMatrixCalculator.calculate_nested_field_metrics` |
| `_calculate_single_nested_field_metrics` | `ConfusionMatrixCalculator.calculate_single_nested_field_metrics` |
| `_add_derived_metrics_to_result` | `DerivedMetricsCalculator.add_derived_metrics_to_result` |
| `_collect_enhanced_non_matches` | `NonMatchCollector.collect_enhanced_non_matches` |
| `_format_for_evaluator` | `EvaluatorFormatHelper.format_for_evaluator` |
Expand Down
6 changes: 3 additions & 3 deletions src/stickler/algorithms/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ true positives. `ComparisonHelper.compare_unordered_lists` builds a matcher
this way on purpose and reads only `matched_pairs`. Nothing should read `tp`
from a matcher built with `0.0`.

**The threshold test here is exact.** `ThresholdHelper`, `ComparisonHelper` and
`ConfusionMatrixCalculator` accept a score up to `1e-10` under the threshold, so
a score inside that window is a TP there and an FD here.
**The threshold test here is exact.** `ThresholdHelper` and `ComparisonHelper`
accept a score up to `1e-10` under the threshold, so a score inside that window
is a TP there and an FD here.

## How the evaluator uses it

Expand Down
9 changes: 4 additions & 5 deletions src/stickler/algorithms/hungarian.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ def calculate_metrics(self, list1: Any, list2: Any) -> dict:
other convention, so the same counts read lower here than they do
as ``cm_recall`` there.

The threshold test here is a bare ``>=``. ``ThresholdHelper``,
``ComparisonHelper`` and ``ConfusionMatrixCalculator`` use a
tolerant test that accepts a score up to ``1e-10`` under the
threshold, so a score inside that window is a TP there and an FD
here.
The threshold test here is a bare ``>=``. ``ThresholdHelper`` and
``ComparisonHelper`` use a tolerant test that accepts a score up
to ``1e-10`` under the threshold, so a score inside that window is
a TP there and an FD here.

``match_threshold=0.0`` is used elsewhere as a capture all
sentinel. Every score satisfies ``>= 0.0``, so ``tp`` then counts
Expand Down
Loading
Loading