Pull addresses out of emails and tickets
Customers write the address in the middle of a sentence. To route a ticket or check a delivery you need that address as a point, and the ticket text should not go to a cloud service to get it.
New Take addresses in Command line Websites, help desks Logistics, field work
What you have
A CSV export of tickets with the text in one column (or a single text file with --text). The last ticket has no address:
ticket,body 101,"Please send the replacement router to 233 S Wacker Dr, Chicago, IL 60606 before Friday." 102,"Delivery failed. The right address is 1600 Pennsylvania Ave NW, Washington, DC 20500, not the one on file." 103,"Can we meet at the office? 350 Fifth Avenue, New York, NY 10118, 34th floor." 104,"No address in this one, just a question about my order."
Steps
1. Find and geocode the addresses in the body column; one JSON line per address found:
$ gridpin extract usa.bin --input tickets.csv --column body > found.jsonl
2. Read the fields you need, here with jq:
$ jq -c '{row, text, level, street: .hit.street, number: .hit.housenumber, lat: .hit.lat, lon: .hit.lon}' found.jsonl
{"row":0,"text":"233 S Wacker Dr, Chicago, IL 60606","level":"house","street":"South WACKER Drive","number":"233","lat":41.878658,"lon":-87.6358684}
{"row":1,"text":"1600 Pennsylvania Ave NW, Washington, DC 20500","level":"house","street":"PENNSYLVANIA Avenue Northwest","number":"1600","lat":38.8976751,"lon":-77.036547}
{"row":2,"text":"350 Fifth Avenue, New York, NY 10118, 34th floor","level":"house","street":"5 Ave","number":"350","lat":40.7488827,"lon":-73.9860301}
What you get
row is the row of the input (from 0), text the span as written, with start and end in the full line; hit is the usual answer. A ticket without an address writes nothing. --verify also reports a span with a number the file does not have, with a reason.
Why it works
The text is scanned for spans that look like an address of the country (a number, a street word, a town or a postcode), each span is geocoded, and only spans the file confirms are written. The span keeps what the person typed, so 34th floor stays with the third address.
Limits
- One country file per run: an address of another country in the text is not found.
- An address without a number, such as
the corner of Main and 5th, is not taken. - It is slow on a large country file: on the United States file a few tickets take tens of seconds.
All its keys: command reference. The function: addresses in free text.