# scope the comparison set to the candidate's own domain references = [t for t in reference_pool if t.domain == candidate.source_domain] prevented = sum(1 for t in references if rule_matches(candidate, t) and not t.success) recall = prevented / len([t for t in references if not t.success])