From 27ec333e65de3fc881f9e62ae9c622353a0b173e Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 1 Jun 2016 13:50:02 +0800 Subject: update test_matrix.cpp --- tests/storage/test_matrix.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++- tests/tests_helper.h | 4 ++-- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp index 3c63902..d80b030 100644 --- a/tests/storage/test_matrix.cpp +++ b/tests/storage/test_matrix.cpp @@ -28,6 +28,57 @@ size_t bench_times = 1000; using namespace pinyin; +bool test_pronunciation_possibility(PhoneticKeyMatrix * matrix, + size_t start, size_t end, + FacadePhraseIndex * phrase_index, + PhraseIndexRanges ranges) { + GArray * cached_keys = g_array_new(TRUE, TRUE, sizeof(ChewingKey)); + + for (size_t i = 0; i < PHRASE_INDEX_LIBRARY_COUNT; ++i) { + GArray * & range = ranges[i]; + if (!range) + continue; + + if (range->len) + printf("range items number:%d\n", range->len); + + + for (size_t k = 0; k < range->len; ++k) { + PhraseIndexRange * onerange = + &g_array_index(range, PhraseIndexRange, k); + printf("start:%d\tend:%d\n", onerange->m_range_begin, + onerange->m_range_end); + + PhraseItem item; + for (phrase_token_t token = onerange->m_range_begin; + token != onerange->m_range_end; ++token){ + + phrase_index->get_phrase_item(token, item); + + gfloat origin = compute_pronunciation_possibility + (matrix, start, end, cached_keys, item); + + bool increased = increase_pronunciation_possibility + (matrix, start, end, cached_keys, item, 30); + + gfloat updated = compute_pronunciation_possibility + (matrix, start, end, cached_keys, item); + + if (increased) { + printf("origin:%f\t updated:%f\n", origin, updated); + } else { + assert(origin == updated); + printf("origin:%f\n", origin); + } + } + } + + } + + g_array_free(cached_keys, TRUE); + return true; +} + int main(int argc, char * argv[]) { SystemTableInfo2 system_table_info; @@ -101,8 +152,11 @@ int main(int argc, char * argv[]) { int retval = search_matrix(&largetable, &matrix, i, j, ranges); #if 0 - if (retval & SEARCH_OK) + if (retval & SEARCH_OK) { dump_ranges(&phrase_index, ranges); + test_pronunciation_possibility + (&matrix, i, j, &phrase_index, ranges); + } #endif if (!(retval & SEARCH_CONTINUED)) diff --git a/tests/tests_helper.h b/tests/tests_helper.h index 995d8c1..d143975 100644 --- a/tests/tests_helper.h +++ b/tests/tests_helper.h @@ -101,10 +101,10 @@ inline bool dump_ranges(FacadePhraseIndex * phrase_index, onerange->m_range_end); PhraseItem item; - for ( phrase_token_t token = onerange->m_range_begin; + for (phrase_token_t token = onerange->m_range_begin; token != onerange->m_range_end; ++token){ - phrase_index->get_phrase_item( token, item); + phrase_index->get_phrase_item(token, item); /* get phrase string */ ucs4_t buffer[MAX_PHRASE_LENGTH + 1]; -- cgit