write phrase lookup in progress
authorPeng Wu <alexepico@gmail.com>
Fri, 29 Oct 2010 03:17:56 +0000 (11:17 +0800)
committerPeng Wu <alexepico@gmail.com>
Fri, 29 Oct 2010 03:17:56 +0000 (11:17 +0800)
src/lookup/phrase_lookup.cpp
src/lookup/phrase_lookup.h

index 7c05dae45a1dcbec7855ad385c0ad5e5fb5b0adb..eae0662b13435f65330ad392c56848dc144d3a63 100644 (file)
 #include "phrase_large_table.h"
 #include "ngram.h"
 #include "phrase_lookup.h"
+
+const gfloat PhraseLookup::bigram_lambda;
+const gfloat PhraseLookup::unigram_lambda;
+
+PhraseLookup::PhraseLookup(PhraseLargeTable * phrase_table,
+                           FacadePhraseIndex * phrase_index,
+                           Bigram * bigram){
+    m_phrase_table = phrase_table;
+    m_phrase_index = phrase_index;
+    m_bigram = bigram;
+
+    m_steps_index = g_ptr_array_new();
+    m_steps_content = g_ptr_array_new();
+}
+
+
+
+
+
+bool PhraseLookup::convert_to_utf8(phrase_token_t token, /* out */ char * & phrase){
+    m_phrase_index->get_phrase_item(token, m_cache_phrase_item);
+    utf16_t buffer[MAX_PHRASE_LENGTH];
+    m_cache_phrase_item.get_phrase_string(buffer);
+    guint8 length = m_cache_phrase_item.get_phrase_length();
+    phrase = g_utf16_to_utf8(buffer, length, NULL, NULL, NULL);
+    return true;
+}
index 686a7d58674519932ac3d7d2204f2f04dad94d0c..0aacdbc1e2b145ddc7a95504ec5be1f117ab1ba6 100644 (file)
  */
 
 class PhraseLookup{
+private:
+    static const gfloat bigram_lambda = LAMBDA_PARAMETER;
+    static const gfloat unigram_lambda = 1 - LAMBDA_PARAMETER;
+
+    PhraseItem m_cache_phrase_item;
 protected:
     //saved varibles
     novel::PhraseLargeTable * m_phrase_table;
@@ -60,10 +65,17 @@ protected:
 
     bool final_step(MatchResults & results);
 public:
+    PhraseLookup(PhraseLargeTable * phrase_table,
+                 FacadePhraseIndex * phrase_index,
+                 Bigram * bigram);
+
+    ~PhraseLookup();
+
     /* Note: this method only accepts the characters in phrase large table. */
     bool get_best_match(int sentence_length, utf16_t sentence[], MatchResults & results);
 
-    bool convert_to_utf8(MatchResults results, /* out */ char * & result_string);
+    /* Note: free the phrase by g_free */
+    bool convert_to_utf8(phrase_token_t token, /* out */ char * & phrase);
 };
 
 #endif