summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2012-02-24 11:55:52 +0800
committerPeng Wu <alexepico@gmail.com>2012-02-24 11:55:52 +0800
commitdbf7a2dcd8e35f0db28e0a8f4ef324c12a3af1b4 (patch)
treea6fbc14e3f1d648a6a9a57565de9de57264507ef /tests
parent23b89bb317cdf38e645cd25b31e2a5dbaaf1fe84 (diff)
downloadlibpinyin-dbf7a2dcd8e35f0db28e0a8f4ef324c12a3af1b4.tar.gz
libpinyin-dbf7a2dcd8e35f0db28e0a8f4ef324c12a3af1b4.tar.xz
libpinyin-dbf7a2dcd8e35f0db28e0a8f4ef324c12a3af1b4.zip
remove old parsers
Diffstat (limited to 'tests')
-rw-r--r--tests/storage/test_parser.cpp192
-rw-r--r--tests/storage/test_pinyin_table.cpp96
2 files changed, 0 insertions, 288 deletions
diff --git a/tests/storage/test_parser.cpp b/tests/storage/test_parser.cpp
deleted file mode 100644
index 7f10d78..0000000
--- a/tests/storage/test_parser.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * libpinyin
- * Library to deal with pinyin.
- *
- * Copyright (c) 2006 James Su <suzhe@tsinghua.org.cn>
- * Copyright (C) 2011 Peng Wu <alexepico@gmail.com>
- *
- * 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 <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include "pinyin_base.h"
-
-using namespace pinyin;
-
-static const char *help_msg =
- "Usage:\n"
- " test-parser [options]\n\n"
- " -i Use incomplete pinyin.\n"
- " -f table Use specified pinyin table file.\n"
- " -p parser Use specified parser instead of Default.\n"
- " parser could be:\n"
-#if 0
- " sp-stone\n"
-#endif
- " sp-zrm\n"
- " sp-ms\n"
- " sp-ziguang\n"
- " sp-abc\n"
-#if 0
- " sp-liushi\n"
-#endif
- " sp-pyjj\n"
- " sp-xhe\n"
- " zy-zhuyin\n"
- " zy-standard\n"
- " zy-hsu\n"
- " zy-ibm\n"
- " zy-gin-yieh\n"
- " zy-et\n"
- " zy-et26\n";
-
-void print_help(){
- printf("%s", help_msg);
-}
-
-int main (int argc, char * argv [])
-{
- NullPinyinValidator validator;
- PinyinKeyVector keys;
- PinyinKeyPosVector poses;
- PinyinCustomSettings custom;
- PinyinParser *parser = 0;
- //PinyinTable table;
- const char *tablefile = "../data/pinyin-table.txt";
-
- keys = g_array_new(FALSE, FALSE, sizeof( PinyinKey));
- poses = g_array_new(FALSE, FALSE, sizeof( PinyinKeyPos));
-
- int i = 0;
- while (i<argc) {
- if (++i >= argc) break;
-
- if ( !strcmp("-h", argv [i]) || !strcmp ("--help", argv [i]) ) {
- print_help ();
- return 0;
- }
-
- if ( !strcmp("-i", argv [i]) ) {
- custom.set_use_incomplete (true);
- continue;
- }
-
- if ( !strcmp("-p", argv [i]) ) {
- if (++i >= argc) {
- fprintf(stderr, "No argument for option %s.\n", argv [i-1]);
- return -1;
- }
- if (!strcmp (argv[i], "sp") || !strcmp (argv[i], "sp-default"))
- parser = new PinyinShuangPinParser ();
-#if 0
- else if (!strcmp (argv[i], "sp-stone"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_STONE);
-#endif
- else if (!strcmp (argv[i], "sp-zrm"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_ZRM);
- else if (!strcmp (argv[i], "sp-ms"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_MS);
- else if (!strcmp (argv[i], "sp-ziguang"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_ZIGUANG);
- else if (!strcmp (argv[i], "sp-abc"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_ABC);
-#if 0
- else if (!strcmp (argv[i], "sp-liushi"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_LIUSHI);
-#endif
- else if (!strcmp (argv[i], "sp-pyjj"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_PYJJ);
- else if (!strcmp (argv[i], "sp-xhe"))
- parser = new PinyinShuangPinParser (SHUANG_PIN_XHE);
- else if (!strcmp (argv[i], "zy") || !strcmp (argv[i], "zy-standard") || !strcmp (argv[i], "zy-default"))
- parser = new PinyinZhuYinParser ();
- else if (!strcmp (argv[i], "zy-hsu"))
- parser = new PinyinZhuYinParser (ZHUYIN_HSU);
- else if (!strcmp (argv[i], "zy-ibm"))
- parser = new PinyinZhuYinParser (ZHUYIN_IBM);
- else if (!strcmp (argv[i], "zy-gin-yieh"))
- parser = new PinyinZhuYinParser (ZHUYIN_GIN_YIEH);
- else if (!strcmp (argv[i], "zy-et"))
- parser = new PinyinZhuYinParser (ZHUYIN_ET);
- else if (!strcmp (argv[i], "zy-et26"))
- parser = new PinyinZhuYinParser (ZHUYIN_ET26);
- else if (!strcmp (argv[i], "zy-zhuyin"))
- parser = new PinyinZhuYinParser (ZHUYIN_ZHUYIN);
- else {
- fprintf(stderr, "Unknown Parser:%s.\n", argv[i]);
- print_help();
- exit(EINVAL);
- }
-
- continue;
- }
-
- if (!strcmp("-f", argv [i])) {
- if (++i >= argc) {
- fprintf(stderr, "No argument for option %s.\n", argv [i-1]);
- return -1;
- }
- tablefile = argv [i];
- continue;
- }
-
- fprintf(stderr, "Invalid option: %s.\n", argv [i]);
- return -1;
- };
-
- if (!parser) parser = new PinyinDefaultParser ();
-
- char * line = NULL;
- size_t len = 0;
-
- while (1) {
- printf("Input:"); fflush(stdout);
- getline(&line, &len, stdin);
-
- if (!strncmp (line, "quit", 4)) break;
-
- int len = parser->parse (validator, keys, poses,(const char *) line);
-
- printf("Parsed %d chars, %d keys:\n", len, keys->len);
-
- for (size_t i=0; i < keys->len; ++i){
- PinyinKey * key = &g_array_index(keys, PinyinKey, i);
- printf("%s ", key->get_key_string ());
- }
- printf("\n");
-
- for ( size_t i=0; i < poses->len; ++i){
- PinyinKeyPos * pos = &g_array_index(poses, PinyinKeyPos, i);
- printf("%d %ld ", pos->get_pos(), pos->get_length());
- }
- printf("\n");
-
- for (size_t i=0; i < keys->len; ++i){
- PinyinKey * key = &g_array_index(keys, PinyinKey, i);
- printf("%s ", key->get_key_zhuyin_string ());
- }
- printf("\n");
- }
-
- if (line)
- free(line);
-
- return 0;
-}
-
diff --git a/tests/storage/test_pinyin_table.cpp b/tests/storage/test_pinyin_table.cpp
deleted file mode 100644
index 6569874..0000000
--- a/tests/storage/test_pinyin_table.cpp
+++ /dev/null
@@ -1,96 +0,0 @@
-#include "timer.h"
-#include <string.h>
-#include <errno.h>
-#include "novel_types.h"
-#include "pinyin_base.h"
-#include "pinyin_large_table.h"
-
-using namespace pinyin;
-
-size_t bench_times = 1000;
-
-int main( int argc, char * argv[]){
-
- PinyinCustomSettings custom;
- PinyinLargeTable largetable(&custom);
-
- FILE * gbfile = fopen("../../data/gb_char.table", "r");
- if ( gbfile == NULL ) {
- fprintf(stderr, "open gb_char.table failed!\n");
- exit(ENOENT);
- }
-
- largetable.load_text(gbfile);
- fclose(gbfile);
-
- FILE * gbkfile = fopen("../../data/gbk_char.table","r");
- if ( gbkfile == NULL ) {
- fprintf(stderr, "open gbk_char.table failed!\n");
- exit(ENOENT);
- }
-
- largetable.load_text(gbkfile);
- fclose(gbkfile);
-
- MemoryChunk* new_chunk = new MemoryChunk;
- largetable.store(new_chunk);
- largetable.load(new_chunk);
-
- char* linebuf = NULL;
- size_t size = 0;
- while( getline(&linebuf, &size, stdin) ){
- linebuf[strlen(linebuf)-1] = '\0';
- if ( strcmp ( linebuf, "quit" ) == 0)
- break;
-
- PinyinDefaultParser parser;
- NullPinyinValidator validator;
- PinyinKeyVector keys;
- PinyinKeyPosVector poses;
-
- keys = g_array_new(FALSE, FALSE, sizeof( PinyinKey));
- poses = g_array_new(FALSE, FALSE, sizeof( PinyinKeyPos));
- parser.parse(validator, keys, poses, linebuf);
-
- guint32 start = record_time();
-
- PhraseIndexRanges ranges;
- for( size_t i = 0 ; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){
- ranges[i] = g_array_new(FALSE, FALSE, sizeof (PhraseIndexRange));
- }
- for ( size_t i = 0 ; i < bench_times; ++i){
- largetable.search(keys->len, (PinyinKey *)keys->data, ranges);
- }
-
- for( size_t i = 0 ; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){
- GArray * range = ranges[i];
- g_array_set_size( range, 0);
- }
- print_time(start, bench_times);
-
- largetable.search(keys->len, (PinyinKey *)keys->data, ranges);
- for( size_t i = 0 ; i < PHRASE_INDEX_LIBRARY_COUNT ; ++i){
- GArray * range = ranges[i];
- if (range) {
- 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);
-
- }
- }
-
- g_array_set_size(range, 0);
- }
-
- g_array_free(keys, TRUE);
- g_array_free(poses, TRUE);
- }
- if (linebuf)
- free(linebuf);
- return 0;
-}