diff options
Diffstat (limited to 'utils/training')
-rw-r--r-- | utils/training/estimate_interpolation.cpp | 4 | ||||
-rw-r--r-- | utils/training/estimate_k_mixture_model.cpp | 10 | ||||
-rw-r--r-- | utils/training/eval_correction_rate.cpp | 6 | ||||
-rw-r--r-- | utils/training/export_k_mixture_model.cpp | 4 | ||||
-rw-r--r-- | utils/training/gen_deleted_ngram.cpp | 4 | ||||
-rw-r--r-- | utils/training/gen_k_mixture_model.cpp | 54 | ||||
-rw-r--r-- | utils/training/gen_ngram.cpp | 4 | ||||
-rw-r--r-- | utils/training/import_k_mixture_model.cpp | 40 | ||||
-rw-r--r-- | utils/training/k_mixture_model.h | 2 | ||||
-rw-r--r-- | utils/training/k_mixture_model_to_interpolation.cpp | 28 | ||||
-rw-r--r-- | utils/training/merge_k_mixture_model.cpp | 16 | ||||
-rw-r--r-- | utils/training/prune_k_mixture_model.cpp | 8 | ||||
-rw-r--r-- | utils/training/validate_k_mixture_model.cpp | 6 |
13 files changed, 93 insertions, 93 deletions
diff --git a/utils/training/estimate_interpolation.cpp b/utils/training/estimate_interpolation.cpp index a0e1dc6..089eadc 100644 --- a/utils/training/estimate_interpolation.cpp +++ b/utils/training/estimate_interpolation.cpp @@ -55,7 +55,7 @@ parameter_t compute_interpolation(SingleGram * deleted_bigram, parameter_t elem_poss = 0; if (bigram && bigram->get_freq(token, freq)){ guint32 total_freq; - assert(bigram->get_total_freq(total_freq)); + check_result(bigram->get_total_freq(total_freq)); assert(0 != total_freq); elem_poss = freq / (parameter_t) total_freq; } @@ -78,7 +78,7 @@ parameter_t compute_interpolation(SingleGram * deleted_bigram, next_lambda += deleted_count * (numerator / (numerator + part_of_denominator)); } - assert(deleted_bigram->get_total_freq(table_num)); + check_result(deleted_bigram->get_total_freq(table_num)); next_lambda /= table_num; g_array_free(array, TRUE); diff --git a/utils/training/estimate_k_mixture_model.cpp b/utils/training/estimate_k_mixture_model.cpp index 779f67d..f5c5777 100644 --- a/utils/training/estimate_k_mixture_model.cpp +++ b/utils/training/estimate_k_mixture_model.cpp @@ -41,7 +41,7 @@ parameter_t compute_interpolation(KMixtureModelSingleGram * deleted_bigram, parameter_t epsilon = 0.001; KMixtureModelMagicHeader magic_header; - assert(unigram->get_magic_header(magic_header)); + check_result(unigram->get_magic_header(magic_header)); assert(0 != magic_header.m_total_freq); while (fabs(lambda - next_lambda) > epsilon){ @@ -64,7 +64,7 @@ parameter_t compute_interpolation(KMixtureModelSingleGram * deleted_bigram, KMixtureModelArrayHeader array_header; KMixtureModelArrayItem array_item; if ( bigram && bigram->get_array_item(token, array_item) ){ - assert(bigram->get_array_header(array_header)); + check_result(bigram->get_array_header(array_header)); assert(0 != array_header.m_WC); elem_poss = array_item.m_WC / (parameter_t) array_header.m_WC; } @@ -85,7 +85,7 @@ parameter_t compute_interpolation(KMixtureModelSingleGram * deleted_bigram, next_lambda += deleted_count * (numerator / (numerator + part_of_denominator)); } KMixtureModelArrayHeader header; - assert(deleted_bigram->get_array_header(header)); + check_result(deleted_bigram->get_array_header(header)); assert(0 != header.m_WC); next_lambda /= header.m_WC; @@ -131,9 +131,9 @@ int main(int argc, char * argv[]){ KMixtureModelArrayHeader array_header; if (single_gram) - assert(single_gram->get_array_header(array_header)); + check_result(single_gram->get_array_header(array_header)); KMixtureModelArrayHeader deleted_array_header; - assert(deleted_single_gram->get_array_header(deleted_array_header)); + check_result(deleted_single_gram->get_array_header(deleted_array_header)); if ( 0 != deleted_array_header.m_WC ) { parameter_t lambda = compute_interpolation(deleted_single_gram, &bigram, single_gram); diff --git a/utils/training/eval_correction_rate.cpp b/utils/training/eval_correction_rate.cpp index aa33e6b..d795c0d 100644 --- a/utils/training/eval_correction_rate.cpp +++ b/utils/training/eval_correction_rate.cpp @@ -45,14 +45,14 @@ bool get_possible_pinyin(FacadePhraseIndex * phrase_index, key_index = 0; max_freq = 0; for ( size_t m = 0; m < item.get_n_pronunciation(); ++m ) { freq = 0; - assert(item.get_nth_pronunciation(m, buffer, freq)); + check_result(item.get_nth_pronunciation(m, buffer, freq)); if ( freq > max_freq ) { key_index = m; max_freq = freq; } } - assert(item.get_nth_pronunciation(key_index, buffer, freq)); + check_result(item.get_nth_pronunciation(key_index, buffer, freq)); assert(max_freq == freq); guint8 len = item.get_phrase_length(); g_array_append_vals(keys, buffer, len); @@ -105,7 +105,7 @@ bool do_one_test(PhoneticLookup<1, 1> * pinyin_lookup, get_best_match(phrase_index, pinyin_lookup, &matrix, &results); assert(1 == results.size()); - assert(results.get_result(0, guessed_tokens)); + check_result(results.get_result(0, guessed_tokens)); /* compare the results */ char * sentence = NULL; char * guessed_sentence = NULL; diff --git a/utils/training/export_k_mixture_model.cpp b/utils/training/export_k_mixture_model.cpp index fe11cb6..8466d3b 100644 --- a/utils/training/export_k_mixture_model.cpp +++ b/utils/training/export_k_mixture_model.cpp @@ -55,7 +55,7 @@ bool print_k_mixture_model_array_headers(FILE * output, for (size_t i = 0; i < items->len; ++i) { phrase_token_t token = g_array_index(items, phrase_token_t, i); KMixtureModelArrayHeader array_header; - assert(bigram->get_array_header(token, array_header)); + check_result(bigram->get_array_header(token, array_header)); char * phrase = taglib_token_to_string(phrase_index, token); if ( phrase ) fprintf(output, "\\item %d %s count %d freq %d\n", @@ -76,7 +76,7 @@ bool print_k_mixture_model_array_items(FILE * output, for (size_t i = 0; i < items->len; ++i) { phrase_token_t token = g_array_index(items, phrase_token_t, i); KMixtureModelSingleGram * single_gram = NULL; - assert(bigram->load(token, single_gram)); + check_result(bigram->load(token, single_gram)); FlexibleBigramPhraseArray array = g_array_new (FALSE, FALSE, sizeof(KMixtureModelArrayItemWithToken)); single_gram->retrieve_all(array); diff --git a/utils/training/gen_deleted_ngram.cpp b/utils/training/gen_deleted_ngram.cpp index 9f61bd7..074c198 100644 --- a/utils/training/gen_deleted_ngram.cpp +++ b/utils/training/gen_deleted_ngram.cpp @@ -109,9 +109,9 @@ int main(int argc, char * argv[]){ guint32 freq, total_freq; //increase freq if (single_gram->get_freq(cur_token, freq)) - assert(single_gram->set_freq(cur_token, freq + 1)); + check_result(single_gram->set_freq(cur_token, freq + 1)); else - assert(single_gram->insert_freq(cur_token, 1)); + check_result(single_gram->insert_freq(cur_token, 1)); //increase total freq single_gram->get_total_freq(total_freq); single_gram->set_total_freq(total_freq + 1); diff --git a/utils/training/gen_k_mixture_model.cpp b/utils/training/gen_k_mixture_model.cpp index b4066d0..4595433 100644 --- a/utils/training/gen_k_mixture_model.cpp +++ b/utils/training/gen_k_mixture_model.cpp @@ -156,19 +156,19 @@ static void train_word_pair(HashofUnigram hash_of_unigram, */ if ( count > maximum_occurs_allowed ){ gpointer value = NULL; - assert( g_hash_table_lookup_extended - (hash_of_unigram, GUINT_TO_POINTER(token2), - NULL, &value) ); + check_result(g_hash_table_lookup_extended + (hash_of_unigram, GUINT_TO_POINTER(token2), + NULL, &value)); guint32 freq = GPOINTER_TO_UINT(value); freq -= count; if ( freq > 0 ) { g_hash_table_insert(hash_of_unigram, GUINT_TO_POINTER(token2), GUINT_TO_POINTER(freq)); } else if ( freq == 0 ) { - assert(g_hash_table_steal(hash_of_unigram, - GUINT_TO_POINTER(token2))); + check_result(g_hash_table_steal(hash_of_unigram, + GUINT_TO_POINTER(token2))); } else { - assert(false); + assert(FALSE); } return; } @@ -178,24 +178,24 @@ static void train_word_pair(HashofUnigram hash_of_unigram, if ( 1 == count ) array_item.m_n_1 ++; array_item.m_Mr = std_lite::max(array_item.m_Mr, count); - assert(single_gram->set_array_item(token2, array_item)); + check_result(single_gram->set_array_item(token2, array_item)); } else { /* item doesn't exist. */ /* the same as above. */ if ( count > g_maximum_occurs ){ gpointer value = NULL; - assert( g_hash_table_lookup_extended - (hash_of_unigram, GUINT_TO_POINTER(token2), - NULL, &value) ); + check_result(g_hash_table_lookup_extended + (hash_of_unigram, GUINT_TO_POINTER(token2), + NULL, &value)); guint32 freq = GPOINTER_TO_UINT(value); freq -= count; if ( freq > 0 ) { g_hash_table_insert(hash_of_unigram, GUINT_TO_POINTER(token2), GUINT_TO_POINTER(freq)); } else if ( freq == 0 ) { - assert(g_hash_table_steal(hash_of_unigram, - GUINT_TO_POINTER(token2))); + check_result(g_hash_table_steal(hash_of_unigram, + GUINT_TO_POINTER(token2))); } else { - assert(false); + assert(FALSE); } return; } @@ -206,7 +206,7 @@ static void train_word_pair(HashofUnigram hash_of_unigram, if ( 1 == count ) array_item.m_n_1 = 1; array_item.m_Mr = count; - assert(single_gram->insert_array_item(token2, array_item)); + check_result(single_gram->insert_array_item(token2, array_item)); } /* save delta in the array header. */ @@ -224,14 +224,14 @@ bool train_single_gram(HashofUnigram hash_of_unigram, assert(NULL != single_gram); delta = 0; /* delta in WC of single_gram. */ KMixtureModelArrayHeader array_header; - assert(single_gram->get_array_header(array_header)); + check_result(single_gram->get_array_header(array_header)); guint32 saved_array_header_WC = array_header.m_WC; HashofSecondWord hash_of_second_word = NULL; gpointer key, value = NULL; - assert(g_hash_table_lookup_extended - (hash_of_document, GUINT_TO_POINTER(token1), - NULL, &value)); + check_result(g_hash_table_lookup_extended + (hash_of_document, GUINT_TO_POINTER(token1), + NULL, &value)); hash_of_second_word = (HashofSecondWord) value; assert(NULL != hash_of_second_word); @@ -244,7 +244,7 @@ bool train_single_gram(HashofUnigram hash_of_unigram, train_word_pair(hash_of_unigram, single_gram, token2, count); } - assert(single_gram->get_array_header(array_header)); + check_result(single_gram->get_array_header(array_header)); delta = array_header.m_WC - saved_array_header_WC; return true; } @@ -268,7 +268,7 @@ static bool train_second_word(HashofUnigram hash_of_unigram, } /* save the single gram. */ - assert(bigram->store(token1, single_gram)); + check_result(bigram->store(token1, single_gram)); delete single_gram; KMixtureModelMagicHeader magic_header; @@ -282,7 +282,7 @@ static bool train_second_word(HashofUnigram hash_of_unigram, return false; } magic_header.m_WC += delta; - assert(bigram->set_magic_header(magic_header)); + check_result(bigram->set_magic_header(magic_header)); return true; } @@ -306,13 +306,13 @@ static bool post_processing_unigram(KMixtureModelBigram * bigram, } KMixtureModelMagicHeader magic_header; - assert(bigram->get_magic_header(magic_header)); + check_result(bigram->get_magic_header(magic_header)); if ( magic_header.m_total_freq + total_freq < magic_header.m_total_freq ){ fprintf(stderr, "the m_total_freq in magic header overflows.\n"); return false; } magic_header.m_total_freq += total_freq; - assert(bigram->set_magic_header(magic_header)); + check_result(bigram->set_magic_header(magic_header)); return true; } @@ -369,8 +369,8 @@ int main(int argc, char * argv[]){ HashofUnigram hash_of_unigram = g_hash_table_new (g_direct_hash, g_direct_equal); - assert(read_document(&phrase_table, &phrase_index, document, - hash_of_document, hash_of_unigram)); + check_result(read_document(&phrase_table, &phrase_index, document, + hash_of_document, hash_of_unigram)); fclose(document); document = NULL; @@ -386,9 +386,9 @@ int main(int argc, char * argv[]){ } KMixtureModelMagicHeader magic_header; - assert(bigram.get_magic_header(magic_header)); + check_result(bigram.get_magic_header(magic_header)); magic_header.m_N ++; - assert(bigram.set_magic_header(magic_header)); + check_result(bigram.set_magic_header(magic_header)); post_processing_unigram(&bigram, hash_of_unigram); diff --git a/utils/training/gen_ngram.cpp b/utils/training/gen_ngram.cpp index 9d9c643..3e73cbe 100644 --- a/utils/training/gen_ngram.cpp +++ b/utils/training/gen_ngram.cpp @@ -113,9 +113,9 @@ int main(int argc, char * argv[]){ guint32 freq, total_freq; /* increase freq */ if (single_gram->get_freq(cur_token, freq)) - assert(single_gram->set_freq(cur_token, freq + 1)); + check_result(single_gram->set_freq(cur_token, freq + 1)); else - assert(single_gram->insert_freq(cur_token, 1)); + check_result(single_gram->insert_freq(cur_token, 1)); /* increase total freq */ single_gram->get_total_freq(total_freq); single_gram->set_total_freq(total_freq + 1); diff --git a/utils/training/import_k_mixture_model.cpp b/utils/training/import_k_mixture_model.cpp index 1a34871..6503dbf 100644 --- a/utils/training/import_k_mixture_model.cpp +++ b/utils/training/import_k_mixture_model.cpp @@ -77,7 +77,7 @@ static ssize_t my_getline(FILE * input){ bool parse_headline(KMixtureModelBigram * bigram){ /* enter "\data" line */ - assert(taglib_add_tag(BEGIN_LINE, "\\data", 0, "model:count:N:total_freq", "")); + check_result(taglib_add_tag(BEGIN_LINE, "\\data", 0, "model:count:N:total_freq", "")); /* read "\data" line */ if ( !taglib_read(linebuf, line_type, values, required) ) { @@ -111,13 +111,13 @@ bool parse_body(FILE * input, PhraseLargeTable3 * phrase_table, KMixtureModelBigram * bigram){ taglib_push_state(); - assert(taglib_add_tag(END_LINE, "\\end", 0, "", "")); - assert(taglib_add_tag(GRAM_1_LINE, "\\1-gram", 0, "", "")); - assert(taglib_add_tag(GRAM_2_LINE, "\\2-gram", 0, "", "")); + check_result(taglib_add_tag(END_LINE, "\\end", 0, "", "")); + check_result(taglib_add_tag(GRAM_1_LINE, "\\1-gram", 0, "", "")); + check_result(taglib_add_tag(GRAM_2_LINE, "\\2-gram", 0, "", "")); do { retry: - assert(taglib_read(linebuf, line_type, values, required)); + check_result(taglib_read(linebuf, line_type, values, required)); switch(line_type) { case END_LINE: goto end; @@ -130,7 +130,7 @@ bool parse_body(FILE * input, PhraseLargeTable3 * phrase_table, parse_bigram(input, phrase_table, phrase_index, bigram); goto retry; default: - assert(false); + assert(FALSE); } } while (my_getline(input) != -1) ; @@ -144,17 +144,17 @@ bool parse_unigram(FILE * input, PhraseLargeTable3 * phrase_table, KMixtureModelBigram * bigram){ taglib_push_state(); - assert(taglib_add_tag(GRAM_1_ITEM_LINE, "\\item", 2, "count:freq", "")); + check_result(taglib_add_tag(GRAM_1_ITEM_LINE, "\\item", 2, "count:freq", "")); do { - assert(taglib_read(linebuf, line_type, values, required)); + check_result(taglib_read(linebuf, line_type, values, required)); switch (line_type) { case GRAM_1_ITEM_LINE:{ /* handle \item in \1-gram */ TAGLIB_GET_TOKEN(token, 0); TAGLIB_GET_PHRASE_STRING(word, 1); - assert(taglib_validate_token_with_string - (phrase_index, token, word)); + check_result(taglib_validate_token_with_string + (phrase_index, token, word)); TAGLIB_GET_TAGVALUE(glong, count, atol); TAGLIB_GET_TAGVALUE(glong, freq, atol); @@ -170,7 +170,7 @@ bool parse_unigram(FILE * input, PhraseLargeTable3 * phrase_table, case GRAM_2_LINE: goto end; default: - assert(false); + assert(FALSE); } } while (my_getline(input) != -1); @@ -184,26 +184,26 @@ bool parse_bigram(FILE * input, PhraseLargeTable3 * phrase_table, KMixtureModelBigram * bigram){ taglib_push_state(); - assert(taglib_add_tag(GRAM_2_ITEM_LINE, "\\item", 4, - "count:T:N_n_0:n_1:Mr", "")); + check_result(taglib_add_tag(GRAM_2_ITEM_LINE, "\\item", 4, + "count:T:N_n_0:n_1:Mr", "")); phrase_token_t last_token = null_token; KMixtureModelSingleGram * last_single_gram = NULL; do { - assert(taglib_read(linebuf, line_type, values, required)); + check_result(taglib_read(linebuf, line_type, values, required)); switch (line_type) { case GRAM_2_ITEM_LINE:{ /* handle \item in \2-gram */ /* two tokens */ TAGLIB_GET_TOKEN(token1, 0); TAGLIB_GET_PHRASE_STRING(word1, 1); - assert(taglib_validate_token_with_string - (phrase_index, token1, word1)); + check_result(taglib_validate_token_with_string + (phrase_index, token1, word1)); TAGLIB_GET_TOKEN(token2, 2); TAGLIB_GET_PHRASE_STRING(word2, 3); - assert(taglib_validate_token_with_string - (phrase_index, token2, word2)); + check_result(taglib_validate_token_with_string + (phrase_index, token2, word2)); TAGLIB_GET_TAGVALUE(glong, count, atol); TAGLIB_GET_TAGVALUE(glong, T, atol); @@ -236,7 +236,7 @@ bool parse_bigram(FILE * input, PhraseLargeTable3 * phrase_table, } assert(NULL != last_single_gram); - assert(last_single_gram->insert_array_item(token2, array_item)); + check_result(last_single_gram->insert_array_item(token2, array_item)); break; } case END_LINE: @@ -244,7 +244,7 @@ bool parse_bigram(FILE * input, PhraseLargeTable3 * phrase_table, case GRAM_2_LINE: goto end; default: - assert(false); + assert(FALSE); } } while (my_getline(input) != -1); diff --git a/utils/training/k_mixture_model.h b/utils/training/k_mixture_model.h index 5b7bfde..3e5eb32 100644 --- a/utils/training/k_mixture_model.h +++ b/utils/training/k_mixture_model.h @@ -79,7 +79,7 @@ static inline parameter_t compute_Pr_G_3(corpus_count_t k, return (alpha * gamma / (B - 1)) * pow((1 - 1 / (B - 1)) , k - 2); } - assert(false); + assert(FALSE); } static inline parameter_t compute_Pr_G_3_with_count(corpus_count_t k, diff --git a/utils/training/k_mixture_model_to_interpolation.cpp b/utils/training/k_mixture_model_to_interpolation.cpp index 4879ac7..3c425ac 100644 --- a/utils/training/k_mixture_model_to_interpolation.cpp +++ b/utils/training/k_mixture_model_to_interpolation.cpp @@ -58,8 +58,8 @@ static ssize_t my_getline(FILE * input){ bool parse_headline(FILE * input, FILE * output) { /* enter "\data" line */ - assert(taglib_add_tag(BEGIN_LINE, "\\data", 0, "model", - "count:N:total_freq")); + check_result(taglib_add_tag(BEGIN_LINE, "\\data", 0, "model", + "count:N:total_freq")); /* read "\data" line */ if ( !taglib_read(linebuf, line_type, values, required) ) { @@ -83,13 +83,13 @@ bool parse_headline(FILE * input, FILE * output) { bool parse_body(FILE * input, FILE * output){ taglib_push_state(); - assert(taglib_add_tag(END_LINE, "\\end", 0, "", "")); - assert(taglib_add_tag(GRAM_1_LINE, "\\1-gram", 0, "", "")); - assert(taglib_add_tag(GRAM_2_LINE, "\\2-gram", 0, "", "")); + check_result(taglib_add_tag(END_LINE, "\\end", 0, "", "")); + check_result(taglib_add_tag(GRAM_1_LINE, "\\1-gram", 0, "", "")); + check_result(taglib_add_tag(GRAM_2_LINE, "\\2-gram", 0, "", "")); do { retry: - assert(taglib_read(linebuf, line_type, values, required)); + check_result(taglib_read(linebuf, line_type, values, required)); switch(line_type) { case END_LINE: fprintf(output, "\\end\n"); @@ -105,7 +105,7 @@ bool parse_body(FILE * input, FILE * output){ parse_bigram(input, output); goto retry; default: - assert(false); + assert(FALSE); } } while (my_getline(input) != -1); @@ -117,10 +117,10 @@ bool parse_body(FILE * input, FILE * output){ bool parse_unigram(FILE * input, FILE * output){ taglib_push_state(); - assert(taglib_add_tag(GRAM_1_ITEM_LINE, "\\item", 2, "freq", "count")); + check_result(taglib_add_tag(GRAM_1_ITEM_LINE, "\\item", 2, "freq", "count")); do { - assert(taglib_read(linebuf, line_type, values, required)); + check_result(taglib_read(linebuf, line_type, values, required)); switch(line_type) { case GRAM_1_ITEM_LINE: { /* handle \item in \1-gram */ @@ -143,7 +143,7 @@ bool parse_unigram(FILE * input, FILE * output){ case GRAM_2_LINE: goto end; default: - assert(false); + assert(FALSE); } } while (my_getline(input) != -1); @@ -155,11 +155,11 @@ bool parse_unigram(FILE * input, FILE * output){ bool parse_bigram(FILE * input, FILE * output){ taglib_push_state(); - assert(taglib_add_tag(GRAM_2_ITEM_LINE, "\\item", 4, - "count", "T:N_n_0:n_1:Mr")); + check_result(taglib_add_tag(GRAM_2_ITEM_LINE, "\\item", 4, + "count", "T:N_n_0:n_1:Mr")); do { - assert(taglib_read(linebuf, line_type, values, required)); + check_result(taglib_read(linebuf, line_type, values, required)); switch (line_type) { case GRAM_2_ITEM_LINE:{ /* handle \item in \2-gram */ @@ -180,7 +180,7 @@ bool parse_bigram(FILE * input, FILE * output){ case GRAM_2_LINE: goto end; default: - assert(false); + assert(FALSE); } } while (my_getline(input) != -1); diff --git a/utils/training/merge_k_mixture_model.cpp b/utils/training/merge_k_mixture_model.cpp index 9554505..b27b4fd 100644 --- a/utils/training/merge_k_mixture_model.cpp +++ b/utils/training/merge_k_mixture_model.cpp @@ -104,7 +104,7 @@ static bool merge_magic_header( /* in & out */ KMixtureModelBigram * target, if (!target->get_magic_header(target_magic_header)) { memset(&target_magic_header, 0, sizeof(KMixtureModelMagicHeader)); } - assert(new_one->get_magic_header(new_magic_header)); + check_result(new_one->get_magic_header(new_magic_header)); if ( target_magic_header.m_WC + new_magic_header.m_WC < std_lite::max( target_magic_header.m_WC, new_magic_header.m_WC ) ){ fprintf(stderr, "the m_WC integer in magic header overflows.\n"); @@ -124,7 +124,7 @@ static bool merge_magic_header( /* in & out */ KMixtureModelBigram * target, merged_magic_header.m_total_freq = target_magic_header.m_total_freq + new_magic_header.m_total_freq; - assert(target->set_magic_header(merged_magic_header)); + check_result(target->set_magic_header(merged_magic_header)); return true; } @@ -139,7 +139,7 @@ static bool merge_array_items( /* in & out */ KMixtureModelBigram * target, KMixtureModelSingleGram * target_single_gram = NULL; KMixtureModelSingleGram * new_single_gram = NULL; - assert(new_one->load(*token, new_single_gram)); + check_result(new_one->load(*token, new_single_gram)); bool exists_in_target = target->load(*token, target_single_gram); if ( !exists_in_target ){ target->store(*token, new_single_gram); @@ -152,8 +152,8 @@ static bool merge_array_items( /* in & out */ KMixtureModelBigram * target, KMixtureModelArrayHeader new_array_header; KMixtureModelArrayHeader merged_array_header; - assert(new_one->get_array_header(*token, new_array_header)); - assert(target->get_array_header(*token, target_array_header)); + check_result(new_one->get_array_header(*token, new_array_header)); + check_result(target->get_array_header(*token, target_array_header)); memset(&merged_array_header, 0, sizeof(KMixtureModelArrayHeader)); merged_array_header.m_WC = target_array_header.m_WC + @@ -176,7 +176,7 @@ static bool merge_array_items( /* in & out */ KMixtureModelBigram * target, FlexibleBigramPhraseArray merged_array = g_array_new(FALSE, FALSE, sizeof(KMixtureModelArrayItemWithToken)); - assert(merge_two_phrase_array(target_array, new_array, merged_array)); + check_result(merge_two_phrase_array(target_array, new_array, merged_array)); g_array_free(target_array, TRUE); g_array_free(new_array, TRUE); @@ -189,8 +189,8 @@ static bool merge_array_items( /* in & out */ KMixtureModelBigram * target, merged_single_gram->insert_array_item(item->m_token, item->m_item); } - assert(merged_single_gram->set_array_header(merged_array_header)); - assert(target->store(*token, merged_single_gram)); + check_result(merged_single_gram->set_array_header(merged_array_header)); + check_result(target->store(*token, merged_single_gram)); delete merged_single_gram; g_array_free(merged_array, TRUE); } diff --git a/utils/training/prune_k_mixture_model.cpp b/utils/training/prune_k_mixture_model.cpp index 988bf1a..5434908 100644 --- a/utils/training/prune_k_mixture_model.cpp +++ b/utils/training/prune_k_mixture_model.cpp @@ -162,10 +162,10 @@ int main(int argc, char * argv[]){ &g_array_index(removed_array, KMixtureModelArrayItemWithToken, m); KMixtureModelArrayHeader array_header; - assert(bigram.get_array_header(item->m_token, array_header)); + check_result(bigram.get_array_header(item->m_token, array_header)); array_header.m_freq -= item->m_item.m_WC; assert(array_header.m_freq >= 0); - assert(bigram.set_array_header(item->m_token, array_header)); + check_result(bigram.set_array_header(item->m_token, array_header)); } g_array_free(removed_array, TRUE); @@ -180,9 +180,9 @@ int main(int argc, char * argv[]){ KMixtureModelArrayHeader array_header; for ( size_t i = 0; i < items->len; ++i ){ phrase_token_t * token = &g_array_index(items, phrase_token_t, i); - assert(bigram.get_array_header(*token, array_header)); + check_result(bigram.get_array_header(*token, array_header)); if ( 0 == array_header.m_WC && 0 == array_header.m_freq ) - assert(bigram.remove(*token)); + check_result(bigram.remove(*token)); } g_array_free(items, TRUE); diff --git a/utils/training/validate_k_mixture_model.cpp b/utils/training/validate_k_mixture_model.cpp index 91a4b2c..be4352b 100644 --- a/utils/training/validate_k_mixture_model.cpp +++ b/utils/training/validate_k_mixture_model.cpp @@ -55,7 +55,7 @@ bool validate_unigram(KMixtureModelBigram * bigram){ for (size_t i = 0; i < items->len; ++i) { phrase_token_t * token = &g_array_index(items, phrase_token_t, i); KMixtureModelArrayHeader array_header; - assert(bigram->get_array_header(*token, array_header)); + check_result(bigram->get_array_header(*token, array_header)); word_count += array_header.m_WC; total_freq += array_header.m_freq; } @@ -88,14 +88,14 @@ bool validate_bigram(KMixtureModelBigram * bigram){ for (size_t i = 0; i < items->len; ++i) { phrase_token_t * token = &g_array_index(items, phrase_token_t, i); KMixtureModelSingleGram * single_gram = NULL; - assert(bigram->load(*token, single_gram)); + check_result(bigram->load(*token, single_gram)); FlexibleBigramPhraseArray array = g_array_new (FALSE, FALSE, sizeof(KMixtureModelArrayItemWithToken)); single_gram->retrieve_all(array); KMixtureModelArrayHeader array_header; - assert(single_gram->get_array_header(array_header)); + check_result(single_gram->get_array_header(array_header)); guint32 expected_sum = array_header.m_WC; guint32 freq = array_header.m_freq; |