summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-07-21 15:13:31 +0800
committerPeng Wu <alexepico@gmail.com>2016-07-21 15:13:31 +0800
commit0ba361964b810f06839f67ddfbfba39fb75b6a70 (patch)
treeb43583105b310a101c53bddd618858c3ebf93441
parenteb08ebb49b4823b17c749cde377c0aa1c6fe76ea (diff)
downloadlibpinyin-0ba361964b810f06839f67ddfbfba39fb75b6a70.tar.gz
libpinyin-0ba361964b810f06839f67ddfbfba39fb75b6a70.tar.xz
libpinyin-0ba361964b810f06839f67ddfbfba39fb75b6a70.zip
fixes fill_matrix function
-rw-r--r--src/pinyin.cpp6
-rw-r--r--src/storage/phonetic_key_matrix.cpp5
-rw-r--r--src/storage/phonetic_key_matrix.h3
-rw-r--r--tests/lookup/test_pinyin_lookup.cpp5
-rw-r--r--tests/storage/test_matrix.cpp2
-rw-r--r--utils/training/eval_correction_rate.cpp2
6 files changed, 13 insertions, 10 deletions
diff --git a/src/pinyin.cpp b/src/pinyin.cpp
index cd66585..c81d8b3 100644
--- a/src/pinyin.cpp
+++ b/src/pinyin.cpp
@@ -1203,7 +1203,7 @@ size_t pinyin_parse_more_full_pinyins(pinyin_instance_t * instance,
instance->m_parsed_len = parsed_len;
- fill_matrix(&matrix, keys, key_rests);
+ fill_matrix(&matrix, keys, key_rests, parsed_len);
resplit_step(options, &matrix);
@@ -1243,7 +1243,7 @@ size_t pinyin_parse_more_double_pinyins(pinyin_instance_t * instance,
instance->m_parsed_len = parsed_len;
- fill_matrix(&matrix, keys, key_rests);
+ fill_matrix(&matrix, keys, key_rests, parsed_len);
fuzzy_syllable_step(options, &matrix);
@@ -1279,7 +1279,7 @@ size_t pinyin_parse_more_chewings(pinyin_instance_t * instance,
instance->m_parsed_len = parsed_len;
- fill_matrix(&matrix, keys, key_rests);
+ fill_matrix(&matrix, keys, key_rests, parsed_len);
fuzzy_syllable_step(options, &matrix);
diff --git a/src/storage/phonetic_key_matrix.cpp b/src/storage/phonetic_key_matrix.cpp
index 66a1d4b..c86d365 100644
--- a/src/storage/phonetic_key_matrix.cpp
+++ b/src/storage/phonetic_key_matrix.cpp
@@ -30,7 +30,8 @@ namespace pinyin{
/* zero ChewingKey for "'" symbol and last key in fill_matrix function. */
bool fill_matrix(PhoneticKeyMatrix * matrix,
ChewingKeyVector keys,
- ChewingKeyRestVector key_rests) {
+ ChewingKeyRestVector key_rests,
+ size_t parsed_len) {
matrix->clear_all();
assert(keys->len == key_rests->len);
@@ -44,7 +45,7 @@ bool fill_matrix(PhoneticKeyMatrix * matrix,
key_rest = &g_array_index(key_rests, ChewingKeyRest, key_rests->len - 1);
/* one extra slot for the last key. */
- size_t length = key_rest->m_raw_end + 1;
+ size_t length = parsed_len + 1;
matrix->set_size(length);
/* fill keys and key rests. */
diff --git a/src/storage/phonetic_key_matrix.h b/src/storage/phonetic_key_matrix.h
index 75ea2aa..0497a62 100644
--- a/src/storage/phonetic_key_matrix.h
+++ b/src/storage/phonetic_key_matrix.h
@@ -177,7 +177,8 @@ public:
*/
bool fill_matrix(PhoneticKeyMatrix * matrix,
ChewingKeyVector keys,
- ChewingKeyRestVector key_rests);
+ ChewingKeyRestVector key_rests,
+ size_t parsed_len);
/**
* resplit_step:
diff --git a/tests/lookup/test_pinyin_lookup.cpp b/tests/lookup/test_pinyin_lookup.cpp
index ac43ce5..9978551 100644
--- a/tests/lookup/test_pinyin_lookup.cpp
+++ b/tests/lookup/test_pinyin_lookup.cpp
@@ -82,7 +82,8 @@ int main( int argc, char * argv[]){
ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey));
ChewingKeyRestVector key_rests =
g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest));
- parser.parse(options, keys, key_rests, linebuf, strlen(linebuf));
+ int parsed_len = parser.parse(options, keys, key_rests,
+ linebuf, strlen(linebuf));
PhoneticKeyMatrix matrix;
@@ -90,7 +91,7 @@ int main( int argc, char * argv[]){
continue;
/* fill the matrix. */
- fill_matrix(&matrix, keys, key_rests);
+ fill_matrix(&matrix, keys, key_rests, parsed_len);
resplit_step(options, &matrix);
diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp
index 5602bd6..bc7ede4 100644
--- a/tests/storage/test_matrix.cpp
+++ b/tests/storage/test_matrix.cpp
@@ -124,7 +124,7 @@ int main(int argc, char * argv[]) {
len = parser->parse(options, keys, key_rests,
linebuf, strlen(linebuf));
- fill_matrix(&matrix, keys, key_rests);
+ fill_matrix(&matrix, keys, key_rests, len);
resplit_step(options, &matrix);
diff --git a/utils/training/eval_correction_rate.cpp b/utils/training/eval_correction_rate.cpp
index 90d1883..a691416 100644
--- a/utils/training/eval_correction_rate.cpp
+++ b/utils/training/eval_correction_rate.cpp
@@ -104,7 +104,7 @@ bool do_one_test(PinyinLookup2 * pinyin_lookup,
}
PhoneticKeyMatrix matrix;
- fill_matrix(&matrix, keys, key_rests);
+ fill_matrix(&matrix, keys, key_rests, keys->len);
get_best_match(pinyin_lookup, &matrix, guessed_tokens);
/* compare the results */