let phrase lookup to use merge single gram
authorPeng Wu <alexepico@gmail.com>
Tue, 10 Jan 2012 06:05:43 +0000 (14:05 +0800)
committerPeng Wu <alexepico@gmail.com>
Tue, 10 Jan 2012 07:35:48 +0000 (15:35 +0800)
src/lookup/phrase_lookup.cpp
src/lookup/phrase_lookup.h

index 28702c247bdd3f6818d43772b780e8020968ebe2..fb96fa43c37e01357f49ade1ecf6819c91c7fb06 100644 (file)
@@ -147,29 +147,21 @@ bool PhraseLookup::search_bigram(int nstep, phrase_token_t token){
         m_system_bigram->load(index_token, system);
         m_user_bigram->load(index_token, user);
 
-        if ( system && user ){
+        if ( !merge_single_gram(&m_merged_single_gram, system, user) )
+            continue;
+
+        guint32 freq;
+        if ( m_merged_single_gram.get_freq(token, freq) ){
             guint32 total_freq;
-            assert(user->get_total_freq(total_freq));
-            assert(system->set_total_freq(total_freq));
-        }
-        if ( system ){
-            guint32 freq;
-            if ( system->get_freq(token, freq) ){
-                guint32 total_freq;
-                system->get_total_freq(total_freq);
-                gfloat bigram_poss = freq / (gfloat) total_freq;
-                found = bigram_gen_next_step(nstep, cur_value, token, bigram_poss) || found;
-            }
-        }
-        if ( user ){
-            guint32 freq;
-            if ( user->get_freq(token, freq) ){
-                guint32 total_freq;
-                user->get_total_freq(total_freq);
-                gfloat bigram_poss = freq / (gfloat) total_freq;
-                found = bigram_gen_next_step(nstep, cur_value, token, bigram_poss) || found;
-            }
+            m_merged_single_gram.get_total_freq(total_freq);
+            gfloat bigram_poss = freq / (gfloat) total_freq;
+            found = bigram_gen_next_step(nstep, cur_value, token, bigram_poss) || found;
         }
+
+        if (system)
+            delete system;
+        if (user)
+            delete user;
     }
 
     return found;
index dd1ddc8698e524f806fded9a28efc3c5260b92e7..a0f0ac246882a5d2f4386ca37a2f24555f87bedc 100644 (file)
@@ -23,6 +23,7 @@
 #define PHRASE_LOOKUP_H
 
 #include "novel_types.h"
+#include "ngram.h"
 #include "lookup.h"
 
 /** @file phrase_lookup.h
@@ -37,6 +38,7 @@ private:
     static const gfloat unigram_lambda;
 
     PhraseItem m_cache_phrase_item;
+    SingleGram m_merged_single_gram;
 protected:
     //saved varibles
     FacadePhraseTable * m_phrase_table;