diff options
author | Peng Wu <alexepico@gmail.com> | 2011-04-01 11:03:46 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2011-04-02 15:11:18 +0800 |
commit | f1f777630f85e58b01b472da23e3f72a71dd1f49 (patch) | |
tree | 5f41f2bd66ef04b41950a9a67ee39459dd46b587 | |
parent | 37498f130e673dcb3052c029c0407ffa483dda8a (diff) | |
download | libpinyin-f1f777630f85e58b01b472da23e3f72a71dd1f49.tar.gz libpinyin-f1f777630f85e58b01b472da23e3f72a71dd1f49.tar.xz libpinyin-f1f777630f85e58b01b472da23e3f72a71dd1f49.zip |
refine code
-rw-r--r-- | src/storage/flexible_ngram.h | 10 | ||||
-rw-r--r-- | src/storage/ngram.cpp | 8 | ||||
-rw-r--r-- | src/storage/ngram.h | 4 | ||||
-rw-r--r-- | utils/training/estimate_interpolation.cpp | 4 |
4 files changed, 18 insertions, 8 deletions
diff --git a/src/storage/flexible_ngram.h b/src/storage/flexible_ngram.h index f437b80..9bcfdc3 100644 --- a/src/storage/flexible_ngram.h +++ b/src/storage/flexible_ngram.h @@ -19,6 +19,12 @@ private: MemoryChunk m_chunk; FlexibleSingleGram(void * buffer, size_t length); public: + /* item typedefs */ + typedef struct{ + phrase_token_t m_token; + ArrayItem m_item; + } ArrayItemWithToken; + /* Null Constructor */ FlexibleSingleGram(); /* retrieve all items */ @@ -73,6 +79,10 @@ public: bool store(phrase_token_t index, FlexibleSingleGram * & single_gram); /* array of phrase_token_t items, for parameter estimation. */ bool get_all_items(GArray * items); + + /* get/set magic header. */ + bool get_magic_header(MagicHeader & header); + bool set_magic_header(const MagicHeader & header); }; #endif diff --git a/src/storage/ngram.cpp b/src/storage/ngram.cpp index 8ea8334..c6b1736 100644 --- a/src/storage/ngram.cpp +++ b/src/storage/ngram.cpp @@ -38,15 +38,15 @@ SingleGram::SingleGram(void * buffer, size_t length){ m_chunk.set_chunk(buffer, length, NULL); } -bool SingleGram::set_total_freq(guint32 m_total){ +bool SingleGram::set_total_freq(guint32 total){ char * buf_begin = (char *)m_chunk.begin(); - *((guint32 *)buf_begin) = m_total; + *((guint32 *)buf_begin) = total; return true; } -bool SingleGram::get_total_freq(guint32 & m_total){ +bool SingleGram::get_total_freq(guint32 & total){ char * buf_begin = (char *)m_chunk.begin(); - m_total = *((guint32 *)buf_begin); + total = *((guint32 *)buf_begin); return true; } diff --git a/src/storage/ngram.h b/src/storage/ngram.h index c4fdf7b..c5e7bc8 100644 --- a/src/storage/ngram.h +++ b/src/storage/ngram.h @@ -66,12 +66,12 @@ public: /* get_total_freq method * used in user bigram table */ - bool get_total_freq(guint32 & m_total); + bool get_total_freq(guint32 & total); /* set_total_freq method * used in user bigram table */ - bool set_total_freq(guint32 m_total); + bool set_total_freq(guint32 total); /* prune one method * only used in training diff --git a/utils/training/estimate_interpolation.cpp b/utils/training/estimate_interpolation.cpp index 60e689b..b7a56f1 100644 --- a/utils/training/estimate_interpolation.cpp +++ b/utils/training/estimate_interpolation.cpp @@ -48,7 +48,7 @@ parameter_t compute_interpolation(SingleGram * deleted_bigram, BigramPhraseItemWithCount* item = &g_array_index(array, BigramPhraseItemWithCount, i); //get the phrase token phrase_token_t token = item->m_token; - guint32 deleted_freq = item->m_count; + guint32 deleted_count = item->m_count; { guint32 freq = 0; @@ -77,7 +77,7 @@ parameter_t compute_interpolation(SingleGram * deleted_bigram, if ( 0 == (numerator + part_of_denominator)) continue; - next_lambda += deleted_freq * (numerator / (numerator + part_of_denominator)); + next_lambda += deleted_count * (numerator / (numerator + part_of_denominator)); } assert(deleted_bigram->get_total_freq(table_num)); next_lambda /= table_num; |