diff options
author | Peng Wu <alexepico@gmail.com> | 2012-06-19 14:41:18 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-06-19 14:41:18 +0800 |
commit | 3120e3f3208f3b0c9e30a811102e0d2ea9c5e29e (patch) | |
tree | 3a2a3d3ecb0ef125687c00773a6e06fe01d52c66 /src | |
parent | 05945ae69172859cb26f33363faccb76cb189629 (diff) | |
download | libpinyin-3120e3f3208f3b0c9e30a811102e0d2ea9c5e29e.tar.gz libpinyin-3120e3f3208f3b0c9e30a811102e0d2ea9c5e29e.tar.xz libpinyin-3120e3f3208f3b0c9e30a811102e0d2ea9c5e29e.zip |
fixes phrase library load
Diffstat (limited to 'src')
-rw-r--r-- | src/include/novel_types.h | 3 | ||||
-rw-r--r-- | src/pinyin.cpp | 18 | ||||
-rw-r--r-- | src/storage/phrase_index.h | 11 |
3 files changed, 22 insertions, 10 deletions
diff --git a/src/include/novel_types.h b/src/include/novel_types.h index c031f40..de249ca 100644 --- a/src/include/novel_types.h +++ b/src/include/novel_types.h @@ -90,7 +90,8 @@ enum PhraseIndexResult{ ERROR_NO_ITEM, /* item has a null slot */ ERROR_OUT_OF_RANGE, /* beyond the end of the sub phrase index */ ERROR_FILE_CORRUPTION, /* file is corrupted */ - ERROR_INTEGER_OVERFLOW /* integer is overflowed */ + ERROR_INTEGER_OVERFLOW, /* integer is overflowed */ + ERROR_ALREADY_EXISTS /* the sub phrase already exists. */ }; /* For N-gram */ diff --git a/src/pinyin.cpp b/src/pinyin.cpp index 2e97ab5..a6c888c 100644 --- a/src/pinyin.cpp +++ b/src/pinyin.cpp @@ -229,11 +229,15 @@ bool pinyin_load_phrase_library(pinyin_context_t * context, chunkfilename = g_build_filename(context->m_user_dir, phrasefilename, NULL); - /* TODO: check bin file exists. if not, create a new one. */ - chunk->load(chunkfilename); - g_free(chunkfilename); + /* check bin file exists. if not, create a new one. */ + if (chunk->load(chunkfilename)) { + context->m_phrase_index->load(index, chunk); + } else { + delete chunk; + context->m_phrase_index->create_sub_phrase(index); + } - context->m_phrase_index->load(index, chunk); + g_free(chunkfilename); return true; } @@ -1321,9 +1325,5 @@ bool pinyin_reset(pinyin_instance_t * instance){ } /** - * TODO: to be implemented. - * Note: prefix is the text before the pre-edit string. - * bool pinyin_get_guessed_sentence_with_prefix(...); - * bool pinyin_get_candidates_with_prefix(...); - * For context-dependent order of the candidates list. + * Note: prefix is the text before the pre-edit string. */ diff --git a/src/storage/phrase_index.h b/src/storage/phrase_index.h index 4deac16..94c8820 100644 --- a/src/storage/phrase_index.h +++ b/src/storage/phrase_index.h @@ -707,6 +707,17 @@ public: } return true; } + + int create_sub_phrase(guint8 index) { + SubPhraseIndex * & sub_phrase = m_sub_phrase_indices[index]; + if (sub_phrase) { + return ERROR_ALREADY_EXISTS; + } + + sub_phrase = new SubPhraseIndex; + + return ERROR_OK; + } }; }; |