Issue parsing US address
AmericanY opened this issue · 0 comments
AmericanY commented
7800 Mockingbird Ln #119 N. Richland Hills, TX 76180
7601 Curry Road Apt 17849 lakeview drive Houston TX 77093
My Code is below:
import usaddress
tag_mapping = {
'Recipient': 'recipient',
'AddressNumber': 'address1',
'AddressNumberPrefix': 'address1',
'AddressNumberSuffix': 'address1',
'StreetName': 'address1',
'StreetNamePreDirectional': 'address1',
'StreetNamePreModifier': 'address1',
'StreetNamePreType': 'address1',
'StreetNamePostDirectional': 'address1',
'StreetNamePostModifier': 'address1',
'StreetNamePostType': 'address1',
'CornerOf': 'address1',
'IntersectionSeparator': 'address1',
'LandmarkName': 'address1',
'USPSBoxGroupID': 'address1',
'USPSBoxGroupType': 'address1',
'USPSBoxID': 'address1',
'USPSBoxType': 'address1',
'BuildingName': 'address2',
'OccupancyType': 'address2',
'OccupancyIdentifier': 'address2',
'SubaddressIdentifier': 'address2',
'SubaddressType': 'address2',
'PlaceName': 'city',
'StateName': 'state',
'ZipCode': 'zip_code',
}
ks = ['address1', 'address2', 'city', 'state', 'zip_code']
def format_address(add):
fadd = usaddress.tag(add.replace('&', ''), tag_mapping=tag_mapping)
res = [fadd[0].get(i, '').title() for i in ks]
res[3] = res[3].upper()
return res
print(usaddress.tag('7601 Curry Road Apt 17849 lakeview drive Houston TX 77093',
tag_mapping=tag_mapping))
I keep getting the following Exception:
"""
Traceback (most recent call last):
File "c:\Users\AmericaN\Desktop\Lab\opa.py", line 42, in <module>
print(usaddress.tag('7800 Mockingbird Ln #119 N. Richland Hills, TX 76180',
File "C:\Users\AmericaN\Desktop\Lab\MyEnv\lib\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: 7800 Mockingbird Ln #119 N. Richland Hills, TX 76180
PARSED TOKENS: [('7800', 'AddressNumber'), ('Mockingbird', 'StreetName'), ('Ln', 'StreetNamePostType'), ('#', 'OccupancyIdentifier'), ('119', 'AddressNumber'), ('N.', 'StreetNamePreDirectional'), ('Richland', 'StreetName'), ('Hills,', 'StreetNamePostType'), ('TX', 'StateName'), ('76180', 'ZipCode')]
UNCERTAIN LABEL: address1
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/
"""
How can i solve that ?