Merge pull request #81 from openvenues/null_options

Fixes for expand case where all options are set to false
This commit is contained in:
Al Barrentine
2016-07-15 13:39:03 -04:00
committed by GitHub
3 changed files with 32 additions and 2 deletions

View File

@@ -888,6 +888,9 @@ static void expand_alternative(cstring_array *strings, khash_t(str_set) *unique_
char_array_clear(temp_string);
string_tree_iterator_foreach_token(iter, token, {
log_debug("token=%s\n", token);
if (token == NULL) {
continue;
}
char_array_append(temp_string, token);
})
char_array_terminate(temp_string);
@@ -933,9 +936,7 @@ char **expand_address(char *input, normalize_options_t options, size_t *n) {
options.languages = lang_response->languages;
}
}
string_tree_t *tree = normalize_string_languages(input, normalize_string_options, options.num_languages, options.languages);
cstring_array *strings = cstring_array_new_size(len * 2);
char_array *temp_string = char_array_new_size(len);
@@ -959,6 +960,7 @@ char **expand_address(char *input, normalize_options_t options, size_t *n) {
bool is_first = true;
string_tree_iterator_foreach_token(iter, segment, {
if (segment == NULL) continue;
if (!is_first) {
char_array_append(temp_string, " ");
}

View File

@@ -100,6 +100,8 @@ void add_latin_alternatives(string_tree_t *tree, char *str, size_t len, uint64_t
}
free(transliterated);
transliterated = NULL;
} else {
string_tree_add_string(tree, str);
}
if (prev_string != NULL) {

View File

@@ -84,6 +84,31 @@ TEST test_expansions_language_classifier(void) {
PASS();
}
TEST test_expansions_no_options(void) {
normalize_options_t options = get_libpostal_default_options();
options.lowercase = false;
options.latin_ascii = false;
options.transliterate = false;
options.strip_accents = false;
options.decompose = false;
options.trim_string = false;
options.drop_parentheticals = false;
options.replace_numeric_hyphens = false;
options.delete_numeric_hyphens = false;
options.split_alpha_from_numeric = false;
options.replace_word_hyphens = false;
options.delete_word_hyphens = false;
options.delete_final_periods = false;
options.delete_acronym_periods = false;
options.drop_english_possessives = false;
options.delete_apostrophes = false;
options.expand_numex = false;
options.roman_numerals = false;
CHECK_CALL(test_expansion_contains_with_languages("120 E 96th St New York", "120 E 96th St New York", options, 0, NULL));
PASS();
}
SUITE(libpostal_expansion_tests) {
@@ -94,6 +119,7 @@ SUITE(libpostal_expansion_tests) {
RUN_TEST(test_expansions);
RUN_TEST(test_expansions_language_classifier);
RUN_TEST(test_expansions_no_options);
libpostal_teardown();
libpostal_teardown_language_classifier();