From 54eb877f6df998eaabb397caed32cab760edbb9b Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 9 May 2011 14:32:13 +0800 Subject: fixes compile for gen k mixture model --- utils/training/Makefile.am | 5 +++++ utils/training/gen_k_mixture_model.cpp | 26 +++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) (limited to 'utils') diff --git a/utils/training/Makefile.am b/utils/training/Makefile.am index fd51670..5cee6bc 100644 --- a/utils/training/Makefile.am +++ b/utils/training/Makefile.am @@ -28,6 +28,7 @@ noinst_HEADERS = k_mixture_model.h noinst_PROGRAMS = gen_ngram \ gen_deleted_ngram \ gen_unigram \ + gen_k_mixture_model \ estimate_interpolation \ estimate_k_mixture_model \ prune_k_mixture_model @@ -44,6 +45,10 @@ gen_unigram_SOURCES = gen_unigram.cpp gen_unigram_LDADD = ../../src/libpinyin.la @GLIB2_LDFLAGS@ +gen_k_mixture_model_SOURCES = gen_k_mixture_model.cpp + +gen_k_mixture_model_LDADD = ../../src/libpinyin.la @GLIB2_LDFLAGS@ + estimate_interpolation_SOURCES = estimate_interpolation.cpp estimate_interpolation_LDADD = ../../src/libpinyin.la @GLIB2_LDFLAGS@ diff --git a/utils/training/gen_k_mixture_model.cpp b/utils/training/gen_k_mixture_model.cpp index cdf7976..7d4e3ed 100644 --- a/utils/training/gen_k_mixture_model.cpp +++ b/utils/training/gen_k_mixture_model.cpp @@ -51,7 +51,7 @@ bool convert_document_to_hash(FILE * document){ if ( feof(document) ) break; /* Note: check '\n' here? */ - linebuf[strlen(linebuf) - 1] = "\0"; + linebuf[strlen(linebuf) - 1] = '\0'; glong phrase_len = 0; utf16_t * phrase = g_utf8_to_utf16(linebuf, -1, NULL, &phrase_len, NULL); @@ -60,27 +60,31 @@ bool convert_document_to_hash(FILE * document){ continue; phrase_token_t token = 0; - int result = g_phrases->search( phrase_len, phrase, token ); - if ( ! (result & SEARCH_OK) ) + int search_result = g_phrases->search( phrase_len, phrase, token ); + if ( ! (search_result & SEARCH_OK) ) token = 0; last_token = cur_token; cur_token = token; /* remember the (last_token, cur_token) word pair. */ + gpointer value = NULL; HashofSecondWord hash_of_second_word = NULL; - gboolean result = g_hash_table_lookup_extended + gboolean lookup_result = g_hash_table_lookup_extended (g_hash_of_document, GUINT_TO_POINTER(last_token), - NULL, &hash_of_second_word); - if ( !result ){ + NULL, &value); + if ( !lookup_result ){ hash_of_second_word = g_hash_table_new(g_int_hash, g_int_equal); + } else { + hash_of_second_word = (HashofSecondWord) value; } - gpointer value = NULL; - result = g_hash_table_lookup_extended + + value = NULL; + lookup_result = g_hash_table_lookup_extended (hash_of_second_word, GUINT_TO_POINTER(cur_token), NULL, &value); guint32 count = 0; - if ( result ) { + if ( lookup_result ) { count = GPOINTER_TO_UINT(value); } count ++; @@ -90,14 +94,14 @@ bool convert_document_to_hash(FILE * document){ g_hash_table_insert(g_hash_of_document, GUINT_TO_POINTER(last_token), hash_of_second_word); - } return true; } int main(int argc, char * argv[]){ - g_hash_of_document = g_hash_table_new(g_int_hash, g_int_equal, NULL, g_hash_table_unref); + g_hash_of_document = g_hash_table_new_full + (g_int_hash, g_int_equal, NULL, (GDestroyNotify)g_hash_table_unref); return 0; -- cgit