### Complete libpostal Build and Installation Source: https://github.com/openvenues/libpostal/blob/master/README.md Finalize the build process with an increased number of parallel jobs and install the library system-wide. ```bash make -j8 sudo make install ``` -------------------------------- ### Install Prerequisites on Ubuntu/Debian Source: https://github.com/openvenues/libpostal/blob/master/README.md Installs necessary packages for building libpostal on Ubuntu or Debian-based systems. Ensure you have curl, build-essential, autoconf, automake, libtool, and pkg-config installed. ```bash sudo apt-get install -y curl build-essential autoconf automake libtool pkg-config ``` -------------------------------- ### Configure libpostal Installation Source: https://github.com/openvenues/libpostal/blob/master/README.md Configure the build, specifying the data directory. Ensure the specified directory has sufficient space and the correct permissions. ```bash ./configure --datadir=[...some dir with a few GB of space where a "libpostal" directory exists or can be created/modified...] ``` -------------------------------- ### Install Prerequisites on CentOS/RHEL Source: https://github.com/openvenues/libpostal/blob/master/README.md Installs necessary packages for building libpostal on CentOS or RHEL-based systems. Ensure you have curl, autoconf, automake, libtool, and pkgconfig installed. ```bash sudo yum install curl autoconf automake libtool pkgconfig ``` -------------------------------- ### Install libpostal with Homebrew Source: https://github.com/openvenues/libpostal/blob/master/README.md Use this command to install libpostal if you are using Homebrew on macOS. ```bash brew install libpostal ``` -------------------------------- ### Parse Address with C API Source: https://github.com/openvenues/libpostal/blob/master/README.md Example of using the C API to parse an address. Requires libpostal setup and teardown calls. Handles component iteration and memory management. ```c #include #include #include int main(int argc, char **argv) { // Setup (only called once at the beginning of your program) if (!libpostal_setup() || !libpostal_setup_parser()) { exit(EXIT_FAILURE) } libpostal_address_parser_options_t options = libpostal_get_address_parser_default_options(); libpostal_address_parser_response_t *parsed = libpostal_parse_address("781 Franklin Ave Crown Heights Brooklyn NYC NY 11216 USA", options); for (size_t i = 0; i < parsed->num_components; i++) { printf("%s: %s\n", parsed->labels[i], parsed->components[i]); } // Free parse result libpostal_address_parser_response_destroy(parsed); // Teardown (only called once at the end of your program) libpostal_teardown(); libpostal_teardown_parser(); } ``` -------------------------------- ### Expand Address with C API Source: https://github.com/openvenues/libpostal/blob/master/README.md Demonstrates how to use the C API for address expansion. Requires libpostal setup and teardown calls. ```c #include #include #include int main(int argc, char **argv) { // Setup (only called once at the beginning of your program) if (!libpostal_setup() || !libpostal_setup_language_classifier()) { exit(EXIT_FAILURE); } size_t num_expansions; libpostal_normalize_options_t options = libpostal_get_default_options(); char **expansions = libpostal_expand_address("Quatre-vingt-douze Ave des Champs-Élysées", options, &num_expansions); for (size_t i = 0; i < num_expansions; i++) { printf("%s\n", expansions[i]); } // Free expansions libpostal_expansion_array_destroy(expansions, num_expansions); // Teardown (only called once at the end of your program) libpostal_teardown(); libpostal_teardown_language_classifier(); } ``` -------------------------------- ### Compile C Program with libpostal Source: https://github.com/openvenues/libpostal/blob/master/README.md Example of compiling a C program named app.c using gcc, incorporating the flags obtained from pkg-config for libpostal. ```bash gcc app.c `pkg-config --cflags --libs libpostal` ``` -------------------------------- ### Install libpostal with MacPorts Source: https://github.com/openvenues/libpostal/blob/master/README.md Use this command to install libpostal if you are using MacPorts on macOS. ```bash port install libpostal ``` -------------------------------- ### Python Bindings Example for libpostal Parser Source: https://github.com/openvenues/libpostal/blob/master/README.md Demonstrates how to use the libpostal address parser API with its Python bindings. This example showcases a typical usage pattern for parsing addresses. ```python from libpostal import parse_address address = "100 Main St, Anytown, CA 90210, USA" parsed_address = parse_address(address) print(parsed_address) ``` -------------------------------- ### Libpostal Setup Functions Source: https://github.com/openvenues/libpostal/wiki/API Functions to initialize the libpostal parser and language classifier. These functions must be called before using the respective modules. ```APIDOC ## libpostal_setup_parser_datadir ### Description Initializes Libpostal's Address Parser using a specified data directory. ### Method ```c bool libpostal_setup_parser_datadir(char *datadir); ``` ### Parameters * `datadir` (char *) - The directory from which to load LibPostal data. ### Return Value * `bool` - True if the operation was successful, false otherwise. ``` ```APIDOC ## libpostal_setup_language_classifier ### Description Initializes Libpostal's Language Classifier using the default data directory set at compile time. ### Method ```c bool libpostal_setup_language_classifier(void); ``` ### Return Value * `bool` - True if the operation was successful, false otherwise. ``` ```APIDOC ## libpostal_setup_language_classifier_datadir ### Description Initializes Libpostal's Language Classifier using a specified data directory. ### Method ```c bool libpostal_setup_language_classifier_datadir(char *datadir); ``` ### Parameters * `datadir` (char *) - The directory from which to load LibPostal data. ### Return Value * `bool` - True if the operation was successful, false otherwise. ``` -------------------------------- ### Expand Address with Python Bindings Source: https://github.com/openvenues/libpostal/blob/master/README.md Use the Python bindings to expand an address. Ensure the 'pypostal' library is installed. ```python from postal.expand import expand_address expansions = expand_address('Quatre-vingt-douze Ave des Champs-Élysées') assert '92 avenue des champs-elysees' in set(expansions) ``` -------------------------------- ### Get Default Normalization Options Source: https://github.com/openvenues/libpostal/wiki/API Retrieves the default configuration options for address normalization. ```c libpostal_normalize_options_t libpostal_get_default_options(void); ``` -------------------------------- ### Download libpostal Data Files Source: https://github.com/openvenues/libpostal/blob/master/README.md Use this command to download all necessary data files for libpostal. Replace $YOUR_DATA_DIR with your installation's data directory. ```bash libpostal_data download all $YOUR_DATA_DIR/libpostal ``` -------------------------------- ### Launch Interactive Address Parser Source: https://github.com/openvenues/libpostal/blob/master/README.md Start the interactive command-line address parser. Type addresses directly into the shell to see parsed results. ```bash cd src/ ./address_parser ``` -------------------------------- ### Example Dictionary Format Source: https://github.com/openvenues/libpostal/blob/master/resources/dictionaries/README.md Demonstrates the pipe-delimited format for defining canonical terms and their synonyms in libpostal dictionary files. The leftmost string is the normalized version, followed by its synonyms. ```text drive|dr street|st|str road|rd ``` -------------------------------- ### Get default fuzzy duplicate options with languages Source: https://github.com/openvenues/libpostal/wiki/API Retrieves the default configuration options for fuzzy duplicate matching, specifying a list of languages to consider. ```c libpostal_fuzzy_duplicate_options_t libpostal_get_default_fuzzy_duplicate_options_with_languages(size_t num_languages, char **languages); ``` -------------------------------- ### Expand Address with libpostal Source: https://context7.com/openvenues/libpostal/llms.txt Expands a raw address string into normalized canonical forms. Requires setup and teardown of libpostal components. The caller must free the returned array. ```c #include #include #include int main(void) { if (!libpostal_setup() || !libpostal_setup_language_classifier()) { exit(EXIT_FAILURE); } libpostal_normalize_options_t options = libpostal_get_default_options(); size_t num_expansions; char **expansions = libpostal_expand_address( "Quatre-vingt-douze Ave des Champs-Élysées", options, &num_expansions ); for (size_t i = 0; i < num_expansions; i++) { printf("%s\n", expansions[i]); // Output example: // 92 avenue des champs-elysees } libpostal_expansion_array_destroy(expansions, num_expansions); // Example 2: German compound street type normalization char **de_expansions = libpostal_expand_address( "Marktstraße 14", options, &num_expansions ); for (size_t i = 0; i < num_expansions; i++) { printf("%s\n", de_expansions[i]); // markt strasse 14 // marktstrasse 14 } libpostal_expansion_array_destroy(de_expansions, num_expansions); libpostal_teardown_language_classifier(); libpostal_teardown(); return EXIT_SUCCESS; } ``` -------------------------------- ### Clean and Bootstrap libpostal Source: https://github.com/openvenues/libpostal/blob/master/README.md Run these commands to clean previous builds and prepare for configuration. ```bash make distclean ./bootstrap.sh ``` -------------------------------- ### libpostal_setup_datadir Source: https://github.com/openvenues/libpostal/wiki/API Initializes LibPostal using a specified data directory. This must be called before using other LibPostal functions. ```APIDOC ## libpostal_setup_datadir ### Description Initializes LibPostal using the directory specified within the `datadir` variable. ### Method ```c bool libpostal_setup_datadir(char *datadir); ``` ### Parameters #### Path Parameters - **datadir** (char *) - Required - The directory from which to load LibPostal. ### Return Value - `bool`: Whether the operation was a success. ``` -------------------------------- ### Build libpostal C Library on Windows Source: https://github.com/openvenues/libpostal/blob/master/README.md Steps to clone the libpostal repository, copy Windows-specific files, bootstrap, configure, and build the C library using make. ```bash git clone https://github.com/openvenues/libpostal cd libpostal cp -rf windows/* ./ ./bootstrap.sh ./configure --datadir=[...some dir with a few GB of space...] make -j4 make install ``` -------------------------------- ### libpostal_setup Source: https://github.com/openvenues/libpostal/wiki/API Initializes LibPostal using the default directory set at compile time. This must be called before using other LibPostal functions. ```APIDOC ## libpostal_setup ### Description Initializes LibPostal using the default directory set at compile time. ### Method ```c bool libpostal_setup(void); ``` ### Return Value - `bool`: Whether the operation was a success. ``` -------------------------------- ### libpostal_setup / libpostal_setup_datadir Source: https://context7.com/openvenues/libpostal/llms.txt Initializes the libpostal core data. This function must be called before any other API functions. `libpostal_setup_datadir` allows specifying a custom data directory. ```APIDOC ## libpostal_setup / libpostal_setup_datadir ### Description Initializes the libpostal core data (language dictionaries, trie structures). Must be called before any other API. `libpostal_setup_datadir` accepts a custom data directory path when the default compile-time path is not appropriate. ### Method C Function Call ### Parameters - **`libpostal_setup()`**: Initializes core with default data directory. - **`libpostal_setup_datadir(const char *data_dir)`**: Initializes with a custom data directory path. ### Return Value - `1` on success, `0` on failure. ### Usage Example ```c #include #include #include int main(void) { // Initialize core with default data directory if (!libpostal_setup()) { fprintf(stderr, "Failed to initialize libpostal core\n"); return EXIT_FAILURE; } // OR: Initialize with a custom data directory // if (!libpostal_setup_datadir("/var/data/libpostal")) { ... } // ... use the library ... libpostal_teardown(); // Always call teardown at program exit return EXIT_SUCCESS; } ``` ``` -------------------------------- ### Update MSys2 and Install Prerequisites on Windows Source: https://github.com/openvenues/libpostal/blob/master/README.md Commands to update the MSys2 environment and install essential build tools and libraries required for compiling libpostal on Windows. ```bash pacman -Syu ``` ```bash pacman -S autoconf automake curl git make libtool gcc mingw-w64-x86_64-gcc ``` -------------------------------- ### libpostal_setup_parser / libpostal_setup_parser_datadir Source: https://context7.com/openvenues/libpostal/llms.txt Initializes the CRF address parser module. This must be called after `libpostal_setup` and is required before using `libpostal_parse_address`. ```APIDOC ## libpostal_setup_parser / libpostal_setup_parser_datadir ### Description Initializes the CRF address parser module. Call after `libpostal_setup`. Required before using `libpostal_parse_address`. ### Method C Function Call ### Parameters - **`libpostal_setup_parser()`**: Initializes the parser module with default data directory. - **`libpostal_setup_parser_datadir(const char *data_dir)`**: Initializes the parser module with a custom data directory path. ### Return Value - `1` on success, `0` on failure. ### Usage Example ```c if (!libpostal_setup() || !libpostal_setup_parser()) { fprintf(stderr, "Failed to initialize libpostal parser\n"); exit(EXIT_FAILURE); } // Use parser ... libpostal_teardown_parser(); libpostal_teardown(); ``` ``` -------------------------------- ### Get Default Address Parser Options Source: https://github.com/openvenues/libpostal/wiki/API Retrieves the default configuration options for the address parser. ```c libpostal_address_parser_options_t libpostal_get_address_parser_default_options(void); ``` -------------------------------- ### libpostal_setup_parser Source: https://github.com/openvenues/libpostal/wiki/API Initializes LibPostal's Address Parser using the default directory set at compile time. This must be called before using parser-specific functions. ```APIDOC ## libpostal_setup_parser ### Description Initializes LibPostals Address Parser using the default directory set at compile time. ### Method ```c bool libpostal_setup_parser(void); ``` ### Return Value - `bool`: Whether the operation was a success. ``` -------------------------------- ### Get default fuzzy duplicate options Source: https://github.com/openvenues/libpostal/wiki/API Retrieves the default configuration options for fuzzy duplicate matching. ```c libpostal_fuzzy_duplicate_options_t libpostal_get_default_fuzzy_duplicate_options(void); ``` -------------------------------- ### Initialize libpostal Core Source: https://context7.com/openvenues/libpostal/llms.txt Initializes the libpostal core data. Must be called before any other API. `libpostal_setup_datadir` can be used to specify a custom data directory. ```c #include #include #include int main(void) { // Initialize core with default data directory if (!libpostal_setup()) { fprintf(stderr, "Failed to initialize libpostal core\n"); return EXIT_FAILURE; } // OR: Initialize with a custom data directory // if (!libpostal_setup_datadir("/var/data/libpostal")) { ... } // ... use the library ... libpostal_teardown(); // Always call teardown at program exit return EXIT_SUCCESS; } ``` -------------------------------- ### Get Default Duplicate Options Source: https://github.com/openvenues/libpostal/wiki/API Retrieves a libpostal_duplicate_options_t struct with default settings for address duplicate checking. ```c libpostal_duplicate_options_t libpostal_get_default_duplicate_options(void); ``` -------------------------------- ### Get Default Near Duplicate Hash Options Source: https://github.com/openvenues/libpostal/wiki/API Retrieves a libpostal_near_dupe_hash_options_t struct with default settings for near duplicate hashing. ```c libpostal_near_dupe_hash_options_t libpostal_get_near_dupe_hash_default_options(void); ``` -------------------------------- ### Initialize LibPostal Core with Data Directory Source: https://github.com/openvenues/libpostal/wiki/API Initializes the LibPostal library by specifying a custom data directory. Returns a boolean indicating success. ```c bool libpostal_setup_datadir(char *datadir); ``` -------------------------------- ### Parse Address with Python API Source: https://github.com/openvenues/libpostal/blob/master/README.md Use the Python binding to parse an address string. Ensure the libpostal library is installed and accessible. ```python from postal.parser import parse_address parse_address('The Book Club 100-106 Leonard St Shoreditch London EC2A 4RH, United Kingdom') ``` -------------------------------- ### Configure libpostal for Apple/ARM CPUs Source: https://github.com/openvenues/libpostal/blob/master/README.md Configure the build for Apple or ARM processors, disabling SSE2 instructions. ```bash ./configure --datadir=[...some dir with a few GB of space where a "libpostal" directory exists or can be created/modified...] --disable-sse2 ``` -------------------------------- ### Compile libpostal from Source Source: https://github.com/openvenues/libpostal/blob/master/README.md Clone the libpostal repository and configure the build process. This is the standard procedure for compiling from source. ```bash git clone https://github.com/openvenues/libpostal cd libpostal ./configure ``` -------------------------------- ### Initialize LibPostal Core Source: https://github.com/openvenues/libpostal/wiki/API Initializes the LibPostal library using the default data directory compiled into the library. Returns a boolean indicating success. ```c bool libpostal_setup(void); ``` -------------------------------- ### Build libpostal for Intel/AMD Processors Source: https://github.com/openvenues/libpostal/blob/master/README.md Compile libpostal using multiple cores for faster build times on standard Intel/AMD CPUs. ```bash make -j4 # For Intel/AMD processors and the default model ./configure --datadir=[...some dir with a few GB of space where a "libpostal" directory exists or can be created/modified...] ``` -------------------------------- ### Get Default Duplicate Detection Options Source: https://context7.com/openvenues/libpostal/llms.txt Returns default options for pairwise duplicate detection. Use these options with `libpostal_is_*_duplicate` functions. ```c // Auto language detection libpostal_duplicate_options_t opts = libpostal_get_default_duplicate_options(); ``` -------------------------------- ### Configure libpostal with Senzing Model Source: https://github.com/openvenues/libpostal/blob/master/README.md Build libpostal with the alternative Senzing data model by adding MODEL=senzing to the configure command. This model offers improved parsing for specific regions. ```bash ./configure --datadir=[...some dir with a few GB of space...] MODEL=senzing ``` -------------------------------- ### Compile libpostal from Source on M1 Mac Source: https://github.com/openvenues/libpostal/blob/master/README.md Clone the libpostal repository and configure the build. For M1 Macs, include the --disable-sse2 flag to ensure a successful build, though it may impact performance. ```bash git clone https://github.com/openvenues/libpostal cd libpostal ./configure --disable-sse2 ``` -------------------------------- ### Classify Language of Address String Source: https://context7.com/openvenues/libpostal/llms.txt Classifies the language(s) used in an address string. Requires only the core libpostal setup. The caller must free the response. ```c #include #include #include int main(void) { if (!libpostal_setup()) exit(EXIT_FAILURE); libpostal_language_classifier_response_t *response = libpostal_classify_language("ул Каретный Ряд, д 4, строение 7"); for (size_t i = 0; i < response->num_languages; i++) { printf("%s: %.4f\n", response->languages[i], response->probs[i]); // ru: 0.9821 } libpostal_language_classifier_response_destroy(response); libpostal_teardown(); return EXIT_SUCCESS; } ``` -------------------------------- ### Configure libpostal with Senzing Model Source: https://github.com/openvenues/libpostal/blob/master/README.md Configure the build to use the improved Senzing model. ```bash ./configure --datadir=[...some dir with a few GB of space where a "libpostal" directory exists or can be created/modified...] MODEL=senzing ``` -------------------------------- ### Get Duplicate Detection Options with Explicit Languages Source: https://context7.com/openvenues/libpostal/llms.txt Returns duplicate detection options pre-populated with a specific language list. This is faster and more accurate when the language is known. ```c // Explicit language (faster, more accurate when language is known) char *langs[] = {"en"}; libpostal_duplicate_options_t opts_en = libpostal_get_duplicate_options_with_languages(1, langs); ``` -------------------------------- ### Get Duplicate Options with Languages Source: https://github.com/openvenues/libpostal/wiki/API Retrieves a libpostal_duplicate_options_t struct, specifying the languages to be used for address duplicate checking. Languages can be obtained from the Detect Languages function. ```c libpostal_duplicate_options_t libpostal_get_duplicate_options_with_languages(size_t num_languages, char **languages); ``` -------------------------------- ### Get Latest Parser Training Set Date Source: https://github.com/openvenues/libpostal/blob/master/README.md This command retrieves the date of the most recently created parser training set, which can be used to reference the latest data. ```bash latest=$(cat current_parser_training_set) ``` -------------------------------- ### libpostal_setup_language_classifier / libpostal_setup_language_classifier_datadir Source: https://context7.com/openvenues/libpostal/llms.txt Initializes the language classifier module. This is required before using functions related to address expansion, near-dupe hashing, or duplicate detection. ```APIDOC ## libpostal_setup_language_classifier / libpostal_setup_language_classifier_datadir ### Description Initializes the language classifier module. Required before using `libpostal_expand_address`, near-dupe hashing, or duplicate detection functions. ### Method C Function Call ### Parameters - **`libpostal_setup_language_classifier()`**: Initializes the language classifier module with default data directory. - **`libpostal_setup_language_classifier_datadir(const char *data_dir)`**: Initializes the language classifier module with a custom data directory path. ### Return Value - `1` on success, `0` on failure. ### Usage Example ```c if (!libpostal_setup() || !libpostal_setup_language_classifier()) { fprintf(stderr, "Failed to initialize language classifier\n"); exit(EXIT_FAILURE); } // Use expansion, deduplication ... libpostal_teardown_language_classifier(); libpostal_teardown(); ``` ``` -------------------------------- ### Initialize LibPostal Address Parser Source: https://github.com/openvenues/libpostal/wiki/API Initializes LibPostal's address parser using the default data directory compiled into the library. Returns a boolean indicating success. ```c bool libpostal_setup_parser(void); ``` -------------------------------- ### Get Default Address Parser Options Source: https://context7.com/openvenues/libpostal/llms.txt Retrieves default parser options. Language and country are auto-detected by default. Set these fields to constrain parsing to a specific locale. ```c libpostal_address_parser_options_t options = libpostal_get_address_parser_default_options(); // Optionally constrain to US English options.language = "en"; options.country = "us"; ```