datamade / usaddress

:us: a python library for parsing unstructured United States address strings into address components
https://parserator.datamade.us/usaddress
MIT License
1.5k stars 302 forks source link

ERROR: Unable to tag this string because more than one area of the string has the same label #359

Open philiporlando opened 6 months ago

philiporlando commented 6 months ago

I'm encountering tag errors with the following address: "38350 40TH ST EAST 100 PALMDALE CA 93552". Both the 100 and 40TH strings have the StreetName tag...

import usaddress

address = "38350 40TH ST EAST 100 PALMDALE CA 93552"

usaddress.tag(address)

# Traceback (most recent call last):
#   File "/home/user/usaddress_parse_error/usaddress_parse_error.py", line 5, in <module>
#     usaddress.tag(address)
#   File "/home/user/.cache/pypoetry/virtualenvs/usaddress-parse-error-aadNbsKj-py3.10/lib/python3.10/site-packages/usaddress/__init__.py", line 177, in tag
#     raise RepeatedLabelError(address_string, parse(address_string),
# usaddress.RepeatedLabelError: 
# ERROR: Unable to tag this string because more than one area of the string has the same label

# ORIGINAL STRING:  38350 40TH ST EAST 100 PALMDALE CA 93552
# PARSED TOKENS:    [('38350', 'AddressNumber'), ('40TH', 'StreetName'), ('ST', 'StreetNamePostType'), ('EAST', 'StreetNamePreDirectional'), ('100', 'StreetName'), ('PALMDALE', 'PlaceName'), ('CA', 'StateName'), ('93552', 'ZipCode')]
# UNCERTAIN LABEL:  StreetName

# When this error is raised, it's likely that either (1) the string is not a valid person/corporation name or (2) some tokens were labeled incorrectly

# To report an error in labeling a valid name, open an issue at https://github.com/datamade/usaddress/issues/new - it'll help us continue to improve probablepeople!

# For more information, see the documentation at https://usaddress.readthedocs.io/

However, in this case, the 100 corresponds to the occupancy identifier, but the input address is missing additional details like STE 100 or #100.

Are there any opportunities to update the tagging logic to discern between street names and occupancy identifiers in the absence of a # or STE prefix?

import usaddress

address = "38350 40TH ST EAST #100 PALMDALE CA 93552"

usaddress.tag(address)

# (OrderedDict([('AddressNumber', '38350'), ('StreetName', '40TH'), ('StreetNamePostType', 'ST'), ('StreetNamePostDirectional', 'EAST'), ('OccupancyIdentifier', '# 100'), ('PlaceName', 'PALMDALE'), ('StateName', 'CA'), ('ZipCode', '93552')]), 'Street Address')

The scourgify.normalize_address_record() utility that I'm using is also breaking because of the errors related to usaddress.tag():

from scourgify import normalize_address_record

address = "38350 40TH ST EAST 100 PALMDALE CA 93552"

normalize_address_record(address)

# Traceback (most recent call last):
#   File "/home/user/usaddress_parse_error/usaddress_parse_error.py", line 5, in <module>
#     normalize_address_record(address)
#   File "/home/user/.cache/pypoetry/virtualenvs/usaddress-parse-error-aadNbsKj-py3.10/lib/python3.10/site-packages/scourgify/normalize.py", line 159, in normalize_address_record
#     return normalize_addr_str(
#   File "/home/user/.cache/pypoetry/virtualenvs/usaddress-parse-error-aadNbsKj-py3.10/lib/python3.10/site-packages/scourgify/normalize.py", line 267, in normalize_addr_str
#     raise UnParseableAddressError(None, None, addr_rec)
# scourgify.exceptions.UnParseableAddressError: UNPARSEABLE ADDRESS: Unable to break this address into its component parts, OrderedDict([('address_line_1', '38350 40TH ST EAST 100 PALMDALE CA 93552'), ('address_line_2', None), ('city', None), ('state', None), ('postal_code', None)])

I originally opened this issue on the usaddress-scourgify repo, but we have determined that the root cause of the issue is related to usaddress.tag() and would prefer to fix upstream.

Please let me know if you have any questions or need any additional details. Thank you!