From fbf33991cf8fb42858b2609760815ebb5d3ad7bc Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Thu, 8 Dec 2011 10:25:39 +0800 Subject: rename test_simple_lookup to test_pinyin_lookup --- tests/lookup/Makefile.am | 7 +-- tests/lookup/test_pinyin_lookup.cpp | 89 +++++++++++++++++++++++++++++++++++++ tests/lookup/test_simple_lookup.cpp | 89 ------------------------------------- 3 files changed, 93 insertions(+), 92 deletions(-) create mode 100644 tests/lookup/test_pinyin_lookup.cpp delete mode 100644 tests/lookup/test_simple_lookup.cpp (limited to 'tests/lookup') diff --git a/tests/lookup/Makefile.am b/tests/lookup/Makefile.am index 9c93dad..0329709 100644 --- a/tests/lookup/Makefile.am +++ b/tests/lookup/Makefile.am @@ -22,11 +22,12 @@ INCLUDES = -I$(top_srcdir)/src \ -I$(top_srcdir)/tests \ @GLIB2_CPPFLAGS@ -noinst_PROGRAMS = test_simple_lookup test_phrase_lookup +noinst_PROGRAMS = test_pinyin_lookup \ + test_phrase_lookup -test_simple_lookup_SOURCES = test_simple_lookup.cpp +test_pinyin_lookup_SOURCES = test_pinyin_lookup.cpp -test_simple_lookup_LDADD = ../../src/libpinyin_internal.la @GLIB2_LDFLAGS@ +test_pinyin_lookup_LDADD = ../../src/libpinyin_internal.la @GLIB2_LDFLAGS@ test_phrase_lookup_SOURCES = test_phrase_lookup.cpp diff --git a/tests/lookup/test_pinyin_lookup.cpp b/tests/lookup/test_pinyin_lookup.cpp new file mode 100644 index 0000000..dad9ddd --- /dev/null +++ b/tests/lookup/test_pinyin_lookup.cpp @@ -0,0 +1,89 @@ +#include "timer.h" +#include +#include "pinyin_internal.h" + +size_t bench_times = 100; + +int main( int argc, char * argv[]){ + + PinyinCustomSettings custom; + PinyinLargeTable largetable(&custom); + + MemoryChunk * new_chunk = new MemoryChunk; + new_chunk->load("../../data/pinyin_index.bin"); + largetable.load(new_chunk); + + BitmapPinyinValidator validator; + validator.initialize(&largetable); + + FacadePhraseIndex phrase_index; + new_chunk = new MemoryChunk; + new_chunk->load("../../data/gb_char.bin"); + phrase_index.load(1, new_chunk); + new_chunk = new MemoryChunk; + new_chunk->load("../../data/gbk_char.bin"); + phrase_index.load(2, new_chunk); + + Bigram system_bigram; + system_bigram.attach("../../data/bigram.db", ATTACH_READONLY); + Bigram user_bigram; + user_bigram.attach(NULL, ATTACH_CREATE|ATTACH_READWRITE); + + PinyinLookup pinyin_lookup(&custom, &largetable, &phrase_index, + &system_bigram, &user_bigram); + + 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; + + PinyinDefaultParser parser; + PinyinKeyVector keys; + PinyinKeyPosVector poses; + + validator.initialize(&largetable); + + keys = g_array_new(FALSE, FALSE, sizeof( PinyinKey)); + poses = g_array_new(FALSE, FALSE, sizeof( PinyinKeyPos)); + parser.parse(validator, keys, poses,linebuf); + + if ( 0 == keys->len ) + continue; + CandidateConstraints constraints = g_array_new(FALSE, FALSE, sizeof(lookup_constraint_t)); + + g_array_set_size(constraints, keys->len); + for ( size_t i = 0; i < constraints->len; ++i){ + lookup_constraint_t * constraint = &g_array_index(constraints, lookup_constraint_t, i); + constraint->m_type = NO_CONSTRAINT; + } + + MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); + + guint32 start_time = record_time(); + for ( size_t i = 0; i < bench_times; ++i) + pinyin_lookup.get_best_match(keys, constraints, results); + print_time(start_time, bench_times); + for ( size_t i = 0; i < results->len; ++i){ + phrase_token_t * token = &g_array_index(results, phrase_token_t, i); + if ( null_token == *token) + continue; + printf("pos:%ld,token:%d\t", i, *token); + } + printf("\n"); + char * sentence = NULL; + pinyin_lookup.convert_to_utf8(results, sentence); + printf("%s\n", sentence); + g_array_free(results, TRUE); + + g_array_free(keys, TRUE); + g_array_free(poses, TRUE); + g_free(sentence); + } + free(linebuf); +} diff --git a/tests/lookup/test_simple_lookup.cpp b/tests/lookup/test_simple_lookup.cpp deleted file mode 100644 index dad9ddd..0000000 --- a/tests/lookup/test_simple_lookup.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "timer.h" -#include -#include "pinyin_internal.h" - -size_t bench_times = 100; - -int main( int argc, char * argv[]){ - - PinyinCustomSettings custom; - PinyinLargeTable largetable(&custom); - - MemoryChunk * new_chunk = new MemoryChunk; - new_chunk->load("../../data/pinyin_index.bin"); - largetable.load(new_chunk); - - BitmapPinyinValidator validator; - validator.initialize(&largetable); - - FacadePhraseIndex phrase_index; - new_chunk = new MemoryChunk; - new_chunk->load("../../data/gb_char.bin"); - phrase_index.load(1, new_chunk); - new_chunk = new MemoryChunk; - new_chunk->load("../../data/gbk_char.bin"); - phrase_index.load(2, new_chunk); - - Bigram system_bigram; - system_bigram.attach("../../data/bigram.db", ATTACH_READONLY); - Bigram user_bigram; - user_bigram.attach(NULL, ATTACH_CREATE|ATTACH_READWRITE); - - PinyinLookup pinyin_lookup(&custom, &largetable, &phrase_index, - &system_bigram, &user_bigram); - - 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; - - PinyinDefaultParser parser; - PinyinKeyVector keys; - PinyinKeyPosVector poses; - - validator.initialize(&largetable); - - keys = g_array_new(FALSE, FALSE, sizeof( PinyinKey)); - poses = g_array_new(FALSE, FALSE, sizeof( PinyinKeyPos)); - parser.parse(validator, keys, poses,linebuf); - - if ( 0 == keys->len ) - continue; - CandidateConstraints constraints = g_array_new(FALSE, FALSE, sizeof(lookup_constraint_t)); - - g_array_set_size(constraints, keys->len); - for ( size_t i = 0; i < constraints->len; ++i){ - lookup_constraint_t * constraint = &g_array_index(constraints, lookup_constraint_t, i); - constraint->m_type = NO_CONSTRAINT; - } - - MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t)); - - guint32 start_time = record_time(); - for ( size_t i = 0; i < bench_times; ++i) - pinyin_lookup.get_best_match(keys, constraints, results); - print_time(start_time, bench_times); - for ( size_t i = 0; i < results->len; ++i){ - phrase_token_t * token = &g_array_index(results, phrase_token_t, i); - if ( null_token == *token) - continue; - printf("pos:%ld,token:%d\t", i, *token); - } - printf("\n"); - char * sentence = NULL; - pinyin_lookup.convert_to_utf8(results, sentence); - printf("%s\n", sentence); - g_array_free(results, TRUE); - - g_array_free(keys, TRUE); - g_array_free(poses, TRUE); - g_free(sentence); - } - free(linebuf); -} -- cgit