summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2011-04-18 16:59:03 +0800
committerPeng Wu <alexepico@gmail.com>2011-04-18 16:59:03 +0800
commitc418ddb0e8ec1eb8e79cb03e83ed3ebc202d02e5 (patch)
tree6833bd52722b0655858f060e8b7fe0df7e0568ce /tests
parent0b113f330653b82be8a87af8b8b4ac826e72b296 (diff)
downloadlibpinyin-c418ddb0e8ec1eb8e79cb03e83ed3ebc202d02e5.tar.gz
libpinyin-c418ddb0e8ec1eb8e79cb03e83ed3ebc202d02e5.tar.xz
libpinyin-c418ddb0e8ec1eb8e79cb03e83ed3ebc202d02e5.zip
use new bi-gram
Diffstat (limited to 'tests')
-rw-r--r--tests/lookup/test_simple_lookup.cpp9
-rw-r--r--tests/storage/test_ngram.cpp41
2 files changed, 15 insertions, 35 deletions
diff --git a/tests/lookup/test_simple_lookup.cpp b/tests/lookup/test_simple_lookup.cpp
index 147d8d6..77fa797 100644
--- a/tests/lookup/test_simple_lookup.cpp
+++ b/tests/lookup/test_simple_lookup.cpp
@@ -44,10 +44,13 @@ int main( int argc, char * argv[]){
new_chunk->load("../../data/gbk_char.bin");
phrase_index.load(2, new_chunk);
- Bigram bigram;
- bigram.attach("../../data/bigram.db", "/tmp/bigram.db");
+ Bigram system_bigram;
+ system_bigram.attach("../../data/bigram.db", ATTACH_READONLY);
+ Bigram user_bigram;
+ user_bigram.attach("/tmp/bigram.db", ATTACH_CREATE|ATTACH_READWRITE);
- PinyinLookup pinyin_lookup(&custom, &largetable, &phrase_index, &bigram);
+ PinyinLookup pinyin_lookup(&custom, &largetable, &phrase_index,
+ &system_bigram, &user_bigram);
char* linebuf = (char *)malloc ( 1024 * sizeof (char) );
size_t size = 1024;
diff --git a/tests/storage/test_ngram.cpp b/tests/storage/test_ngram.cpp
index b93a55d..044cf59 100644
--- a/tests/storage/test_ngram.cpp
+++ b/tests/storage/test_ngram.cpp
@@ -39,7 +39,7 @@ int main(int argc, char * argv[]){
Bigram bigram;
- assert(bigram.attach(NULL, "/tmp/system.db"));
+ assert(bigram.attach("/tmp/test.db", ATTACH_CREATE|ATTACH_READWRITE));
bigram.store(1, &single_gram);
assert(single_gram.insert_freq(5, 8));
single_gram.set_total_freq(32);
@@ -47,37 +47,20 @@ int main(int argc, char * argv[]){
bigram.store(2, &single_gram);
- SingleGram * system, * user;
+ SingleGram * gram = NULL;
for ( int m = 1; m <= 2; ++m ){
printf("--------------------------------------------------------\n");
- bigram.load(m, system, user);
- assert(NULL == system);
+ bigram.load(m, gram);
g_array_set_size(array, 0);
range.m_range_begin = 0; range.m_range_end = 8;
- user->search(&range,array);
+ gram->search(&range,array);
for ( size_t i = 0; i < array->len; ++i){
BigramPhraseItem * item = &g_array_index(array, BigramPhraseItem, i);
printf("item:%d:%f\n", item->m_token, item->m_freq);
}
- delete user;
+ delete gram;
}
- bigram.attach("/tmp/system.db", NULL);
-
- for ( int m = 1; m <=2; ++m ){
- printf("--------------------------------------------------------\n");
- bigram.load(m, system, user);
- assert(NULL == user);
- g_array_set_size(array, 0);
- range.m_range_begin = 0; range.m_range_end = 8;
- system->search(&range,array);
- for ( size_t i = 0; i < array->len; ++i){
- BigramPhraseItem * item = &g_array_index(array, BigramPhraseItem, i);
- printf("item:%d:%f\n", item->m_token, item->m_freq);
- }
- delete system;
- }
-
printf("--------------------------------------------------------\n");
single_gram.prune();
g_array_set_size(array, 0);
@@ -92,18 +75,12 @@ int main(int argc, char * argv[]){
g_array_free(array, TRUE);
- GArray * system_items = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
- GArray * user_items = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
- bigram.get_all_items(system_items, user_items);
+ GArray * items = g_array_new(FALSE, FALSE, sizeof(phrase_token_t));
+ bigram.get_all_items(items);
printf("----------------------system----------------------------\n");
- for ( size_t i = 0; i < system_items->len; ++i){
- phrase_token_t * token = &g_array_index(system_items, phrase_token_t, i);
- printf("item:%d\n", *token);
- }
- printf("-----------------------user-----------------------------\n");
- for ( size_t i = 0; i < user_items->len; ++i){
- phrase_token_t * token = &g_array_index(user_items, phrase_token_t, i);
+ for ( size_t i = 0; i < items->len; ++i){
+ phrase_token_t * token = &g_array_index(items, phrase_token_t, i);
printf("item:%d\n", *token);
}
}