MCPcopy Create free account
hub / github.com/SpecterOps/DeepPass2 / _areEqualOverlapStrings

Function _areEqualOverlapStrings

test/testDeeppass2.py:56–93  ·  view source on GitHub ↗
(y_true, y_pred, min_overlap=0.5, string_min_ratio=0.5)

Source from the content-addressed store, hash-verified

54
55
56def _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
96def _calculate_accuracy(

Callers 1

_calculate_accuracyFunction · 0.85

Calls 1

_string_overlap_ratioFunction · 0.85

Tested by

no test coverage detected