A Libpostal NIF for Erlang & Elixir
Postie is a NIF for Erlang & Elixir that allows you to use libpostal's natural language processing algorithm to normalise and parse physical addresses. This is useful for matching or filtering addresses in your system.
NIFs (Native Implemented Functions) are one way of integrating external code into Erlang or Elixir. Postie uses the libpostal C bindings to provide an interface you can use in your projects just as if it was a regular Elixir library.
NIFs have some pretty hefty downsides though - if something goes wrong with them they can take down your entire erlang VM (!), and they can negatively effect the performance of your VM's scheduler. You can find out more about that in the bitwise project.
If available in Hex, the package can be installed as:
-
Add postie to your list of dependencies in
mix.exs
:def deps do [{:postie, "~> 0.0.1"}] end
-
Ensure postie is started before your application:
def application do [applications: [:postie]] end
To parse an an address:
iex(1)> Postie.parse_address("The Book Club 100-106 Leonard St Shoreditch London EC2A 4RH, United Kingdom")
[house: "the book club", house_number: "100-106", road: "leonard st",
suburb: "shoreditch", city: "london", postcode: "ec2a 4rh",
country: "united kingdom"]
To expand an address:
iex(3)> Postie.expand_address("Quatre vingt douze R. de l'Église")
["92 rue de l'eglise", "92 r de l'eglise", "92 rue de l eglise",
"92 rue de 50 eglise", "92 r de l eglise", "92 r de 50 eglise"]