int opencc_dict_load(opencc_t t_opencc, const char * dict_filename, opencc_dictionary_type dict_type) { if (!lib_initialized) lib_initialize(); opencc_desc * opencc = (opencc_desc *) t_opencc; dictionary_group_t dictionary_group; if (opencc->dictionary_set == NULL) { opencc->dictionary_set = dictionary_set_open(); dictionary_group = dictionary_set_new_group(opencc->dictionary_set); } else { dictionary_group = dictionary_set_get_group(opencc->dictionary_set, 0); } int retval; retval = dictionary_group_load(dictionary_group, dict_filename, dict_type); if (retval == -1) { errnum = OPENCC_ERROR_DICTLOAD; return -1; } converter_assign_dictionary(opencc->converter, opencc->dictionary_set); return retval; }
static int load_dictionary(config_desc * config) { if (config->dicts_count == 0) return 0; qsort ( config->dicts, config->dicts_count, sizeof(config->dicts[0]), qsort_dictionary_buffer_cmp ); size_t i, last_index = 0; dictionary_group_t group = dictionary_set_new_group(config->dictionary_set); for (i = 0; i < config->dicts_count; i ++) { if (config->dicts[i].index > last_index) { last_index = config->dicts[i].index; group = dictionary_set_new_group(config->dictionary_set); } dictionary_group_load(group, config->dicts[i].file_name, config->home_dir,config->dicts[i].dict_type); } return 0; }
void init(const char * filename) { dictionary_group_t dictionary_group = dictionary_group_open(NULL); if (dictionary_group_load(dictionary_group, filename, OPENCC_DICTIONARY_TYPE_TEXT) == -1) { dictionary_perror("Dictionary loading error"); fprintf(stderr, _("\n")); exit(1); } dictionary_t t_dictionary = dictionary_group_get_dictionary(dictionary_group, 0); if (t_dictionary == (dictionary_t) -1) { dictionary_perror("Dictionary loading error"); fprintf(stderr, _("\n")); exit(1); } static entry tlexicon[DATRIE_WORD_MAX_COUNT]; /* TODO add datrie support */ dictionary_t dictionary = dictionary_get(t_dictionary); lexicon_count = dictionary_text_get_lexicon(dictionary, tlexicon); qsort(tlexicon, lexicon_count, sizeof(tlexicon[0]), cmp); size_t i; size_t lexicon_cursor = 0; for (i = 0; i < lexicon_count; i ++) { lexicon[i].key = tlexicon[i].key; lexicon[i].length = ucs4len(lexicon[i].key); size_t j; for (j = 0; tlexicon[i].value[j] != NULL; j ++); lexicon[i].value_count = j; lexicon_index_length += lexicon[i].value_count + 1; lexicon[i].value = (value_t *) malloc(lexicon[i].value_count * sizeof(value_t)); for (j = 0; j < lexicon[i].value_count; j ++) { lexicon[i].value[j].cursor = lexicon_cursor; lexicon[i].value[j].pointer = tlexicon[i].value[j]; lexicon_cursor += ucs4len(tlexicon[i].value[j]) + 1; } } lexicon_cursor_end = lexicon_cursor; }
void init(const char * filename) { dictionary_group_t dictionary_group = dictionary_group_open(); if (dictionary_group_load(dictionary_group, filename, OPENCC_DICTIONARY_TYPE_TEXT) == -1) { dictionary_perror("Dictionary loading error"); fprintf(stderr, _("\n")); exit(1); } dictionary_t t_dictionary = dictionary_group_get_dictionary(dictionary_group, 0); if (t_dictionary == (dictionary_t) -1) { dictionary_perror("Dictionary loading error"); fprintf(stderr, _("\n")); exit(1); } static opencc_entry tlexicon[DATRIE_WORD_MAX_COUNT]; /* TODO add datrie support */ dictionary_t dictionary = dictionary_get(t_dictionary); lexicon_count = dictionary_text_get_lexicon(dictionary, tlexicon); qsort(tlexicon, lexicon_count, sizeof(tlexicon[0]), cmp); size_t i; lexicon[0].pos = 0; for (i = 0; i < lexicon_count; i ++) { lexicon[i].key = tlexicon[i].key; lexicon[i].value = tlexicon[i].value; lexicon[i].length = ucs4len(lexicon[i].key); if (i > 0) { lexicon[i].pos = lexicon[i-1].pos + ucs4len(lexicon[i-1].value) + 1; } } }