From bb3218247dfddf2c90f0a353059908dfb6890119 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 6 Sep 2012 13:16:50 +0800 Subject: write TAGLIB_GET_VALUE --- utils/storage/import_interpolation.cpp | 23 ++++++++++++++--------- utils/training/import_k_mixture_model.cpp | 22 +++++++++++++--------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/utils/storage/import_interpolation.cpp b/utils/storage/import_interpolation.cpp index d0ac36a..9295096 100644 --- a/utils/storage/import_interpolation.cpp +++ b/utils/storage/import_interpolation.cpp @@ -24,6 +24,16 @@ #include "pinyin_internal.h" #include "utils_helper.h" +#define TAGLIB_GET_VALUE(var, index) \ + phrase_token_t var = null_token; \ + { \ + const char * string = (const char *) g_ptr_array_index \ + (values, index); \ + var = taglib_string_to_token \ + (phrase_table, phrase_index, string); \ + } + + enum LINE_TYPE{ BEGIN_LINE = 1, END_LINE, @@ -125,9 +135,8 @@ bool parse_unigram(FILE * input, PhraseLargeTable2 * phrase_table, switch (line_type) { case GRAM_1_ITEM_LINE:{ /* handle \item in \1-gram */ - const char * string = (const char *) g_ptr_array_index(values, 0); - phrase_token_t token = taglib_string_to_token - (phrase_table, phrase_index, string); + TAGLIB_GET_VALUE(token, 0); + gpointer value = NULL; assert(g_hash_table_lookup_extended(required, "count", NULL, &value)); glong count = atol((const char *)value); @@ -162,12 +171,8 @@ bool parse_bigram(FILE * input, PhraseLargeTable2 * phrase_table, case GRAM_2_ITEM_LINE:{ /* handle \item in \2-gram */ /* two tokens */ - const char * string = (const char *) g_ptr_array_index(values, 0); - phrase_token_t token1 = taglib_string_to_token - (phrase_table, phrase_index, string); - string = (const char *) g_ptr_array_index(values, 1); - phrase_token_t token2 = taglib_string_to_token - (phrase_table, phrase_index, string); + TAGLIB_GET_VALUE(token1, 0); + TAGLIB_GET_VALUE(token2, 1); gpointer value = NULL; /* tag: count */ diff --git a/utils/training/import_k_mixture_model.cpp b/utils/training/import_k_mixture_model.cpp index 59c311f..5bbd603 100644 --- a/utils/training/import_k_mixture_model.cpp +++ b/utils/training/import_k_mixture_model.cpp @@ -24,6 +24,15 @@ #include "utils_helper.h" #include "k_mixture_model.h" +#define TAGLIB_GET_VALUE(var, index) \ + phrase_token_t var = null_token; \ + { \ + const char * string = (const char *) g_ptr_array_index \ + (values, index); \ + var = taglib_string_to_token \ + (phrase_table, phrase_index, string); \ + } + enum LINE_TYPE{ BEGIN_LINE = 1, END_LINE, @@ -145,9 +154,8 @@ bool parse_unigram(FILE * input, PhraseLargeTable2 * phrase_table, switch (line_type) { case GRAM_1_ITEM_LINE:{ /* handle \item in \1-gram */ - const char * string = (const char *) g_ptr_array_index(values, 0); - phrase_token_t token = taglib_string_to_token - (phrase_table, phrase_index, string); + TAGLIB_GET_VALUE(token, 0); + gpointer value = NULL; assert(g_hash_table_lookup_extended(required, "count", NULL, &value)); @@ -192,12 +200,8 @@ bool parse_bigram(FILE * input, PhraseLargeTable2 * phrase_table, case GRAM_2_ITEM_LINE:{ /* handle \item in \2-gram */ /* two tokens */ - const char * string = (const char *) g_ptr_array_index(values, 0); - phrase_token_t token1 = taglib_string_to_token - (phrase_table, phrase_index, string); - string = (const char *) g_ptr_array_index(values, 1); - phrase_token_t token2 = taglib_string_to_token - (phrase_table, phrase_index, string); + TAGLIB_GET_VALUE(token1, 0); + TAGLIB_GET_VALUE(token2, 1); gpointer value = NULL; /* tag: count */ -- cgit