From bf657efc00bdb1ffb8a57baf2674a828092f9e44 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 17 Apr 2012 14:32:33 +0800 Subject: [PATCH] remove old code --- src/pinyin.cpp | 124 --------------------------------------------------------- 1 file changed, 124 deletions(-) diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 5985a43..3c87122 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -492,130 +492,6 @@ bool pinyin_in_chewing_keyboard(pinyin_instance_t * instance, (context->m_options, key, symbol); } -#if 0 - -static gint compare_token( gconstpointer lhs, gconstpointer rhs){ - phrase_token_t token_lhs = *((phrase_token_t *)lhs); - phrase_token_t token_rhs = *((phrase_token_t *)rhs); - return token_lhs - token_rhs; -} - -/* internal definition */ -typedef struct { - pinyin_context_t * m_context; - ChewingKey * m_pinyin_keys; -} compare_context; - -static gint compare_token_with_unigram_freq(gconstpointer lhs, - gconstpointer rhs, - gpointer user_data){ - phrase_token_t token_lhs = *((phrase_token_t *)lhs); - phrase_token_t token_rhs = *((phrase_token_t *)rhs); - compare_context * context = (compare_context *)user_data; - FacadePhraseIndex * phrase_index = context->m_context->m_phrase_index; - pinyin_option_t options = context->m_context->m_options; - ChewingKey * pinyin_keys = context->m_pinyin_keys; - - PhraseItem item; - phrase_index->get_phrase_item(token_lhs, item); - guint32 freq_lhs = item.get_unigram_frequency() * - item.get_pronunciation_possibility(options, pinyin_keys) * 256; - phrase_index->get_phrase_item(token_rhs, item); - guint32 freq_rhs = item.get_unigram_frequency() * - item.get_pronunciation_possibility(options, pinyin_keys) * 256; - - return -(freq_lhs - freq_rhs); /* in descendant order */ -} - -bool pinyin_get_candidates(pinyin_instance_t * instance, - size_t offset, - TokenVector candidates){ - - pinyin_context_t * & context = instance->m_context; - ChewingKeyVector & pinyin_keys = instance->m_pinyin_keys; - g_array_set_size(candidates, 0); - - ChewingKey * keys = &g_array_index - (pinyin_keys, ChewingKey, offset); - size_t pinyin_len = pinyin_keys->len - offset; - - compare_context comp_context; - comp_context.m_context = context; - comp_context.m_pinyin_keys = keys; - - PhraseIndexRanges ranges; - memset(ranges, 0, sizeof(ranges)); - - guint8 min_index, max_index; - assert( ERROR_OK == context->m_phrase_index-> - get_sub_phrase_range(min_index, max_index)); - - for (size_t m = min_index; m <= max_index; ++m) { - ranges[m] = g_array_new(FALSE, FALSE, sizeof(PhraseIndexRange)); - } - - GArray * tokens = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); - - for (ssize_t i = pinyin_len; i >= 1; --i) { - g_array_set_size(tokens, 0); - - /* clear ranges. */ - for ( size_t m = min_index; m <= max_index; ++m ) { - g_array_set_size(ranges[m], 0); - } - - /* do pinyin search. */ - int retval = context->m_pinyin_table->search - (i, keys, ranges); - - if ( !(retval & SEARCH_OK) ) - continue; - - /* reduce to a single GArray. */ - for (size_t m = min_index; m <= max_index; ++m) { - for (size_t n = 0; n < ranges[m]->len; ++n) { - PhraseIndexRange * range = - &g_array_index(ranges[m], PhraseIndexRange, n); - for (size_t k = range->m_range_begin; - k < range->m_range_end; ++k) { - g_array_append_val(tokens, k); - } - } - } - - g_array_sort(tokens, compare_token); - /* remove the duplicated items. */ - phrase_token_t last_token = null_token; - for ( size_t n = 0; n < tokens->len; ++n) { - phrase_token_t token = g_array_index(tokens, phrase_token_t, n); - if ( last_token == token ){ - g_array_remove_index(tokens, n); - n--; - } - last_token = token; - } - - /* sort the candidates of the same length by uni-gram freqs. */ - g_array_sort_with_data(tokens, compare_token_with_unigram_freq, - &comp_context); - - /* copy out candidates. */ - g_array_append_vals(candidates, tokens->data, tokens->len); - - if ( !(retval & SEARCH_CONTINUED) ) - break; - } - - g_array_free(tokens, TRUE); - for (size_t m = min_index; m <= max_index; ++m) { - g_array_free(ranges[m], TRUE); - } - - return true; -} - -#endif - /* internal definition */ typedef struct _compare_item_t{ phrase_token_t m_token; -- 2.7.4