summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2016-05-24 16:48:51 +0800
committerPeng Wu <alexepico@gmail.com>2016-05-24 16:50:34 +0800
commite2f610a6102f91428e42288e71447a015fd3472b (patch)
tree8ff80aaeb56deed8c1f2cecde648c7ed7dfa4da7 /tests
parent65494d1d325294deb4f0abea0c18462b9f29b5e7 (diff)
downloadlibpinyin-e2f610a6102f91428e42288e71447a015fd3472b.tar.gz
libpinyin-e2f610a6102f91428e42288e71447a015fd3472b.tar.xz
libpinyin-e2f610a6102f91428e42288e71447a015fd3472b.zip
update test_matrix.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/storage/test_matrix.cpp47
1 files changed, 44 insertions, 3 deletions
diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp
index 9a283f9..3c63902 100644
--- a/tests/storage/test_matrix.cpp
+++ b/tests/storage/test_matrix.cpp
@@ -22,15 +22,32 @@
#include "timer.h"
#include <stdlib.h>
#include "pinyin_internal.h"
+#include "tests_helper.h"
size_t bench_times = 1000;
using namespace pinyin;
int main(int argc, char * argv[]) {
- pinyin_option_t options = PINYIN_CORRECT_ALL;
- options |= PINYIN_AMB_ALL;
- options |= PINYIN_INCOMPLETE;
+ SystemTableInfo2 system_table_info;
+
+ bool retval = system_table_info.load("../../data/table.conf");
+ if (!retval) {
+ fprintf(stderr, "load table.conf failed.\n");
+ exit(ENOENT);
+ }
+
+ pinyin_option_t options = PINYIN_CORRECT_ALL | PINYIN_AMB_ALL | PINYIN_INCOMPLETE;
+
+ FacadeChewingTable2 largetable;
+ largetable.load("../../data/pinyin_index.bin", NULL);
+
+ const pinyin_table_info_t * phrase_files =
+ system_table_info.get_default_tables();
+
+ FacadePhraseIndex phrase_index;
+ if (!load_phrase_index(phrase_files, &phrase_index))
+ exit(ENOENT);
PhoneticParser2 * parser = new FullPinyinParser2();
ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey));
@@ -70,6 +87,30 @@ int main(int argc, char * argv[]) {
printf("parsed %d chars, %d keys.\n", len, keys->len);
dump_phonetic_key_matrix(&matrix);
+
+ PhraseIndexRanges ranges;
+ memset(ranges, 0, sizeof(PhraseIndexRanges));
+
+ phrase_index.prepare_ranges(ranges);
+
+ for (size_t i = 0; i < matrix.size(); ++i) {
+ for (size_t j = i + 1; j < matrix.size(); ++j) {
+ phrase_index.clear_ranges(ranges);
+
+ printf("search index: start %ld\t end %ld\n", i, j);
+ int retval = search_matrix(&largetable, &matrix, i, j, ranges);
+
+#if 0
+ if (retval & SEARCH_OK)
+ dump_ranges(&phrase_index, ranges);
+#endif
+
+ if (!(retval & SEARCH_CONTINUED))
+ break;
+ }
+ }
+
+ phrase_index.destroy_ranges(ranges);
}
if (linebuf)