[expansion] tokenized version of search_address_dictionaries
This commit is contained in:
@@ -21,7 +21,6 @@ address_expansion_array *address_dictionary_get_expansions(char *key) {
|
|||||||
int32_t address_dictionary_next_canonical_index(void) {
|
int32_t address_dictionary_next_canonical_index(void) {
|
||||||
if (address_dict == NULL || address_dict->canonical == NULL) return -1;
|
if (address_dict == NULL || address_dict->canonical == NULL) return -1;
|
||||||
return (int32_t)cstring_array_num_strings(address_dict->canonical);
|
return (int32_t)cstring_array_num_strings(address_dict->canonical);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool address_dictionary_add_canonical(char *canonical) {
|
bool address_dictionary_add_canonical(char *canonical) {
|
||||||
@@ -117,17 +116,27 @@ bool address_dictionary_add_expansion(char *key, address_expansion_t expansion)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
phrase_array *search_address_dictionaries(char *str, char *lang) {
|
static trie_prefix_result_t get_language_prefix(char *lang) {
|
||||||
if (str == NULL || lang == NULL) return NULL;
|
|
||||||
|
|
||||||
trie_prefix_result_t prefix = trie_get_prefix(address_dict->trie, lang);
|
trie_prefix_result_t prefix = trie_get_prefix(address_dict->trie, lang);
|
||||||
|
|
||||||
if (prefix.node_id == NULL_NODE_ID) {
|
if (prefix.node_id == NULL_NODE_ID) {
|
||||||
return NULL;
|
return NULL_PREFIX_RESULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
prefix = trie_get_prefix_from_index(address_dict->trie, NAMESPACE_SEPARATOR_CHAR, NAMESPACE_SEPARATOR_CHAR_LEN, prefix.node_id, prefix.tail_pos);
|
prefix = trie_get_prefix_from_index(address_dict->trie, NAMESPACE_SEPARATOR_CHAR, NAMESPACE_SEPARATOR_CHAR_LEN, prefix.node_id, prefix.tail_pos);
|
||||||
|
|
||||||
|
if (prefix.node_id == NULL_NODE_ID) {
|
||||||
|
return NULL_PREFIX_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
phrase_array *search_address_dictionaries(char *str, char *lang) {
|
||||||
|
if (str == NULL || lang == NULL) return NULL;
|
||||||
|
|
||||||
|
trie_prefix_result_t prefix = get_language_prefix(lang);
|
||||||
|
|
||||||
if (prefix.node_id == NULL_NODE_ID) {
|
if (prefix.node_id == NULL_NODE_ID) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@@ -135,6 +144,15 @@ phrase_array *search_address_dictionaries(char *str, char *lang) {
|
|||||||
return trie_search_from_index(address_dict->trie, str, prefix.node_id);
|
return trie_search_from_index(address_dict->trie, str, prefix.node_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens, char *lang) {
|
||||||
|
trie_prefix_result_t prefix = get_language_prefix(lang);
|
||||||
|
|
||||||
|
if (prefix.node_id == NULL_NODE_ID) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return trie_search_tokens_from_index(address_dict->trie, str, tokens, prefix.node_id);
|
||||||
|
}
|
||||||
|
|
||||||
bool address_dictionary_init(void) {
|
bool address_dictionary_init(void) {
|
||||||
if (address_dict != NULL) return false;
|
if (address_dict != NULL) return false;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ address_dictionary_t *get_address_dictionary(void);
|
|||||||
bool address_dictionary_init(void);
|
bool address_dictionary_init(void);
|
||||||
|
|
||||||
phrase_array *search_address_dictionaries(char *str, char *lang);
|
phrase_array *search_address_dictionaries(char *str, char *lang);
|
||||||
|
phrase_array *search_address_dictionaries_tokens(char *str, token_array *tokens, char *lang);
|
||||||
|
|
||||||
address_expansion_array *address_dictionary_get_expansions(char *key);
|
address_expansion_array *address_dictionary_get_expansions(char *key);
|
||||||
char *address_dictionary_get_canonical(uint32_t index);
|
char *address_dictionary_get_canonical(uint32_t index);
|
||||||
int32_t address_dictionary_next_canonical_index(void);
|
int32_t address_dictionary_next_canonical_index(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user