Merge pull request 'correlator: a radio code is not a location' (#182) from fix/radio-code-location into main
This commit was merged in pull request #182.
This commit is contained in:
@@ -343,9 +343,21 @@ def clean_location(value) -> Optional[str]:
|
||||
s = str(value).strip()
|
||||
if not s or not _LOCATION_WORD_RE.search(s):
|
||||
return None
|
||||
if _RADIO_CODE_RE.match(s):
|
||||
return None
|
||||
return s
|
||||
|
||||
|
||||
# Status/disposition codes the extractor sometimes returns as a location:
|
||||
# "96 times 5" (a disposition code read aloud) titled a 09-22 replay stop
|
||||
# "Traffic Stop at 96 times 5" (server-26#170); "10-8", "signal 99", "code 4"
|
||||
# are the same shape.
|
||||
_RADIO_CODE_RE = re.compile(
|
||||
r"^\s*(?:\d{1,3}\s*(?:times|x)\s*\d{1,3}|10[\s-]?\d{1,3}|(?:signal|code|condition)\s+\d{1,3})\s*$",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
|
||||
|
||||
def location_is_unit(location, units) -> bool:
|
||||
"""
|
||||
True when a location label is really one of the incident's own unit
|
||||
|
||||
@@ -154,3 +154,10 @@ def test_plate_read_on_a_patrol_channel_is_a_stop():
|
||||
# not on rail/bridge channels, and not without digits
|
||||
assert b("Frank David Boy 4514", [], None, "routine", "MTA Bridges and Tunnels - Whitestone") == ([], None, "routine")
|
||||
assert b("Charlie, David, go ahead.", [], None, "routine", ch) == ([], None, "routine")
|
||||
|
||||
|
||||
def test_radio_codes_are_not_locations():
|
||||
for junk in ("96 times 5", "96 x 1", "10-8", "Signal 99", "code 4"):
|
||||
assert ic.clean_location(junk) is None, junk
|
||||
for place in ("West Main Street", "Route 9", "96 Main Street", "Exit 17 southbound"):
|
||||
assert ic.clean_location(place) == place, place
|
||||
|
||||
Reference in New Issue
Block a user