Esempio n. 1
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;
}
Esempio n. 2
0
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;
		}
	}
}