write update pinyin
authorPeng Wu <alexepico@gmail.com>
Tue, 20 Sep 2011 05:52:05 +0000 (13:52 +0800)
committerPeng Wu <alexepico@gmail.com>
Thu, 22 Dec 2011 04:23:12 +0000 (12:23 +0800)
src/PYPFullPinyinEditor.cc
src/PYPFullPinyinEditor.h

index 9712d97..5194ef8 100644 (file)
@@ -62,3 +62,34 @@ LibPinyinFullPinyinEditor::processKeyEvent (guint keyval,
     return LibPinyinPinyinEditor::processKeyEvent (keyval, keycode, modifiers);
 }
 
+void
+LibPinyinFullPinyinEditor::updatePinyin (void)
+{
+    if (G_UNLIKELY (m_text.empty ())) {
+        m_pinyins.clear ();
+        m_pinyin_len = 0;
+        return;
+    }
+
+    m_pinyin_len = PinyinParser::parse (m_text,               // text
+                                        m_text.length (),     // text length
+                                        m_config.option (),   // option
+                                        m_pinyins,            // result
+                                        MAX_PHRASE_LEN);      // max result length
+
+    /* propagate to libpinyin */
+    g_array_set_size (m_instance->m_pinyin_keys, 0);
+    g_array_set_size (m_instance->m_pinyin_poses, 0);
+
+    PinyinKey key; PinyinKeyPos pos;
+    PinyinArray::const_iterator iter = m_pinyins.begin ();
+    for ( ; iter != m_pinyins.end (); ++iter ) {
+        PinyinSegment py = *iter;
+        pinyin_parse_full_pinyin (m_instance, py.pinyin->text, &key);
+        pos.set_pos (py.begin); pos.set_length (py.len);
+        g_array_append_val(m_instance->m_pinyin_keys, key);
+        g_array_append_val(m_instance->m_pinyin_poses, pos);
+    }
+
+    pinyin_guess_sentence(m_instance);
+}
index a6e74c4..afb52d5 100644 (file)
@@ -52,6 +52,8 @@ public:
 
 protected:
     /* TODO: to be implemented. */
+    void updatePinyin (void);
+
 };
 
 };