4 #include "pinyin_internal.h"
5 #include "tests_helper.h"
7 size_t bench_times = 100000;
9 int main(int argc, char * argv[]){
10 PhraseItem phrase_item;
12 ChewingKey key1 = ChewingKey(CHEWING_CH, CHEWING_ZERO_MIDDLE, CHEWING_ENG);
13 ChewingKey key2 = ChewingKey(CHEWING_SH, CHEWING_ZERO_MIDDLE, CHEWING_ANG);
16 phrase_item.set_phrase_string(1, &string1);
17 phrase_item.append_pronunciation(&key1, 100);
18 phrase_item.append_pronunciation(&key2, 300);
20 assert(phrase_item.get_phrase_length() == 1);
24 phrase_item.get_nth_pronunciation(0, &key3, freq);
27 phrase_item.get_nth_pronunciation(1, &key3, freq);
31 pinyin_option_t options = 0;
32 gfloat poss = phrase_item.get_pronunciation_possibility(options, &key1);
33 printf("pinyin possiblitiy:%f\n", poss);
35 assert(phrase_item.get_unigram_frequency() == 0);
38 phrase_item.get_phrase_string(&string2);
39 assert(string1 == string2);
41 FacadePhraseIndex phrase_index_test;
42 assert(!phrase_index_test.add_phrase_item(1, &phrase_item));
44 MemoryChunk* chunk = new MemoryChunk;
45 assert(phrase_index_test.store(0, chunk));
46 assert(phrase_index_test.load(0, chunk));
49 guint32 time = record_time();
50 for ( size_t i = 0; i < bench_times; ++i){
51 phrase_index_test.get_phrase_item(1, item2);
52 assert(item2.get_unigram_frequency() == 0);
53 assert(item2.get_n_pronunciation() == 2);
54 assert(item2.get_phrase_length() == 1);
55 assert(item2.get_pronunciation_possibility(options, &key2) == 0.75);
57 print_time(time, bench_times);
61 phrase_index_test.get_phrase_item(1, item3);
62 item3.increase_pronunciation_possibility(options, &key1, 200);
63 assert(item3.get_pronunciation_possibility(options, &key1) == 0.5) ;
68 phrase_index_test.get_phrase_item(1, item5);
69 gfloat poss = item5.get_pronunciation_possibility(options, &key1);
70 printf("pinyin poss:%f\n", poss);
74 FacadePhraseIndex phrase_index;
75 if (!load_phrase_table(NULL, NULL, &phrase_index))
78 phrase_index.compact();
80 MemoryChunk* store1 = new MemoryChunk;
81 phrase_index.store(1, store1);
82 phrase_index.load(1, store1);
84 MemoryChunk* store2 = new MemoryChunk;
85 phrase_index.store(2, store2);
86 phrase_index.load(2, store2);
88 phrase_index.compact();
90 phrase_index.get_phrase_item(16870553, item2);
91 assert( item2.get_phrase_length() == 14);
92 assert( item2.get_n_pronunciation() == 1);
95 item2.get_phrase_string(buf);
96 char * string = g_ucs4_to_utf8( buf, 14, NULL, NULL, NULL);
97 printf("%s\n", string);
101 phrase_index.add_unigram_frequency(16870553, delta);
102 phrase_index.get_phrase_item(16870553, item2);
103 assert( item2.get_unigram_frequency() == 3);
105 phrase_index.get_phrase_item(16777222, item2);
106 assert(item2.get_phrase_length() == 1);
107 assert(item2.get_n_pronunciation() == 6);