(y_true, y_pred, min_overlap=0.5, string_min_ratio=0.5)
| 54 | |
| 55 | |
| 56 | def _areEqualOverlapStrings(y_true, y_pred, min_overlap=0.5, string_min_ratio=0.5): |
| 57 | if not y_true and not y_pred: |
| 58 | return True |
| 59 | |
| 60 | if not y_true or not y_pred: |
| 61 | return False |
| 62 | |
| 63 | # Find matches between strings in the lists |
| 64 | matches = 0 |
| 65 | used_pred_indices = set() |
| 66 | |
| 67 | for true_item in y_true: |
| 68 | best_match_idx = None |
| 69 | best_similarity = 0 |
| 70 | |
| 71 | for pred_idx, pred_item in enumerate(y_pred): |
| 72 | if pred_idx in used_pred_indices: |
| 73 | continue |
| 74 | |
| 75 | # Check if strings are similar enough |
| 76 | if _string_overlap_ratio(true_item, pred_item, string_min_ratio): |
| 77 | similarity = SequenceMatcher( |
| 78 | None, true_item.lower(), pred_item.lower() |
| 79 | ).ratio() |
| 80 | |
| 81 | if similarity > best_similarity: |
| 82 | best_similarity = similarity |
| 83 | best_match_idx = pred_idx |
| 84 | |
| 85 | if best_match_idx is not None: |
| 86 | matches += 1 |
| 87 | used_pred_indices.add(best_match_idx) |
| 88 | |
| 89 | # Calculate overall overlap |
| 90 | longer_length = max(len(y_true), len(y_pred)) |
| 91 | overlap_ratio = matches / longer_length |
| 92 | |
| 93 | return overlap_ratio >= min_overlap |
| 94 | |
| 95 | |
| 96 | def _calculate_accuracy( |
no test coverage detected