From cf2a0efa11d9f0f8a1602450509ea4d10d61a1e2 Mon Sep 17 00:00:00 2001 From: Al Date: Sat, 19 Dec 2015 17:29:26 -0500 Subject: [PATCH] [fix] Prefixes and suffixes that are the same length as the original token should be handled as regular expansions --- src/libpostal.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/libpostal.c b/src/libpostal.c index d61f3985..85f46ab9 100644 --- a/src/libpostal.c +++ b/src/libpostal.c @@ -437,8 +437,12 @@ inline void cat_affix_expansion(char_array *key, char *str, address_expansion_t bool add_affix_expansions(string_tree_t *tree, char *str, char *lang, token_t token, phrase_t prefix, phrase_t suffix, normalize_options_t options) { cstring_array *strings = tree->strings; - bool have_suffix = suffix.len > 0; - bool have_prefix = prefix.len > 0; + bool have_suffix = suffix.len > 0 && suffix.len < token.len; + bool have_prefix = prefix.len > 0 && prefix.len < token.len; + + if (!have_suffix && !have_prefix) { + return false; + } address_expansion_array *prefix_expansions = NULL; address_expansion_array *suffix_expansions = NULL; @@ -470,6 +474,7 @@ bool add_affix_expansions(string_tree_t *tree, char *str, char *lang, token_t to } if (!have_suffix && !have_prefix) { + char_array_destroy(key); return false; } @@ -556,7 +561,6 @@ bool add_affix_expansions(string_tree_t *tree, char *str, char *lang, token_t to char_array_clear(key); root_word = cstring_array_get_string(root_strings, j); char_array_cat(key, root_word); - root_end = key->n - 1; for (int k = 0; k < suffix_expansions->n; k++) { @@ -645,6 +649,7 @@ inline bool expand_affixes(string_tree_t *tree, char *str, char *lang, token_t t if ((suffix.len == 0 && prefix.len == 0)) return false; + return add_affix_expansions(tree, str, lang, token, prefix, suffix, options); }