From 3cbdc6bf30617959f94987ff82b4881e29f966b0 Mon Sep 17 00:00:00 2001 From: michplunkett <5885605+michplunkett@users.noreply.github.com> Date: Sat, 17 Feb 2024 15:23:17 -0600 Subject: [PATCH] Update address_parser.py --- incident_scraper/models/address_parser.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/incident_scraper/models/address_parser.py b/incident_scraper/models/address_parser.py index 20f274b..2b73d2e 100644 --- a/incident_scraper/models/address_parser.py +++ b/incident_scraper/models/address_parser.py @@ -8,6 +8,7 @@ class AddressParser: """ _instance = None + ORDINALS_REGEX = r"E\. (\d{2})[a-z]{2} \w+" def __new__(cls): if cls._instance is None: @@ -189,9 +190,7 @@ def _correct_replacements(address: str) -> str: return address def process_at_and_streets(self, address: str) -> str: - ordinals = list( - map(int, re.findall(r"E\. (\d{2})[a-z]{2} \w+", address)) - ) + ordinals = list(map(int, re.findall(self.ORDINALS_REGEX, address))) non_ordinal_streets = [ s for s in self.street_corrections_final if s in address ] @@ -205,9 +204,7 @@ def process_at_and_streets(self, address: str) -> str: def process_between_streets(self, address) -> [str]: and_cnt = len([s for s in address.split() if s == "and"]) - ordinals = list( - map(int, re.findall(r"E\. (\d{2})[a-z]{2} \w+", address)) - ) + ordinals = list(map(int, re.findall(self.ORDINALS_REGEX, address))) ordinals.sort() non_ordinal_streets = [ s for s in self.street_corrections_final if s in address