Eric R.
Eric R.

Reputation: 983

How do I do address normalizations?

I'm interacting with two APIs, which return addresses that are formatted quite differently. One returns an address like "6 Avenue" and another returns "6 Ave."

I explored using the Normalic gem, but for some reason many of my addresses are returned malformed or blank: "6 Avenue" gets returned as "Ave.".

I also tried GeoCoder, but each API such as Google and Yahoo have set quotas. After a few hours of testing my app in development, these quotas expire. This obviously won't do in production.

It would be great if there was a library that let me do something like evaluate "6 Ave." == "6 Avenue".

Upvotes: 3

Views: 1529

Answers (2)

Dave Guarino
Dave Guarino

Reputation: 509

The Ruby StreetAddress gem should take care of this for you: https://rubygems.org/gems/StreetAddress

Here's some example usage for your case:

pry(main)> StreetAddress::US.parse("42 6 Ave., Washington, DC")
=> 42 6 Ave, Washington, DC
pry(main)> StreetAddress::US.parse("42 6 Avenue, Washington, DC")
=> 42 6 Ave, Washington, DC

So if you run both of your API addresses through the parse method, it should standardize both for you, and free up your life for more reflection, biking, and pizza consumption.

Upvotes: 1

Larry K
Larry K

Reputation: 49114

For US addresses, the USPS offers an address api. My understanding is that there is no charge, but your purpose needs to be for use with an e commerce website to validate addesses as they're entered.

For cleaning databases, the USPS often sends you to one of their (expensive) service providers for mailers.

Upvotes: 4

Related Questions