[expand] added search_address_dictionaries_substring to support the new use case (i.e. returns "does this substring in the trie?" regardless of if it's stored under the special prefixes/suffixes namespaces)

This commit is contained in:
Al
2017-10-28 02:40:14 -04:00
parent 053dca82ba
commit 2d6079b06f
2 changed files with 26 additions and 0 deletions

View File

@@ -251,6 +251,31 @@ phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens,
return phrases;
}
phrase_t search_address_dictionaries_substring(char *str, size_t len, char *lang) {
if (str == NULL) return NULL_PHRASE;
if (address_dict == NULL) {
log_error(ADDRESS_DICTIONARY_SETUP_ERROR);
return NULL_PHRASE;
}
trie_prefix_result_t prefix = get_language_prefix(lang);
if (prefix.node_id == NULL_NODE_ID) {
log_debug("prefix.node_id == NULL_NODE_ID\n");
return NULL_PHRASE;
}
phrase_t phrase = trie_search_prefixes_from_index(address_dict->trie, str, len, prefix.node_id);
if (phrase.len == len) {
return phrase;
} else {
return NULL_PHRASE;
}
}
phrase_t search_address_dictionaries_prefix(char *str, size_t len, char *lang) {
if (str == NULL) return NULL_PHRASE;
if (address_dict == NULL) {

View File

@@ -63,6 +63,7 @@ bool search_address_dictionaries_with_phrases(char *str, char *lang, phrase_arra
phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens, char *lang);
bool search_address_dictionaries_tokens_with_phrases(char *str, token_array *tokens, char *lang, phrase_array **phrases);
phrase_t search_address_dictionaries_substring(char *str, size_t len, char *lang);
phrase_t search_address_dictionaries_prefix(char *str, size_t len, char *lang);
phrase_t search_address_dictionaries_suffix(char *str, size_t len, char *lang);