summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-09-09 15:07:56 +0800
committerPeng Wu <alexepico@gmail.com>2011-09-09 15:07:56 +0800
commit014d8c208f4edd8be02929893e270b1fbe17082b (patch)
tree765571268273b618da7cd85a304c67ee0ae42c5d
parent65d222d080b2bea07a49b981460435f39bff4f4b (diff)
downloadlibpinyin-014d8c208f4edd8be02929893e270b1fbe17082b.zip
libpinyin-014d8c208f4edd8be02929893e270b1fbe17082b.tar.gz
libpinyin-014d8c208f4edd8be02929893e270b1fbe17082b.tar.xz
update test case for pinyin header
-rw-r--r--tests/test_chewing.cpp23
-rw-r--r--tests/test_phrase.cpp11
-rw-r--r--tests/test_pinyin.cpp23
3 files changed, 20 insertions, 37 deletions
diff --git a/tests/test_chewing.cpp b/tests/test_chewing.cpp
index 912a932..8d88bb2 100644
--- a/tests/test_chewing.cpp
+++ b/tests/test_chewing.cpp
@@ -27,13 +27,7 @@ int main(int argc, char * argv[]){
pinyin_context_t * context =
pinyin_init("../data", "../data");
- PinyinKeyVector pinyin_keys = NULL;
- PinyinKeyPosVector pinyin_poses = NULL;
- CandidateConstraints constraints = NULL;
- MatchResults match_results = NULL;
-
- pinyin_alloc_auxiliary_arrays
- (context, &pinyin_keys, &pinyin_poses, &constraints, &match_results);
+ pinyin_instance_t * instance = pinyin_get_instance(context);
char* linebuf = NULL;
size_t size = 0;
@@ -47,23 +41,20 @@ int main(int argc, char * argv[]){
break;
pinyin_parse_more_chewings
- (context, linebuf, pinyin_keys, pinyin_poses);
- pinyin_update_constraints(context, pinyin_keys, constraints);
- pinyin_get_guessed_tokens(context, pinyin_keys, constraints,
- match_results);
+ (instance, linebuf);
+ pinyin_guess_sentence(instance);
char * sentence = NULL;
- pinyin_get_sentence (context, match_results, &sentence);
+ pinyin_get_sentence (instance, &sentence);
printf("%s\n", sentence);
g_free(sentence);
- pinyin_train(context, pinyin_keys, constraints, match_results);
- pinyin_reset(context, pinyin_keys, constraints, match_results);
+ pinyin_train(instance);
+ pinyin_reset(instance);
pinyin_save(context);
}
- pinyin_free_auxiliary_arrays
- (context, &pinyin_keys, &pinyin_poses, &constraints, &match_results);
+ pinyin_release_instance(instance);
pinyin_fini(context);
free(linebuf);
return 0;
diff --git a/tests/test_phrase.cpp b/tests/test_phrase.cpp
index 0137e08..31ed518 100644
--- a/tests/test_phrase.cpp
+++ b/tests/test_phrase.cpp
@@ -27,8 +27,7 @@ int main(int argc, char * argv[]){
pinyin_context_t * context =
pinyin_init("../data", "../data");
- TokenVector tokens =
- g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
+ pinyin_instance_t * instance = pinyin_get_instance(context);
char* linebuf = NULL;
size_t size = 0;
@@ -41,7 +40,9 @@ int main(int argc, char * argv[]){
if ( strcmp ( linebuf, "quit" ) == 0)
break;
- pinyin_phrase_segment(context, linebuf, tokens);
+ pinyin_phrase_segment(instance, linebuf);
+ MatchResults & tokens = instance->m_match_results;
+
for ( size_t i = 0; i < tokens->len; ++i ){
phrase_token_t token = g_array_index
(tokens, phrase_token_t, i);
@@ -50,7 +51,7 @@ int main(int argc, char * argv[]){
continue;
char * word = NULL;
- pinyin_translate_token(context, token, &word);
+ pinyin_translate_token(instance, token, &word);
printf("%s\t", word);
g_free(word);
}
@@ -59,8 +60,8 @@ int main(int argc, char * argv[]){
pinyin_save(context);
}
+ pinyin_release_instance(instance);
pinyin_fini(context);
- g_array_free(tokens, TRUE);
free(linebuf);
return 0;
}
diff --git a/tests/test_pinyin.cpp b/tests/test_pinyin.cpp
index d8bc49a..61671a4 100644
--- a/tests/test_pinyin.cpp
+++ b/tests/test_pinyin.cpp
@@ -27,13 +27,7 @@ int main(int argc, char * argv[]){
pinyin_context_t * context =
pinyin_init("../data", "../data");
- PinyinKeyVector pinyin_keys = NULL;
- PinyinKeyPosVector pinyin_poses = NULL;
- CandidateConstraints constraints = NULL;
- MatchResults match_results = NULL;
-
- pinyin_alloc_auxiliary_arrays
- (context, &pinyin_keys, &pinyin_poses, &constraints, &match_results);
+ pinyin_instance_t * instance = pinyin_get_instance(context);
char* linebuf = NULL;
size_t size = 0;
@@ -46,23 +40,20 @@ int main(int argc, char * argv[]){
if ( strcmp ( linebuf, "quit" ) == 0)
break;
- pinyin_parse_more_fulls(context, linebuf, pinyin_keys, pinyin_poses);
- pinyin_update_constraints(context, pinyin_keys, constraints);
- pinyin_get_guessed_tokens(context, pinyin_keys, constraints,
- match_results);
+ pinyin_parse_more_fulls(instance, linebuf);
+ pinyin_guess_sentence(instance);
char * sentence = NULL;
- pinyin_get_sentence (context, match_results, &sentence);
+ pinyin_get_sentence (instance, &sentence);
printf("%s\n", sentence);
g_free(sentence);
- pinyin_train(context, pinyin_keys, constraints, match_results);
- pinyin_reset(context, pinyin_keys, constraints, match_results);
+ pinyin_train(instance);
+ pinyin_reset(instance);
pinyin_save(context);
}
- pinyin_free_auxiliary_arrays
- (context, &pinyin_keys, &pinyin_poses, &constraints, &match_results);
+ pinyin_release_instance(instance);
pinyin_fini(context);
free(linebuf);
return 0;