summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-07-20 19:37:19 +0800
committerPeng Wu <alexepico@gmail.com>2011-07-20 19:37:19 +0800
commit9e0f9cf94da0a656cc810fb5d96ec4774152871d (patch)
tree692fa52953d9bb88697ff1bf17635799ef1ec9dc /tests
parent71d760a003d296413ab87aea4235dc96c9e68e69 (diff)
downloadlibpinyin-9e0f9cf94da0a656cc810fb5d96ec4774152871d.tar.gz
libpinyin-9e0f9cf94da0a656cc810fb5d96ec4774152871d.tar.xz
libpinyin-9e0f9cf94da0a656cc810fb5d96ec4774152871d.zip
refine test phrase lookup
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/test_phrase_lookup.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/tests/lookup/test_phrase_lookup.cpp b/tests/lookup/test_phrase_lookup.cpp
index 0333290..dd8bf80 100644
--- a/tests/lookup/test_phrase_lookup.cpp
+++ b/tests/lookup/test_phrase_lookup.cpp
@@ -24,16 +24,15 @@
#include <locale.h>
#include "pinyin.h"
-PhraseLookup * g_phrase_lookup = NULL;
-
void print_help(){
printf("Usage: test_phrase_lookup\n");
}
-bool try_phrase_lookup(utf16_t * utf16, glong utf16_len){
+bool try_phrase_lookup(PhraseLookup * phrase_lookup,
+ utf16_t * utf16, glong utf16_len){
char * result_string = NULL;
MatchResults results = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
- g_phrase_lookup->get_best_match(utf16_len, utf16, results);
+ phrase_lookup->get_best_match(utf16_len, utf16, results);
#if 0
for ( size_t i = 0; i < results->len; ++i) {
phrase_token_t * token = &g_array_index(results, phrase_token_t, i);
@@ -43,7 +42,7 @@ bool try_phrase_lookup(utf16_t * utf16, glong utf16_len){
}
printf("\n");
#endif
- g_phrase_lookup->convert_to_utf8(results, "\n", result_string);
+ phrase_lookup->convert_to_utf8(results, "\n", result_string);
if (result_string)
printf("%s\n", result_string);
else
@@ -91,8 +90,8 @@ int main(int argc, char * argv[]){
Bigram user_bigram;
//init phrase lookup
- g_phrase_lookup = new PhraseLookup(&phrase_table, &phrase_index,
- &system_bigram, &user_bigram);
+ PhraseLookup phrase_lookup(&phrase_table, &phrase_index,
+ &system_bigram, &user_bigram);
//try one sentence
char * linebuf = NULL;
@@ -116,11 +115,10 @@ int main(int argc, char * argv[]){
continue;
}
- try_phrase_lookup(sentence, len);
+ try_phrase_lookup(&phrase_lookup, sentence, len);
g_free(sentence);
}
- delete g_phrase_lookup;
free(linebuf);
return 0;
}