Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: Parse Australian Street Addresses

Looking for a quick and dirty way to parse Australian street addresses into its parts:
3A/45 Jindabyne Rd, Oakleigh, VIC 3166

should split into:
"3A", 45, "Jindabyne Rd" "Oakleigh", "VIC", 3166

Suburb names can have multiple words, as can street names.


See: Parse A Steet Address into components

Has to be in Java, cannot make http requests (e.g. to web APIs).


EDIT: Assume that format specified is always followed. I have no issue with spitting incorrectly formatted strings back at the user with a message telling them to follow the format (which I've described above).

like image 223
bguiz Avatar asked Jul 12 '26 21:07

bguiz


1 Answers

Honestly, you're setting yourself a rather Sisyphean challenge here, and I'm not sure if it's worthwhile. Unless your data comes from a known source, with a very well specified format, you're going to get data that's completely useless. If you're dealing with free text, people screw up their addresses in ways you wouldn't believe.

Do you really want to try (yourself) to parse every possible combination of Richmond, Victoria, 3121 and Richmond 3121 VIC and Richmond VIC, 3121 etc? And that's just suburb granularity!

Addresses are even worse. Sure, most people would put 7/21 Smith St for a unit, or 29-33 Jones St for a location spanning multiple street numbers, but people aren't consistent. Is 1-5 Brown St unit 1 at number 5, or a location spanning #1 to #5 on that street? Is 7A a separate subdivided street address, or Unit A at #7?

Address matching is not a simple problem and if your data set is end-user-entered free text, I seriously wouldn't bother unless you have a trivial amount of data or don't care about accuracy that much (or, alternatively, have a lot of time for manual cleanups). If not, hand it off to a piece of software that does this work for you.

Australia Post have something called the Postal Address File (PAF) which contains every valid delivery location in Australia. There are a number of software libraries which will do the parsing + matching for you, and either give you a definitive answer (including all the individual address components, as you're after) or provide a list of potential matches for you to choose from if the address is non-existent or ambiguous. One example I'm aware of is QAS Batch (not affiliated with them in any way, evaluated their software in the past but didn't end up using it) but that's just one example; there's a list of others accessible through the PAF website.

Cannot recommend strongly enough that you don't waste your time on this unless it's at a trivial scale.

If it is, hey, yeah, regex.

like image 115
Cowan Avatar answered Jul 14 '26 10:07

Cowan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!