4 ms·
I used it for street address matching. I've got a DB with sales tax data for about half the US states, and an API for looking up tax given a street address. I
by tzs 5y ago
I used it for street address matching.
I've got a DB with sales tax data for about half the US states, and an API for looking up tax given a street address. I wanted to see if it was feasible to handle tax rate lookup ourselves instead of using a third party service.
Suppose the database contains the address "123 NW Maple Road, Hooterville, MI, 65026".
There are all kinds of variations in what people will give for that address. Some people might enter "Rd" instead of "Road". Some might might get the qualifier wrong and enter "street" or "avenue" instead of "road" (or abbreviations of "street" or "avenue"). Sometimes people put the directional prefix in the wrong place, so it becomes "Maple Road NW" instead of "NW Maple Road".
I found that people always get the street number right and usually get the zip code right.
What I would do then is take the address given, and lookup in the database all addresses that have that street number and zip code. For each found address, put it in the usual form (<number> <directional_prefixes> <street_name> <qualifiers> <directional_postfixes>, <city>, <state>, <zip>), and compute the Levenshtein distance between that and the input.
Whichever gave the lowest Levenshtein distance is the one I returned the tax rate for. I found that this worked quite well--way better than I expected it to.
Sometimes there would be more than one address with minimal distance, but it almost always turned out in that case that they all had the same tax rate.
Examples of where this would fail would be street names like "Martin Luther King". People will often write that as "MLK". All you need then is to have an "Elk" street in the same city and zip code, that has an address with the same number, and there isn't much hope of picking the right one.