From 0327150d2b0363c7d8c7a5a37ad8ea7b4a65806a Mon Sep 17 00:00:00 2001 From: "Luiz Otavio V. B. Oliveira" Date: Fri, 14 Jun 2019 14:31:12 +0200 Subject: [PATCH] Exposes language classification functions --- libpostal.def | 2 ++ src/libpostal.c | 24 ++++++++++++++++++++++++ src/libpostal.h | 13 +++++++++++++ 3 files changed, 39 insertions(+) diff --git a/libpostal.def b/libpostal.def index 7deba4f7..6bf12ede 100644 --- a/libpostal.def +++ b/libpostal.def @@ -3,9 +3,11 @@ libpostal_get_default_options libpostal_expand_address libpostal_expansion_array_destroy libpostal_address_parser_response_destroy +libpostal_language_classifier_response_destroy libpostal_get_address_parser_default_options libpostal_parse_address libpostal_parser_print_features +libpostal_classify_language libpostal_setup libpostal_setup_datadir libpostal_teardown diff --git a/src/libpostal.c b/src/libpostal.c index d56e7000..c1ac6a7a 100644 --- a/src/libpostal.c +++ b/src/libpostal.c @@ -202,6 +202,30 @@ libpostal_fuzzy_duplicate_status_t libpostal_is_street_duplicate_fuzzy(size_t nu return is_street_duplicate_fuzzy(num_tokens1, tokens1, token_scores1, num_tokens2, tokens2, token_scores2, options); } +libpostal_language_classifier_response_t *libpostal_classify_language(char *address) { + libpostal_language_classifier_response_t *response = classify_languages(address); + + if (response == NULL) { + log_error("Language classification returned NULL\n"); + return NULL; + } + + return response; +} + +void libpostal_language_classifier_response_destroy(libpostal_language_classifier_response_t *self) { + if (self == NULL) return; + if (self->languages != NULL) { + free(self->languages); + } + + if (self->probs) { + free(self->probs); + } + + free(self); +} + void libpostal_address_parser_response_destroy(libpostal_address_parser_response_t *self) { if (self == NULL) return; diff --git a/src/libpostal.h b/src/libpostal.h index 89b9a4c6..ddc07dff 100644 --- a/src/libpostal.h +++ b/src/libpostal.h @@ -167,6 +167,19 @@ LIBPOSTAL_EXPORT libpostal_address_parser_response_t *libpostal_parse_address(ch LIBPOSTAL_EXPORT bool libpostal_parser_print_features(bool print_features); +/* +Language classification +*/ + +typedef struct libpostal_language_classifier_response { + size_t num_languages; + char **languages; + double *probs; +} libpostal_language_classifier_response_t; + +LIBPOSTAL_EXPORT libpostal_language_classifier_response_t *libpostal_classify_language(char *address); + +LIBPOSTAL_EXPORT void libpostal_language_classifier_response_destroy(libpostal_language_classifier_response_t *self); /* Deduping