summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-09-06 13:16:50 +0800
committerPeng Wu <alexepico@gmail.com>2012-09-06 13:16:50 +0800
commitbb3218247dfddf2c90f0a353059908dfb6890119 (patch)
tree7049576df2575bf8742e41ea1cb69af6ae329447 /utils
parent8a0214e80f7034751d79135fa6d438bc1fe2a6a0 (diff)
downloadlibpinyin-bb3218247dfddf2c90f0a353059908dfb6890119.tar.gz
libpinyin-bb3218247dfddf2c90f0a353059908dfb6890119.tar.xz
libpinyin-bb3218247dfddf2c90f0a353059908dfb6890119.zip
write TAGLIB_GET_VALUE
Diffstat (limited to 'utils')
-rw-r--r--utils/storage/import_interpolation.cpp23
-rw-r--r--utils/training/import_k_mixture_model.cpp22
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 */