Skip to content

zehengl/ez-address-parser

Repository files navigation

logo

ez-address-parser

pytest coding_style PyPI - License PyPI - Python Version PyPI - Wheel Downloads GitHub Pages

A parser for Canadian postal addresses

Install

From PyPi

pip install ez-address-parser

From GitHub

pip install git+https://github.com/zehengl/ez-address-parser.git

Usage

Command Line

python -m ez_address_parser --address <some-address>

Code (with pretrained model)

from ez_address_parser import AddressParser

ap = AddressParser()

address = input("Address: ")
result = ap.parse(address)
for token, label in result:
    print(f"{token:20s} -> {label}")

Code (without pretrained model)

from ez_address_parser import AddressParser

ap = AddressParser(use_pretrained=False)

data = [
    [
        ('123', 'StreetNumber'),
        ('Main', 'StreetName'),
        ('St', 'StreetType'),
        ('E', 'StreetDirection')
    ],
    ...
] # list of list of (<token>, <label>) tuple

ap.train(data)

address = input("Address: ")
result = ap.parse(address)
for token, label in result:
    print(f"{token:20s} -> {label}")

Credits