diff options
Diffstat (limited to 'utils/training')
-rw-r--r-- | utils/training/import_k_mixture_model.cpp | 22 |
1 files changed, 13 insertions, 9 deletions
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 */ |