[expansion] Address dictionary allocation, I/O, get/set

This commit is contained in:
Al
2015-07-21 16:46:15 -04:00
parent 2114b21399
commit c798876b3d
2 changed files with 449 additions and 0 deletions

69
src/address_dictionary.h Normal file
View File

@@ -0,0 +1,69 @@
#ifndef ADDRESS_DICTIONARY_H
#define ADDRESS_DICTIONARY_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include "address_expansion_rule.h"
#include "config.h"
#include "constants.h"
#include "collections.h"
#include "file_utils.h"
#include "gazetteers.h"
#include "trie.h"
#define DEFAULT_ADDRESS_EXPANSION_PATH LIBPOSTAL_DATA_DIR PATH_SEPARATOR "address_expansions" PATH_SEPARATOR "address_dictionary.dat"
typedef union expansion_value {
uint32_t value;
struct {
uint32_t components:16;
uint32_t count:15;
uint32_t canonical:1;
};
} expansion_value_t;
typedef struct address_expansion {
int32_t canonical_index;
char language[MAX_LANGUAGE_LEN];
uint16_t dictionary_id;
uint16_t address_components;
} address_expansion_t;
VECTOR_INIT(address_expansion_array, address_expansion_t)
KHASH_MAP_INIT_STR(str_expansions, address_expansion_array *)
typedef struct address_dictionary {
cstring_array *canonical;
khash_t(str_expansions) *expansions;
trie_t *trie;
} address_dictionary_t;
address_dictionary_t *get_address_dictionary(void);
bool address_dictionary_init(void);
address_expansion_array *address_dictionary_get_expansions(address_dictionary_t *self, char *key);
bool address_dictionary_add_expansion(address_dictionary_t *self, char *key, char *canonical, char *language, uint16_t dictionary_id, uint16_t address_components);
void address_dictionary_destroy(address_dictionary_t *self);
bool address_dictionary_load(char *path);
bool address_dictionary_save(char *path);
bool address_dictionary_module_setup(void);
void address_dictionary_module_teardown(void);
#ifdef __cplusplus
}
#endif
#endif