From 0d1aaf9cb0f4b53114422618cb61510560f4611d Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 11 May 2016 16:15:01 +0800 Subject: add test_matrix.cpp --- tests/storage/test_matrix.cpp | 76 ++++++++++++++++++++++++++++++++++++++++++ tests/storage/test_parser2.cpp | 3 +- 2 files changed, 77 insertions(+), 2 deletions(-) create mode 100644 tests/storage/test_matrix.cpp (limited to 'tests/storage') diff --git a/tests/storage/test_matrix.cpp b/tests/storage/test_matrix.cpp new file mode 100644 index 0000000..ba9b3e0 --- /dev/null +++ b/tests/storage/test_matrix.cpp @@ -0,0 +1,76 @@ +/* + * libpinyin + * Library to deal with pinyin. + * + * Copyright (C) 2016 Peng Wu + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "timer.h" +#include +#include "pinyin_internal.h" + + +using namespace pinyin; + +int main(int argc, char * argv[]) { + pinyin_option_t options = PINYIN_CORRECT_ALL; + options |= PINYIN_INCOMPLETE; + + PhoneticParser2 * parser = FullPinyinParser2(); + ChewingKeyVector keys = g_array_new(FALSE, FALSE, sizeof(ChewingKey)); + ChewingKeyRestVector key_rests = + g_array_new(FALSE, FALSE, sizeof(ChewingKeyRest)); + + PhoneticKeyMatrix matrix; + + char* linebuf = NULL; size_t size = 0; ssize_t read; + while( (read = getline(&linebuf, &size, stdin)) != -1 ){ + if ( '\n' == linebuf[strlen(linebuf) - 1] ) { + linebuf[strlen(linebuf) - 1] = '\0'; + } + + if ( strcmp ( linebuf, "quit" ) == 0) + break; + + int len = 0; + guint32 start_time = record_time(); + for (size_t i = 0; i < bench_times; ++i) { + matrix.clear_all(); + + len = parser->parse(options, keys, key_rests, + linebuf, strlen(linebuf)); + + fill_phonetic_key_matrix_from_chewing_keys + (&matrix, keys, key_rests); + } + print_time(start_time, bench_times); + + printf("parsed %d chars, %d keys.\n", len, keys->len); + + dump_phonetic_key_matrix(&matrix); + } + + if (linebuf) + free(linebuf); + + delete parser; + + g_array_free(key_rests, TRUE); + g_array_free(keys, TRUE); + + return 0; +} diff --git a/tests/storage/test_parser2.cpp b/tests/storage/test_parser2.cpp index 8427ae8..b0a1787 100644 --- a/tests/storage/test_parser2.cpp +++ b/tests/storage/test_parser2.cpp @@ -26,8 +26,7 @@ #include #include #include -#include "pinyin_parser2.h" -#include "zhuyin_parser2.h" +#include "pinyin_internal.h" static const gchar * parsername = ""; -- cgit