Skip to content

Strip a trailing city, state and ZIP before parsing an address - #170

Merged
jinskeep-morpc merged 1 commit into
mainfrom
fix/postal-tail-parsing
Aug 4, 2026
Merged

Strip a trailing city, state and ZIP before parsing an address#170
jinskeep-morpc merged 1 commit into
mainfrom
fix/postal-tail-parsing

Conversation

@jinskeep-morpc

Copy link
Copy Markdown
Collaborator

Addresses the first and largest of the three defects in #168. The two route-form defects there are untouched and the issue stays open for them.

The defect

Some registries publish a full postal address in the field others use for the street line alone. ODRC writes 1990 Harmon Avenue, Columbus, OH 43223 where DODD writes 1990 Harmon Avenue. parse_address replaces commas with spaces, so the whole tail became part of the street name and took the street type with it:

>>> morpc.parse_address('1990 Harmon Avenue, Columbus, OH 43223')   # before
{'streetaddr': '1990', 'streetname': 'HARMON AVENUE COLUMBUS OH 43223', 'streettype': None, ...}

>>> morpc.parse_address('1990 Harmon Avenue, Columbus, OH 43223')   # after
{'streetaddr': '1990', 'streetname': 'HARMON', 'streettype': 'AVE', ...}

What is and is not treated as a tail

The tail must end in the state, optionally followed by a ZIP and a parenthetical note, before anything is removed. A comma alone is not enough to act on, because in this data a comma often separates something that belongs to the address:

Input Result
1990 Harmon Avenue, Columbus, OH 43223 stripped
5900 BIS Rd SW, Lancaster, Ohio 43130 stripped — spelled-out state
16197 State Route 104, Chillicothe, OH 45601, (visitor entrance) stripped — trailing note
1234 Main St, OH 43215 stripped — no city segment
123 Main St, Ohio City, OH 45874 stripped — city named for the state
1359 State Route #38, Southeast kept — a directional, not a city
4410,4412,4416,4418,4424,4426 MORSE RD kept — commas separate house numbers
1990 Harmon Avenue, Columbus kept — a city with no state does not confirm a tail
123 Ohio Ave kept — a street named for the state

Ohio only, which is the region this data covers.

Effect

Against the 359 DODD, CMS and ODRC facility addresses used to validate morpc/morpc-addresspoints-standardize#7:

Baseline After #169 After this
Overall 320 / 359 (89.1%) 324 / 359 (90.3%) 330 / 359 (91.9%)
ODRC 68.5% 74.1% 85.2%

The number_name and route_number tiers are unchanged at 8 and 4; the six new matches land in exact (277 → 281) and components (35 → 37), so nothing previously matched was displaced.

Tests

Four added: the headline case, the three tail variants, the four inputs that must be left alone, and a street named for the state. All 40 in test_geocode.py pass. The test_utils.py failures noted in #169 remain, unrelated and pre-existing on main.

Two pre-existing quirks found while testing, not fixed here

Both are visible in the "kept" rows above and predate this change:

  1. 1359 State Route #38, Southeast parses to streetname='STATE ROUTE', unitnum='38 SOUTHEAST' — the # in Route #38 is read as a unit designator rather than a route number, so the route never reaches CONST_ROUTE_PREFIX_ABBREV.
  2. 4410,4412,4416,4418,4424,4426 MORSE RD parses to streetname='4412 4416 4418 4424 4426 MORSE'. normalize_house_number documents handling the multi-number case, but commas are flattened before it sees the joined form, so only the first number is taken and the rest leak into the name.

Neither is in scope for #168. Happy to file them separately if they are worth fixing.

🤖 Generated with Claude Code

Some registries publish a full postal address in the field others use for the
street line alone: ODRC writes "1990 Harmon Avenue, Columbus, OH 43223" where
DODD writes "1990 Harmon Avenue". parse_address replaces commas with spaces, so
the whole tail was read as part of the street name -- "HARMON AVENUE COLUMBUS
OH 43223" -- taking the street type down with it. None of those addresses could
match anything.

The tail must end in the state, optionally followed by a ZIP and a parenthetical
note, before anything is removed. A comma alone is not enough to act on: DODD
writes "1359 State Route #38, Southeast", where what follows the comma belongs
to the address, and "4410,4412,4416 MORSE RD", where the commas separate house
numbers. Both are left untouched, as is a street named for the state.

Against the 359 DODD, CMS and ODRC facility addresses used to validate
morpc/morpc-addresspoints-standardize#7, this takes matching from 324/359
(90.3%) to 330/359 (91.9%), and ODRC from 74.1% to 85.2%. The number_name and
route_number tiers are unchanged, so nothing previously matched was displaced.

Addresses the first of the three defects in #168; the OH-104 and C.R. 32 route
forms are untouched and that issue stays open for them.

Refs #168
@jinskeep-morpc
jinskeep-morpc merged commit f0b8230 into main Aug 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant