Localize.Address.Nif (Localize.Address v1.0.0)

Copy Markdown View Source

NIF interface to the libpostal address parsing library.

This module provides NIF bindings for parsing unstructured address strings into labeled components using libpostal's machine-learning models. The NIF is always compiled and loaded as a required dependency.

Requires the libpostal C library to be installed on the system. On macOS: brew install libpostal.

Summary

Functions

Returns whether the NIF backend is available.

Parses an address string into labeled components.

Functions

available?()

@spec available?() :: boolean()

Returns whether the NIF backend is available.

Returns

  • true if the NIF shared library was loaded successfully.

  • false if the NIF is not compiled or libpostal is missing.

Examples

iex> is_boolean(Localize.Address.Nif.available?())
true

parse(address_string, language)

@spec parse(String.t(), String.t()) ::
  {:ok, [{String.t(), String.t()}]} | {:error, String.t()}

Parses an address string into labeled components.

Arguments

  • address_string is the unstructured address string to parse.

  • language is an optional language hint (ISO 639-1 code) or empty string for automatic detection.

Returns

  • {:ok, components} where components is a list of {label, value} binary tuples.

  • {:error, reason} if parsing fails.