From 1f61810979063239470aaade0da1c143aa677a0b Mon Sep 17 00:00:00 2001 From: Jared Bell Date: Wed, 16 Sep 2026 20:26:24 +0000 Subject: [PATCH] Externalize and expand headline aliases Move the hard-coded ALIASES dict into resources/aliases.toml (loaded with stdlib tomllib), expand it with agencies, international bodies, and country names, and fix two correctness bugs in the naive replace(): - Whole-word matching so 'united states' no longer collapses inside 'united statesman', and 'inflation rate' no longer mangles 'inflation rates'. - Longest-phrase-first application so 'president of the united states' resolves to 'potus' before 'united states' fires. - Correct a stopword collision: 'united nations' -> 'un' was silently dropped because 'un' is a stopword; it now maps to 'unitednations'. Aliases are threaded through normalize_headline -> is_headline -> _build_headlines -> prepare_headlines and loaded in main.py. Includes unit tests and README coverage. --- README.md | 24 ++++++--- main.py | 13 ++++- resources/aliases.toml | 95 ++++++++++++++++++++++++++++++++ services/headlines.py | 20 +++---- services/normalization.py | 110 +++++++++++++++++++++----------------- tests/test_aliases.py | 109 +++++++++++++++++++++++++++++++++++++ 6 files changed, 303 insertions(+), 68 deletions(-) create mode 100644 resources/aliases.toml create mode 100644 tests/test_aliases.py diff --git a/README.md b/README.md index f6a95a4..365e045 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ question: *which stories are multiple independent sources reporting right now?* are first checked for embedded JSON (JSON-LD / Next.js SSR state) before falling back to scraping ``/`` text, associating each headline with the nearest `