Пример #1
0
static Trie *
brk_get_dict ()
{
    static int is_dict_tried = 0;

    if (!brk_dict && !is_dict_tried) {
        const char *dict_dir;
        char        path[512];

        /* Try LIBTHAI_DICTDIR env first */
        if (NULL != (dict_dir = getenv ("LIBTHAI_DICTDIR"))) {
            snprintf (path, sizeof path, "%s/%s.tri", dict_dir, DICT_NAME);
            brk_dict = trie_new_from_file (path);
        }

        /* Then, fall back to default DICT_DIR macro */
        if (!brk_dict) {
            brk_dict = trie_new_from_file (DICT_DIR "/" DICT_NAME ".tri");
        }

        if (!brk_dict) {
            if (dict_dir) {
                fprintf (stderr,
                         "LibThai: Fail to open dictionary at '%s' and '%s'.\n",
                         path, DICT_DIR "/" DICT_NAME ".tri");
            } else {
                fprintf (stderr,
                         "LibThai: Fail to open dictionary at '%s'.\n",
                         DICT_DIR "/" DICT_NAME ".tri");
            }
        }

        is_dict_tried = 1;
    }

    return brk_dict;
}
Пример #2
0
ATTrie :: ATTrie(const char * path) : data(NULL) {
	nodes=database_info.trie_nodes;
	data = new ATTrieData;
#if 1 //added by Jad due to an error occuring in desctructor when trie is loaded from file
	data->amap = alpha_map_new();
	if (data->amap == NULL)
		throw "AlphaMapConstructionException";

	// add all characters except 0 and FF FF FF FF
	// AlphaChar is uint32
	// this needs to change later to allow only Arabic and Latin
	alpha_map_add_range(data->amap, 1, 0xFFFFFFFE);
	data->trie = trie_new(data->amap);
#endif
    data->trie = trie_new_from_file(path);
    if (data->trie == NULL)
        throw "TrieConstructionException";
}