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
This commit is contained in:
Alex Galarce
2025-03-13 17:47:44 +00:00
parent 6283f37f01
commit 564408fb20
@@ -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}
}