summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-05-25 16:59:09 +0800
committerPeng Wu <alexepico@gmail.com>2016-05-25 16:59:09 +0800
commit10fd5d0c796f817c5f82bbdb92adbb7fee1095ed (patch)
tree63bc7d24343ca1561167a8ccce564dc3be9093fa
parent473d80f6681f0fe7c20bc2008c249563a0f99eee (diff)
downloadlibpinyin-10fd5d0c796f817c5f82bbdb92adbb7fee1095ed.tar.gz
libpinyin-10fd5d0c796f817c5f82bbdb92adbb7fee1095ed.tar.xz
libpinyin-10fd5d0c796f817c5f82bbdb92adbb7fee1095ed.zip
fixes compile
-rw-r--r--src/lookup/pinyin_lookup2.cpp23
-rw-r--r--src/lookup/pinyin_lookup2.h2
2 files changed, 14 insertions, 11 deletions
diff --git a/src/lookup/pinyin_lookup2.cpp b/src/lookup/pinyin_lookup2.cpp
index b09b8a0..7162a67 100644
--- a/src/lookup/pinyin_lookup2.cpp
+++ b/src/lookup/pinyin_lookup2.cpp
@@ -34,7 +34,7 @@ const gfloat PinyinLookup2::unigram_lambda = 1 - lambda;
/* internal definition */
static const size_t nbeam = 32;
-static bool dump_max_value(GPtrArray * values){
+bool dump_max_value(GPtrArray * values){
if (0 == values->len)
return false;
@@ -54,7 +54,7 @@ static bool dump_max_value(GPtrArray * values){
return true;
}
-static bool dump_all_values(GPtrArray * values) {
+bool dump_all_values(GPtrArray * values) {
if (0 == values->len)
return false;
@@ -203,8 +203,10 @@ PinyinLookup2::PinyinLookup2(const gfloat lambda,
m_steps_index = g_ptr_array_new();
m_steps_content = g_ptr_array_new();
+ m_cached_keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey));
+
/* the member variables below are saved in get_best_match call. */
- m_keys = NULL;
+ m_matrix = NULL;
m_constraints = NULL;
}
@@ -212,6 +214,7 @@ PinyinLookup2::~PinyinLookup2(){
clear_steps(m_steps_index, m_steps_content);
g_ptr_array_free(m_steps_index, TRUE);
g_ptr_array_free(m_steps_content, TRUE);
+ g_array_free(m_cached_keys, TRUE);
}
@@ -254,8 +257,6 @@ bool PinyinLookup2::get_best_match(TokenVector prefixes,
continue;
for ( int m = i + 1; m < nstep; ++m ){
- const int len = m - i;
-
lookup_constraint_t * next_constraint = &g_array_index
(m_constraints, lookup_constraint_t, m);
@@ -268,14 +269,14 @@ bool PinyinLookup2::get_best_match(TokenVector prefixes,
int retval = search_matrix(m_pinyin_table, m_matrix,
i, m, ranges);
- if (result & SEARCH_OK) {
+ if (retval & SEARCH_OK) {
/* assume topresults always contains items. */
search_bigram2(topresults, i, m, ranges),
search_unigram2(topresults, i, m, ranges);
}
/* no longer pinyin */
- if (!(result & SEARCH_CONTINUED))
+ if (!(retval & SEARCH_CONTINUED))
break;
}
}
@@ -404,8 +405,8 @@ bool PinyinLookup2::unigram_gen_next_step(int start, int end,
if ( elem_poss < DBL_EPSILON )
return false;
- ChewingKey * pinyin_keys = ((ChewingKey *)m_keys->data) + nstep;
- gfloat pinyin_poss = m_cache_phrase_item.get_pronunciation_possibility(m_options, pinyin_keys);
+ gfloat pinyin_poss = compute_pronunciation_possibility
+ (m_options, m_matrix, start, end, m_cached_keys, m_cache_phrase_item);
if (pinyin_poss < FLT_EPSILON )
return false;
@@ -432,8 +433,8 @@ bool PinyinLookup2::bigram_gen_next_step(int start, int end,
if ( bigram_poss < FLT_EPSILON && unigram_poss < DBL_EPSILON )
return false;
- ChewingKey * pinyin_keys = ((ChewingKey *)m_keys->data) + nstep;
- gfloat pinyin_poss = m_cache_phrase_item.get_pronunciation_possibility(m_options, pinyin_keys);
+ gfloat pinyin_poss = compute_pronunciation_possibility
+ (m_options, m_matrix, start, end, m_cached_keys, m_cache_phrase_item);
if ( pinyin_poss < FLT_EPSILON )
return false;
diff --git a/src/lookup/pinyin_lookup2.h b/src/lookup/pinyin_lookup2.h
index 1a8e888..6a7f14f 100644
--- a/src/lookup/pinyin_lookup2.h
+++ b/src/lookup/pinyin_lookup2.h
@@ -31,6 +31,7 @@
#include "phrase_index.h"
#include "ngram.h"
#include "lookup.h"
+#include "phonetic_key_matrix.h"
namespace pinyin{
@@ -86,6 +87,7 @@ private:
const gfloat bigram_lambda;
const gfloat unigram_lambda;
+ GArray * m_cached_keys;
PhraseItem m_cache_phrase_item;
SingleGram m_merged_single_gram;