fix(auditing): normalize address punctuation + category synonyms

- _normalize_address: drop commas, map 'suite'->'ste' so '3460 Robin Ln,
  Ste 4' == '3460 Robin Ln Ste 4' (no false address mismatch)
- check_category_alignment: add _CATEGORY_SYNONYMS map so 'beauty salon' /
  'beauty and spa' / 'beauty & spa' collapse; real drift (e.g. 'medical
  spa', 'barber shop') still fires
- Phoenix proof run drops from 4 findings to 2 (removes 2 false positives)
This commit is contained in:
Leonard (VeriPath Agent)
2026-08-14 21:02:33 +00:00
parent 94d5607819
commit 6583c85871
+29 -2
View File
@@ -63,12 +63,14 @@ def _normalize_phone(phone):
def _normalize_address(addr):
"""Lowercase, strip extra whitespace, remove suite abbrev variances."""
"""Lowercase, strip extra whitespace, remove suite abbrev variances, drop commas."""
if not addr:
return ""
s = re.sub(r'[\U000E0000-\U000EFFFF]', '', addr or '')
s = re.sub(r'\s+', ' ', s.strip().lower())
s = re.sub(r'\bst[e]*\.?\b', 'ste', s)
s = re.sub(r'\bsuite\b', 'ste', s)
s = s.replace(',', '') # ponytail: comma is pure formatting, not a material diff
return s
@@ -393,6 +395,31 @@ def check_review_text_quality(contract):
return findings
# ponytail: small explicit synonym map; extend when new variants appear in the wild
_CATEGORY_SYNONYMS = {
"beauty salon": "beauty salon",
"beauty and spa": "beauty salon",
"beauty & spa": "beauty salon",
"beauty & spa": "beauty salon",
"salon and spa": "beauty salon",
"hair salon": "hair salon",
"hair & beauty salon": "hair salon",
"hair and beauty salon": "hair salon",
"day spa": "day spa",
"spa": "spa",
"medical spa": "medical spa",
"barber shop": "barber shop",
"barbershop": "barber shop",
}
def _normalize_category(cat):
if not cat:
return ""
c = re.sub(r'\s+', ' ', cat.strip().lower()).replace('&', '&')
return _CATEGORY_SYNONYMS.get(c, c)
def check_category_alignment(contract):
"""Category consistency and fragmentation across surfaces."""
findings = []
@@ -403,7 +430,7 @@ def check_category_alignment(contract):
data = _safe_get(contract, "sources", src_data, default={})
cat = data.get('category')
if cat:
categories[src_name] = cat.lower().strip()
categories[src_name] = _normalize_category(cat)
if len(categories) < 2:
return findings