summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2015-05-25 15:16:11 +0800
committerPeng Wu <alexepico@gmail.com>2015-05-25 15:16:11 +0800
commitf82963f28c0d57574e077417d092fba4cbfead06 (patch)
tree0eaf5e40b3169596226dfa5d5bc836e8ec97446c
parent6cca2a97d0660e5a51f65389fbfacc0f5cdaaf5d (diff)
downloadlibpinyin-f82963f28c0d57574e077417d092fba4cbfead06.tar.gz
libpinyin-f82963f28c0d57574e077417d092fba4cbfead06.tar.xz
libpinyin-f82963f28c0d57574e077417d092fba4cbfead06.zip
fixes a bug
-rw-r--r--src/storage/phrase_index.cpp8
-rw-r--r--utils/training/gen_unigram.cpp2
2 files changed, 5 insertions, 5 deletions
diff --git a/src/storage/phrase_index.cpp b/src/storage/phrase_index.cpp
index cdec42d..57146cd 100644
--- a/src/storage/phrase_index.cpp
+++ b/src/storage/phrase_index.cpp
@@ -622,14 +622,14 @@ int SubPhraseIndex::get_range(/* out */ PhraseIndexRange & range){
}
/* remove trailing zeros. */
- const table_offset_t * poffset = 0;
- for (poffset = end - 1; poffset >= begin + 1; --poffset) {
- if (0 != *poffset)
+ const table_offset_t * poffset = NULL;
+ for (poffset = end; poffset > begin; --poffset) {
+ if (NULL != *(poffset - 1))
break;
}
range.m_range_begin = 1; /* token starts with 1 in gen_pinyin_table. */
- range.m_range_end = poffset + 1 - begin; /* removed zeros. */
+ range.m_range_end = poffset - begin + 1; /* removed zeros. */
return ERROR_OK;
}
diff --git a/utils/training/gen_unigram.cpp b/utils/training/gen_unigram.cpp
index bb9b6b3..fe63e36 100644
--- a/utils/training/gen_unigram.cpp
+++ b/utils/training/gen_unigram.cpp
@@ -64,7 +64,7 @@ bool generate_unigram(const pinyin_table_info_t * phrase_files) {
int result = phrase_index.get_range(i, range);
if ( result == ERROR_OK ) {
for (size_t token = range.m_range_begin;
- token <= range.m_range_end; ++token) {
+ token < range.m_range_end; ++token) {
phrase_index.add_unigram_frequency(token, freq);
}
}