fixes phrase library load
authorPeng Wu <alexepico@gmail.com>
Tue, 19 Jun 2012 06:41:18 +0000 (14:41 +0800)
committerPeng Wu <alexepico@gmail.com>
Tue, 19 Jun 2012 06:41:18 +0000 (14:41 +0800)
src/include/novel_types.h
src/pinyin.cpp
src/storage/phrase_index.h

index c031f40..de249ca 100644 (file)
@@ -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 */
index 2e97ab5..a6c888c 100644 (file)
@@ -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.
  */
index 4deac16..94c8820 100644 (file)
@@ -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;
+    }
 };
  
 };