Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Howdy, I have looked around for a module or code to parse a postal address and all I can find is email parsing and Lingua-EN-AddressParse-1.12 . The single review for this module is not exactly glorious. Any pointers to existing code that would parse postal addresses? Thanks

Replies are listed 'Best First'.
Re: Parsing an Mailing Addresss
by shemp (Deacon) on Aug 03, 2004 at 14:49 UTC
    I have worked with cleaning up municipal public record data in the US (wisconsin) for a number of years, and parsing addresses is an incredibly complex subject. So as the previous post mentions, you need to be more specific.

    I guess you have to determine what you need out of the addresses. Are you looking to CASS certify them, or do some other sort of checking? There are many possible goals.

    If you're not sure, and you're dealing with addresses in the US, you might want to check out www.usps.gov which contains extensive documentation on US postal standards, which will help you with what is valid address information.

    As a general parsing technique, if you split an address line on whitespace, any non alphanumeric characters, and any number-letter (or letter-number) boundary, it is much easier to determine what parts represent street numbers, directions, street types, units, etc.

Re: Parsing an Mailing Addresss
by mifflin (Curate) on Aug 03, 2004 at 15:16 UTC
    I number of years ago I was searching for just such a tool. What we ended up using was a product called the Postalsoft ACE library from Firstlogic. It is a C library and a database (about 650 MB). Data updates come every 2 months which you must apply or you cannot get CASS certified.
    With this tool you can correct and encode any US address (they also have international and canadian libraries). Since this library is in C I was forced to build an xs extention. An example of the interface is...
    use ACE; $ah = ACE->open("/u02/postalsoft/ace.cfg"); $ah->set_input_fields('discrete'); $ah->want_all_components(); $addr = '101 morris'; $city = 'sbastopul'; $state = 'CA'; $zip = ''; %a = $ah->find($addr, $city, $state, $zip); for my $key (qw(ADDRESS CITY ZIP ZIP4 COUNTY COUNTYNAME)) { print "$key = $a{$key}\n" if $a{$key}; } $ah->close();
    This will produce output like ...
    ADDRESS = 101 MORRIS ST
    CITY = SEBASTOPOL
    ZIP = 95472
    ZIP4 = 3858
    COUNTY = 097
    COUNTYNAME = SONOMA
    
    Note that the software fixed the street name, corrected the spelling of the city and added zip4, county and countyname fields.

    I have never posted this code to CPAN because I've never looked into the legal issues. Postalsoft is not free. Our license fees are several thousand dollars a year. If you are interested in more details you can message me.
Re: Parsing an Mailing Addresss
by shemp (Deacon) on Aug 03, 2004 at 16:11 UTC
    At my job, we are currently using a product called 'Correct Address' (how creative), from a company called Intelligent Search Technology Ltd.

    It has a very rudimentary perl interface, which a co-worker of mine has written a decent layer on top of. I believe that he is refining it as i type. We've been using it for about 2 years now, and it serves its purpose.

    My only other experience with address correction software is a product called AccuMail from a company called Datasoft. They did not have a perl interface when we used it, and their support was less than great.

    A word of warning regarding any of these products that i've seen. They assume that you have pretty clean addresses to begin with, if your addresses have issues, you'll need to write your own code to get your addresses into a halfway decent format, before the CASS software will handle the addresses properly.

    Again it all depends on what you begin with, and what you want to do with it.

Re: Parsing an Mailing Addresss
by gellyfish (Monsignor) on Aug 03, 2004 at 13:40 UTC

    I think you are going to have to be more explicit about what you mean by 'parsing a postal address' and how the module does not fit your requirement before we can give an answer. Some idea of what you would like the address parsed into would be very helpful.

    /J\