fix(parser): use max of both attribute counts in similarity scoring denominator

Candidates with fewer attributes than the original got inflated scores because the denominator counted candidate attributes only, while the extra-attributes penalty direction worked as intended. Using `max()` on both counts fixes the inflation while keeping the penalty.

Closes #322
This commit is contained in:
Karim shoair
2026-06-07 15:51:10 +03:00
parent f7d1e338e0
commit 9c0c857245
2 changed files with 34 additions and 7 deletions
+3 -1
View File
@@ -991,7 +991,9 @@ class Selector(SelectorsGeneration):
SequenceMatcher(None, v, candidate_attributes.get(k, "")).ratio()
for k, v in original_attributes.items()
)
checks += len(candidate_attributes)
# Using `max` so candidates with extra attributes are penalized and candidates
# with fewer attributes don't get inflated scores from a smaller denominator
checks += max(len(original_attributes), len(candidate_attributes))
else:
if not candidate_attributes:
# Both don't have attributes, this must mean something