Modifed the libpostal API to add an extra function libpostal_parser_print_features to toggle debugging info. Updated address_parser app to use the new function.

This commit is contained in:
AeroXuk
2017-11-27 19:20:37 +00:00
parent 69e0d5d963
commit 9090811826
6 changed files with 20 additions and 5 deletions

View File

@@ -5,6 +5,7 @@ libpostal_expansion_array_destroy
libpostal_address_parser_response_destroy
libpostal_get_address_parser_default_options
libpostal_parse_address
libpostal_parser_print_features
libpostal_setup
libpostal_setup_datadir
libpostal_teardown

View File

@@ -49,6 +49,13 @@ address_parser_t *get_address_parser(void) {
return parser;
}
bool address_parser_print_features(bool print_features) {
if (parser == NULL) return false;
parser->options.print_features = print_features;
return true;
}
bool address_parser_save(address_parser_t *self, char *output_dir) {
if (self == NULL || output_dir == NULL) return false;

View File

@@ -215,6 +215,7 @@ address_parser_t *address_parser_new_options(parser_options_t options);
address_parser_t *get_address_parser(void);
bool address_parser_load(char *dir);
bool address_parser_print_features(bool print_features);
libpostal_address_parser_response_t *address_parser_parse(char *address, char *language, char *country);
void address_parser_destroy(address_parser_t *self);

View File

@@ -73,23 +73,23 @@ int main(int argc, char **argv) {
cstring_array_destroy(command);
goto next_input;
} /*else if (string_starts_with(input, ".print_features")) {
} else if (string_starts_with(input, ".print_features")) {
size_t num_tokens = 0;
cstring_array *command = cstring_array_split(input, " ", 1, &num_tokens);
if (cstring_array_num_strings(command) > 1) {
char *flag = cstring_array_get_string(command, 1);
if (string_compare_case_insensitive(flag, "off") == 0) {
parser->options.print_features = false;
libpostal_parser_print_features(false);
} else if (string_compare_case_insensitive(flag, "on") == 0) {
parser->options.print_features = true;
libpostal_parser_print_features(true);
}
} else {
parser->options.print_features = true;
libpostal_parser_print_features(true);
}
cstring_array_destroy(command);
goto next_input;
}*/ else if (strlen(input) == 0) {
} else if (strlen(input) == 0) {
goto next_input;
}

View File

@@ -1073,6 +1073,10 @@ libpostal_address_parser_response_t *libpostal_parse_address(char *address, libp
return parsed;
}
bool libpostal_parser_print_features(bool print_features) {
return address_parser_print_features(print_features);
}
bool libpostal_setup_datadir(char *datadir) {
char *transliteration_path = NULL;
char *numex_path = NULL;

View File

@@ -101,6 +101,8 @@ LIBPOSTAL_EXPORT libpostal_address_parser_options_t libpostal_get_address_parser
LIBPOSTAL_EXPORT libpostal_address_parser_response_t *libpostal_parse_address(char *address, libpostal_address_parser_options_t options);
LIBPOSTAL_EXPORT bool libpostal_parser_print_features(bool print_features);
// Setup/teardown methods
LIBPOSTAL_EXPORT bool libpostal_setup(void);