fixes compile for gen k mixture model
authorPeng Wu <alexepico@gmail.com>
Mon, 9 May 2011 06:32:13 +0000 (14:32 +0800)
committerPeng Wu <alexepico@gmail.com>
Mon, 9 May 2011 06:32:13 +0000 (14:32 +0800)
utils/training/Makefile.am
utils/training/gen_k_mixture_model.cpp

index fd516704e178e6d00a2f96caae51a0c2250990ba..5cee6bca8b3ed0adae9d82ed7ab992f170e3df9b 100644 (file)
@@ -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@
index cdf7976508d82b794a52201ef938013b9b8ea6c1..7d4e3edbf357392115c49e5339f65632e16acbde 100644 (file)
@@ -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;