fix(iace): prioritize zone-specific matches in greedy assignment

Sort matches by specificity first (zone overlap), then by score.
Prevents generic matches from consuming specific Engine patterns
that should match more specific GT entries.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Benjamin Admin
2026-05-15 09:45:08 +02:00
parent 659c0505f8
commit c060ac222a
@@ -111,8 +111,17 @@ func CompareBenchmark(gt *GroundTruth, hazards []Hazard, mitigations []Mitigatio
} }
} }
// Greedy best-first 1:1 assignment // Greedy assignment: sort by score, but prioritize high-specificity matches
sort.Slice(pairs, func(a, b int) bool { return pairs[a].score > pairs[b].score }) // (matches where both category AND zone overlap) over generic ones
sort.Slice(pairs, func(a, b int) bool {
// First: prioritize matches with zone overlap (more specific)
aHasZone := pairs[a].reason != "" && (strings.Contains(pairs[a].reason, "Zone") || strings.Contains(pairs[a].reason, "Keywords+Zone"))
bHasZone := pairs[b].reason != "" && (strings.Contains(pairs[b].reason, "Zone") || strings.Contains(pairs[b].reason, "Keywords+Zone"))
if aHasZone != bHasZone {
return aHasZone
}
return pairs[a].score > pairs[b].score
})
usedGT := make(map[int]bool) usedGT := make(map[int]bool)
usedEng := make(map[int]bool) usedEng := make(map[int]bool)
var matched []HazardMatchPair var matched []HazardMatchPair