From 7d00ec7925b472edb8d52390da3862f9d7e9cdfe Mon Sep 17 00:00:00 2001 From: Ritik Yadav <97098551+Ritik650@users.noreply.github.com> Date: Sun, 23 Aug 2026 12:56:21 +0530 Subject: [PATCH] fix(salary): stop dropping the dotted A.M.B.A. suffix in company-name matching (#356) The A.M.B.A. STRIP_PATTERNS regex ended in a literal dot followed by \b, but \b can't fire right after a non-word character when the next char is also non-word (space/end-of-string) - so it never matched any realistic company name. The sibling undotted 'amba' suffix stripped fine, so 'Arla Foods A.M.B.A.' and 'Arla Foods amba' normalized to different strings and scored 86 vs 100 against the same query. Made the trailing dot optional so the boundary resolves correctly. --- salary_lookup.py | 2 +- tests/test_salary_lookup.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/salary_lookup.py b/salary_lookup.py index 8020935..4d1bbcb 100644 --- a/salary_lookup.py +++ b/salary_lookup.py @@ -35,7 +35,7 @@ SPELLING_VARIANTS = { # Legal suffixes and noise to strip when matching company names STRIP_PATTERNS = [ r"\ba/s\b", r"\baps\b", r"\bi/s\b", r"\bp/s\b", r"\bk/s\b", - r"\bivs\b", r"\bamba\b", r"\ba\.m\.b\.a\.\b", + r"\bivs\b", r"\bamba\b", r"\ba\.m\.b\.a\.?\b", r"\(vg\)", r"\(.*?\)", # (VG) and other parentheticals r"\bdanmark\b", r"\bdenmark\b", r"\bscandinavia\b", r"\bnordic\b", r"\bgroup\b", r"\bholding\b", diff --git a/tests/test_salary_lookup.py b/tests/test_salary_lookup.py index 0a4dd06..77f4de9 100644 --- a/tests/test_salary_lookup.py +++ b/tests/test_salary_lookup.py @@ -102,6 +102,12 @@ class TestMatchScoreExactMatch(unittest.TestCase): def test_exact_match_after_suffix_stripping(self): self.assertEqual(match_score("Mærsk", "Mærsk A/S"), 100) + def test_exact_match_after_dotted_amba_suffix_stripping(self): + # "A.M.B.A." (dotted) is the same legal-suffix family as the + # undotted "amba" pattern above it in STRIP_PATTERNS and must + # strip just as cleanly. + self.assertEqual(match_score("Arla Foods", "Arla Foods A.M.B.A."), 100) + class TestMatchScoreSubstring(unittest.TestCase): def test_query_contained_in_entry_gives_high_score(self): @@ -332,6 +338,14 @@ class UtilityTests(unittest.TestCase): self.assertEqual(normalize("Chr. Hansen, Denmark Division"), "chrhansen") self.assertEqual(normalize("Simple Corp ApS"), "simplecorp") + def test_normalize_strips_dotted_amba_suffix_same_as_undotted(self): + # The dotted form ("A.M.B.A.") must normalize identically to the + # undotted form ("amba"), same as A/S vs ApS variants above. + self.assertEqual( + normalize("Arla Foods A.M.B.A."), normalize("Arla Foods amba") + ) + self.assertEqual(normalize("Arla Foods A.M.B.A."), "arlafoods") + def test_anglicize_replaces_danish_chars(self): self.assertEqual(anglicize("ørsted"), "orsted") self.assertEqual(anglicize("mærsk"), "maersk")