diff options
-rw-r--r-- | src/include/novel_types.h | 2 | ||||
-rw-r--r-- | src/lookup/lookup.cpp | 6 | ||||
-rw-r--r-- | src/lookup/lookup.h | 2 | ||||
-rw-r--r-- | src/lookup/phonetic_lookup.cpp | 4 | ||||
-rw-r--r-- | src/lookup/phonetic_lookup.h | 20 | ||||
-rw-r--r-- | src/lookup/phrase_lookup.cpp | 14 | ||||
-rw-r--r-- | src/lookup/phrase_lookup.h | 8 | ||||
-rw-r--r-- | src/lookup/pinyin_lookup2.cpp | 22 | ||||
-rw-r--r-- | src/lookup/pinyin_lookup2.h | 16 | ||||
-rw-r--r-- | src/pinyin.cpp | 4 | ||||
-rw-r--r-- | tests/lookup/test_phrase_lookup.cpp | 12 | ||||
-rw-r--r-- | tests/lookup/test_pinyin_lookup.cpp | 12 | ||||
-rw-r--r-- | utils/segment/ngseg.cpp | 10 |
13 files changed, 66 insertions, 66 deletions
diff --git a/src/include/novel_types.h b/src/include/novel_types.h index 66c2477..d9d9e65 100644 --- a/src/include/novel_types.h +++ b/src/include/novel_types.h @@ -135,7 +135,7 @@ typedef GArray * ChewingKeyRestVector; /* Array of phrase_token_t */ typedef GArray * TokenVector; -typedef TokenVector MatchResults; +typedef TokenVector MatchResult; /* Array of lookup_constraint_t */ typedef GArray * CandidateConstraints; diff --git a/src/lookup/lookup.cpp b/src/lookup/lookup.cpp index e5bae85..ac3d705 100644 --- a/src/lookup/lookup.cpp +++ b/src/lookup/lookup.cpp @@ -25,7 +25,7 @@ namespace pinyin{ bool convert_to_utf8(FacadePhraseIndex * phrase_index, - MatchResults match_results, + MatchResult result, /* in */ const char * delimiter, /* in */ bool show_tokens, /* out */ char * & result_string){ @@ -36,9 +36,9 @@ bool convert_to_utf8(FacadePhraseIndex * phrase_index, PhraseItem item; - for ( size_t i = 0; i < match_results->len; ++i ){ + for ( size_t i = 0; i < result->len; ++i ){ phrase_token_t token = g_array_index - (match_results, phrase_token_t, i); + (result, phrase_token_t, i); if ( null_token == token ) continue; diff --git a/src/lookup/lookup.h b/src/lookup/lookup.h index 27a426a..47fe204 100644 --- a/src/lookup/lookup.h +++ b/src/lookup/lookup.h @@ -73,7 +73,7 @@ typedef GHashTable * LookupStepIndex; typedef GArray * LookupStepContent; /* array of lookup_value_t */ bool convert_to_utf8(FacadePhraseIndex * phrase_index, - MatchResults match_results, + MatchResult match_result, /* in */ const char * delimiter, /* in */ bool show_tokens, /* out */ char * & result_string); diff --git a/src/lookup/phonetic_lookup.cpp b/src/lookup/phonetic_lookup.cpp index 5c3a6ce..417ee9f 100644 --- a/src/lookup/phonetic_lookup.cpp +++ b/src/lookup/phonetic_lookup.cpp @@ -172,8 +172,8 @@ bool ForwardPhoneticConstraints::validate_constraint(PhoneticKeyMatrix * matrix) } -bool ForwardPhoneticConstraints::diff_result(MatchResults best, - MatchResults other){ +bool ForwardPhoneticConstraints::diff_result(MatchResult best, + MatchResult other){ bool changed = false; assert(best->len == other->len); diff --git a/src/lookup/phonetic_lookup.h b/src/lookup/phonetic_lookup.h index f1fdae0..9a147ed 100644 --- a/src/lookup/phonetic_lookup.h +++ b/src/lookup/phonetic_lookup.h @@ -366,7 +366,7 @@ public: template <gint32 nbest> bool extract_result(const ForwardPhoneticTrellis<nbest> * trellis, const trellis_value_t * tail, - /* out */ MatchResults & result) { + /* out */ MatchResult & result) { /* reset result */ g_array_set_size(result, trellis->size()); for (size_t i = 0; i < result->len; ++i){ @@ -445,7 +445,7 @@ public: return true; } - bool diff_result(MatchResults best, MatchResults other); + bool diff_result(MatchResult best, MatchResult other); }; @@ -469,19 +469,19 @@ public: return m_results->len; } - bool get_result(size_t index, MatchResults & result) const { + bool get_result(size_t index, MatchResult & result) const { if (index >= m_results->len) return false; - result = (MatchResults) g_ptr_array_index(m_results, index); + result = (MatchResult) g_ptr_array_index(m_results, index); return true; } bool clear() { /* free m_results */ for (size_t i = 0; i < m_results->len; ++i) { - MatchResults array = - (MatchResults) g_ptr_array_index(m_results, i); + MatchResult array = + (MatchResult) g_ptr_array_index(m_results, i); g_array_free(array, TRUE); } g_ptr_array_set_size(m_results, 0); @@ -490,8 +490,8 @@ public: } /* copy result here */ - bool add_result(MatchResults result) { - MatchResults array = g_array_new + bool add_result(MatchResult result) { + MatchResult array = g_array_new (TRUE, TRUE, sizeof(phrase_token_t)); g_array_append_vals(array, result->data, result->len); @@ -812,7 +812,7 @@ public: GPtrArray * tails = g_ptr_array_new(); m_trellis.get_tails(tails); - MatchResults result = g_array_new + MatchResult result = g_array_new (TRUE, TRUE, sizeof(phrase_token_t)); for (size_t i = 0; i < tails->len; ++i) { const trellis_value_t * tail = (const trellis_value_t *) @@ -830,7 +830,7 @@ public: bool train_result3(const PhoneticKeyMatrix * matrix, const ForwardPhoneticConstraints * constraints, - MatchResults result) { + MatchResult result) { const guint32 initial_seed = 23 * 3; const guint32 expand_factor = 2; const guint32 unigram_factor = 7; diff --git a/src/lookup/phrase_lookup.cpp b/src/lookup/phrase_lookup.cpp index 662d788..d42e069 100644 --- a/src/lookup/phrase_lookup.cpp +++ b/src/lookup/phrase_lookup.cpp @@ -117,7 +117,7 @@ PhraseLookup::~PhraseLookup(){ } bool PhraseLookup::get_best_match(int sentence_length, ucs4_t sentence[], - MatchResults & results){ + MatchResult & result){ m_sentence_length = sentence_length; m_sentence = sentence; int nstep = m_sentence_length + 1; @@ -154,7 +154,7 @@ bool PhraseLookup::get_best_match(int sentence_length, ucs4_t sentence[], m_phrase_index->destroy_tokens(tokens); - return final_step(results); + return final_step(result); } #if 0 @@ -379,12 +379,12 @@ bool PhraseLookup::save_next_step(int next_step_pos, lookup_value_t * cur_value, } } -bool PhraseLookup::final_step(MatchResults & results ){ +bool PhraseLookup::final_step(MatchResult & result){ /* reset results */ - g_array_set_size(results, m_steps_content->len - 1); - for ( size_t i = 0; i < results->len; ++i ){ - phrase_token_t * token = &g_array_index(results, phrase_token_t, i); + g_array_set_size(result, m_steps_content->len - 1); + for ( size_t i = 0; i < result->len; ++i ){ + phrase_token_t * token = &g_array_index(result, phrase_token_t, i); *token = null_token; } @@ -411,7 +411,7 @@ bool PhraseLookup::final_step(MatchResults & results ){ break; phrase_token_t * token = &g_array_index - (results, phrase_token_t, cur_step_pos); + (result, phrase_token_t, cur_step_pos); *token = max_value->m_handles[1]; phrase_token_t last_token = max_value->m_handles[0]; diff --git a/src/lookup/phrase_lookup.h b/src/lookup/phrase_lookup.h index b744854..df6a55d 100644 --- a/src/lookup/phrase_lookup.h +++ b/src/lookup/phrase_lookup.h @@ -76,7 +76,7 @@ protected: bool save_next_step(int next_step_pos, lookup_value_t * cur_value, lookup_value_t * next_step); - bool final_step(MatchResults & results); + bool final_step(MatchResult & result); public: /** * PhraseLookup::PhraseLookup: @@ -115,7 +115,7 @@ public: * Note: this method only accepts the characters in phrase large table. * */ - bool get_best_match(int sentence_length, ucs4_t sentence[], MatchResults & results); + bool get_best_match(int sentence_length, ucs4_t sentence[], MatchResult & result); /** * PhraseLookup::convert_to_utf8: @@ -128,10 +128,10 @@ public: * Note: free the result_string by g_free. * */ - bool convert_to_utf8(MatchResults results, + bool convert_to_utf8(MatchResult result, /* out */ char * & result_string) { - return pinyin::convert_to_utf8(m_phrase_index, results, + return pinyin::convert_to_utf8(m_phrase_index, result, "\n", true, result_string); } }; diff --git a/src/lookup/pinyin_lookup2.cpp b/src/lookup/pinyin_lookup2.cpp index c72bc86..bb3d053 100644 --- a/src/lookup/pinyin_lookup2.cpp +++ b/src/lookup/pinyin_lookup2.cpp @@ -218,7 +218,7 @@ PinyinLookup2::~PinyinLookup2(){ bool PinyinLookup2::get_best_match(TokenVector prefixes, PhoneticKeyMatrix * matrix, CandidateConstraints constraints, - MatchResults & results){ + MatchResult & result){ m_constraints = constraints; m_matrix = matrix; @@ -304,7 +304,7 @@ bool PinyinLookup2::get_best_match(TokenVector prefixes, g_ptr_array_free(candidates, TRUE); g_ptr_array_free(topresults, TRUE); - return final_step(results); + return final_step(result); } bool PinyinLookup2::search_unigram2(GPtrArray * topresults, @@ -507,12 +507,12 @@ bool PinyinLookup2::save_next_step(int next_step_pos, } } -bool PinyinLookup2::final_step(MatchResults & results){ +bool PinyinLookup2::final_step(MatchResult & result){ - /* reset results */ - g_array_set_size(results, m_steps_content->len); - for (size_t i = 0; i < results->len; ++i){ - phrase_token_t * token = &g_array_index(results, phrase_token_t, i); + /* reset result */ + g_array_set_size(result, m_steps_content->len); + for (size_t i = 0; i < result->len; ++i){ + phrase_token_t * token = &g_array_index(result, phrase_token_t, i); *token = null_token; } @@ -539,7 +539,7 @@ bool PinyinLookup2::final_step(MatchResults & results){ break; phrase_token_t * token = &g_array_index - (results, phrase_token_t, cur_step_pos); + (result, phrase_token_t, cur_step_pos); *token = max_value->m_handles[1]; phrase_token_t last_token = max_value->m_handles[0]; @@ -565,7 +565,7 @@ bool PinyinLookup2::final_step(MatchResults & results){ bool PinyinLookup2::train_result2(PhoneticKeyMatrix * matrix, CandidateConstraints constraints, - MatchResults results) { + MatchResult result) { const guint32 initial_seed = 23 * 3; const guint32 expand_factor = 2; const guint32 unigram_factor = 7; @@ -578,7 +578,7 @@ bool PinyinLookup2::train_result2(PhoneticKeyMatrix * matrix, phrase_token_t last_token = sentence_start; for (size_t i = 0; i < constraints->len; ++i) { - phrase_token_t token = g_array_index(results, phrase_token_t, i); + phrase_token_t token = g_array_index(result, phrase_token_t, i); if (null_token == token) continue; @@ -633,7 +633,7 @@ bool PinyinLookup2::train_result2(PhoneticKeyMatrix * matrix, guint next_pos = i + 1; for (; next_pos < constraints->len; ++next_pos) { phrase_token_t next_token = g_array_index - (results, phrase_token_t, next_pos); + (result, phrase_token_t, next_pos); if (null_token != next_token) break; diff --git a/src/lookup/pinyin_lookup2.h b/src/lookup/pinyin_lookup2.h index bd3d774..7a21966 100644 --- a/src/lookup/pinyin_lookup2.h +++ b/src/lookup/pinyin_lookup2.h @@ -125,7 +125,7 @@ protected: bool save_next_step(int next_step_pos, lookup_value_t * cur_step, lookup_value_t * next_step); - bool final_step(MatchResults & results); + bool final_step(MatchResult & result); public: /** @@ -158,7 +158,7 @@ public: * @prefixes: the phrase tokens before the guessed sentence. * @matrix: the matrix of the pinyin keys. * @constraints: the constraints on the guessed sentence. - * @results: the guessed sentence in the form of the phrase tokens. + * @result: the guessed sentence in the form of the phrase tokens. * @returns: whether the guess operation is successful. * * Guess the best sentence according to user inputs. @@ -167,13 +167,13 @@ public: bool get_best_match(TokenVector prefixes, PhoneticKeyMatrix * matrix, CandidateConstraints constraints, - MatchResults & results); + MatchResult & result); /** * PinyinLookup2::train_result2: * @matrix: the matrix of the pinyin keys. * @constraints: the constraints on the guessed sentence. - * @results: the guessed sentence in the form of the phrase tokens. + * @result: the guessed sentence in the form of the phrase tokens. * @returns: whether the train operation is successful. * * Self learning the guessed sentence based on the constraints. @@ -181,21 +181,21 @@ public: */ bool train_result2(PhoneticKeyMatrix * matrix, CandidateConstraints constraints, - MatchResults results); + MatchResult result); /** * PinyinLookup2::convert_to_utf8: - * @results: the guessed sentence in the form of the phrase tokens. + * @result: the guessed sentence in the form of the phrase tokens. * @result_string: the guessed sentence in the utf8 encoding. * @returns: whether the convert operation is successful. * * Convert the guessed sentence from the phrase tokens to the utf8 string. * */ - bool convert_to_utf8(MatchResults results, + bool convert_to_utf8(MatchResult result, /* out */ char * & result_string) { - return pinyin::convert_to_utf8(m_phrase_index, results, + return pinyin::convert_to_utf8(m_phrase_index, result, NULL, false, result_string); } diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 88dd8d6..fb451a1 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -77,7 +77,7 @@ struct _pinyin_instance_t{ /* cached pinyin lookup variables. */ CandidateConstraints m_constraints; - MatchResults m_match_results; + MatchResult m_match_results; CandidateVector m_candidates; }; @@ -2609,7 +2609,7 @@ bool pinyin_get_n_phrase(pinyin_instance_t * instance, bool pinyin_get_phrase_token(pinyin_instance_t * instance, guint index, phrase_token_t * token){ - MatchResults & match_results = instance->m_match_results; + MatchResult & match_results = instance->m_match_results; *token = null_token; diff --git a/tests/lookup/test_phrase_lookup.cpp b/tests/lookup/test_phrase_lookup.cpp index 3a475b9..408b0eb 100644 --- a/tests/lookup/test_phrase_lookup.cpp +++ b/tests/lookup/test_phrase_lookup.cpp @@ -32,23 +32,23 @@ bool try_phrase_lookup(PhraseLookup * phrase_lookup, ucs4_t * ucs4_str, glong ucs4_len){ char * result_string = NULL; - MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); - phrase_lookup->get_best_match(ucs4_len, ucs4_str, results); + MatchResult result = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); + phrase_lookup->get_best_match(ucs4_len, ucs4_str, result); #if 0 - for ( size_t i = 0; i < results->len; ++i) { - phrase_token_t * token = &g_array_index(results, phrase_token_t, i); + for (size_t i = 0; i < result->len; ++i) { + phrase_token_t * token = &g_array_index(result, phrase_token_t, i); if ( *token == null_token ) continue; printf("%d:%d\t", i, *token); } printf("\n"); #endif - phrase_lookup->convert_to_utf8(results, result_string); + phrase_lookup->convert_to_utf8(result, result_string); if (result_string) printf("%s\n", result_string); else fprintf(stderr, "Error: Un-segmentable sentence encountered!\n"); - g_array_free(results, TRUE); + g_array_free(result, TRUE); g_free(result_string); return true; } diff --git a/tests/lookup/test_pinyin_lookup.cpp b/tests/lookup/test_pinyin_lookup.cpp index b0af455..8a1647d 100644 --- a/tests/lookup/test_pinyin_lookup.cpp +++ b/tests/lookup/test_pinyin_lookup.cpp @@ -70,7 +70,7 @@ int main( int argc, char * argv[]){ CandidateConstraints constraints = g_array_new (TRUE, FALSE, sizeof(lookup_constraint_t)); - MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); + MatchResult result = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); char* linebuf = NULL; size_t size = 0; ssize_t read; while( (read = getline(&linebuf, &size, stdin)) != -1 ){ @@ -113,11 +113,11 @@ int main( int argc, char * argv[]){ guint32 start_time = record_time(); for (size_t i = 0; i < bench_times; ++i) - pinyin_lookup.get_best_match(prefixes, &matrix, constraints, results); + pinyin_lookup.get_best_match(prefixes, &matrix, constraints, result); print_time(start_time, bench_times); - for (size_t i = 0; i < results->len; ++i){ - phrase_token_t * token = &g_array_index(results, phrase_token_t, i); + for (size_t i = 0; i < result->len; ++i){ + phrase_token_t * token = &g_array_index(result, phrase_token_t, i); if ( null_token == *token) continue; printf("pos:%ld,token:%d\t", i, *token); @@ -125,7 +125,7 @@ int main( int argc, char * argv[]){ printf("\n"); char * sentence = NULL; - pinyin_lookup.convert_to_utf8(results, sentence); + pinyin_lookup.convert_to_utf8(result, sentence); printf("%s\n", sentence); g_array_free(keys, TRUE); @@ -135,7 +135,7 @@ int main( int argc, char * argv[]){ g_array_free(prefixes, TRUE); g_array_free(constraints, TRUE); - g_array_free(results, TRUE); + g_array_free(result, TRUE); free(linebuf); return 0; diff --git a/utils/segment/ngseg.cpp b/utils/segment/ngseg.cpp index dcc3c05..32c56f5 100644 --- a/utils/segment/ngseg.cpp +++ b/utils/segment/ngseg.cpp @@ -68,11 +68,11 @@ bool deal_with_segmentable(PhraseLookup * phrase_lookup, GArray * current_ucs4, FILE * output){ char * result_string = NULL; - MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); + MatchResult result = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); phrase_lookup->get_best_match(current_ucs4->len, - (ucs4_t *) current_ucs4->data, results); + (ucs4_t *) current_ucs4->data, result); - phrase_lookup->convert_to_utf8(results, result_string); + phrase_lookup->convert_to_utf8(result, result_string); if (result_string) { fprintf(output, "%s\n", result_string); @@ -82,10 +82,10 @@ bool deal_with_segmentable(PhraseLookup * phrase_lookup, NULL, NULL, NULL); fprintf(stderr, "Un-segmentable sentence encountered:%s\n", tmp_string); - g_array_free(results, TRUE); + g_array_free(result, TRUE); return false; } - g_array_free(results, TRUE); + g_array_free(result, TRUE); g_free(result_string); return true; } |