From 564408fb2098fc9a801b3693c5aba903beff91bb Mon Sep 17 00:00:00 2001 From: Alex Galarce Date: Thu, 13 Mar 2025 17:47:44 +0000 Subject: [PATCH] Merged in feature/change-1-to-n-comparison-metric (pull request #439) Refactor fuzzy matching logic to use partial token sort ratio and update matched pairs structure * Refactor fuzzy matching logic to use partial token sort ratio and update matched pairs structure * Merged main into feature/change-1-to-n-comparison-metric Approved-by: Katon Minhas --- fieldExtraction/src/testbed/one_to_n_comparison.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fieldExtraction/src/testbed/one_to_n_comparison.py b/fieldExtraction/src/testbed/one_to_n_comparison.py index 7b22af0..c311c29 100644 --- a/fieldExtraction/src/testbed/one_to_n_comparison.py +++ b/fieldExtraction/src/testbed/one_to_n_comparison.py @@ -24,7 +24,7 @@ def are_entries_similar_field_by_field(entry1: tuple, entry2: tuple, thresholds= field2_str = str(field2).lower() # Calculate similarity for this field - similarity = fuzz.token_sort_ratio(field1_str, field2_str) + similarity = fuzz.partial_token_sort_ratio(field1_str, field2_str) # If any field fails the threshold check, entries are not similar if similarity < thresholds[i]: @@ -111,7 +111,7 @@ def evaluate_one_to_n_fields_fuzzy_matching_field_by_field( "true_positives": total_true_positives, "false_positives": total_false_positives, "false_negatives": total_false_negatives, - "matched_labels": {contract_id: [labeled_entries[i] for i in matched_labels] for contract_id in contract_ids}, + "matched_pairs": {contract_id: [{"label": labeled_entries[i], "prediction": predicted_entries[j]} for i, j in zip(matched_labels, matched_predictions)] for contract_id in contract_ids}, "unmatched_labels": {contract_id: [labeled_entries[i] for i in range(len(labeled_entries)) if i not in matched_labels] for contract_id in contract_ids}, "unmatched_predictions": {contract_id: [predicted_entries[j] for j in range(len(predicted_entries)) if j not in matched_predictions] for contract_id in contract_ids} } \ No newline at end of file