From e16682240d6df8777a7b6605811258b5ec71cec1 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 4 Jul 2012 13:19:47 +0800 Subject: [PATCH 1/7] fixes fillLookupTableByPage --- src/PYPPhoneticEditor.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index bdc05d8..a9b81ce 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -204,7 +204,7 @@ LibPinyinPhoneticEditor::fillLookupTableByPage (void) if (need_nr == 0) return FALSE; - String word, phrase_string; + String word; for (guint i = filled_nr; i < filled_nr + need_nr; i++) { if (i >= m_candidates->len) /* no more candidates */ break; @@ -212,14 +212,7 @@ LibPinyinPhoneticEditor::fillLookupTableByPage (void) lookup_candidate_t * candidate = &g_array_index (m_candidates, lookup_candidate_t, i); - phrase_string = candidate->m_phrase_string; - - if (BEST_MATCH_CANDIDATE == candidate->m_candidate_type) { - /* hide selected part */ - guint cursor = getLookupCursor (); - phrase_string = g_utf8_offset_to_pointer - (candidate->m_phrase_string, cursor); - } + const gchar * phrase_string = candidate->m_phrase_string; /* show get candidates. */ if (G_LIKELY (m_props.modeSimp ())) { -- 1.7.10.4 From a742f0e61a9cc81ee14f5d66070bede4a737fa18 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Wed, 4 Jul 2012 15:19:05 +0800 Subject: [PATCH 2/7] uses pinyin_load_phrase_library --- src/PYLibPinyin.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc index dd56fa7..621863b 100644 --- a/src/PYLibPinyin.cc +++ b/src/PYLibPinyin.cc @@ -64,6 +64,7 @@ LibPinyinBackEnd::allocPinyinInstance () g_free(userdir); userdir = NULL; } m_pinyin_context = pinyin_init ("/usr/share/libpinyin/data", userdir); + pinyin_load_phrase_library(m_pinyin_context, 2); g_free(userdir); } @@ -87,7 +88,8 @@ LibPinyinBackEnd::allocChewingInstance () if (retval) { g_free(userdir); userdir = NULL; } - m_chewing_context = pinyin_init ("/usr/share/libpinyin/data", NULL); + m_chewing_context = pinyin_init ("/usr/share/libpinyin/data", userdir); + pinyin_load_phrase_library(m_chewing_context, 2); g_free(userdir); } -- 1.7.10.4 From 155103f5528d450c05c8639c64c8fef2cb9e52bd Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 9 Jul 2012 13:11:45 +0800 Subject: [PATCH 3/7] fixes selectCandidate --- src/PYPPhoneticEditor.cc | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index a9b81ce..13e6011 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -363,10 +363,15 @@ LibPinyinPhoneticEditor::selectCandidate (guint i) lookup_cursor = pinyin_choose_candidate (m_instance, lookup_cursor, candidate); + if (DIVIDED_CANDIDATE == candidate->m_candidate_type || + RESPLIT_CANDIDATE == candidate->m_candidate_type) { + m_text = m_instance->m_raw_full_pinyin; + } pinyin_guess_sentence (m_instance); PinyinKeyPosVector & pinyin_poses = m_instance->m_pinyin_key_rests; if (lookup_cursor == pinyin_poses->len) { + pinyin_train(m_instance); commit(); return TRUE; } -- 1.7.10.4 From 87c19323a056947e42b573e92dfd4e29e320d99b Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 9 Jul 2012 13:20:15 +0800 Subject: [PATCH 4/7] improves full pinyin mode --- src/PYPFullPinyinEditor.cc | 11 +++++++++++ src/PYPFullPinyinEditor.h | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/PYPFullPinyinEditor.cc b/src/PYPFullPinyinEditor.cc index 00e3077..90e3f2f 100644 --- a/src/PYPFullPinyinEditor.cc +++ b/src/PYPFullPinyinEditor.cc @@ -125,3 +125,14 @@ LibPinyinFullPinyinEditor::updateAuxiliaryText () StaticText aux_text (m_buffer); Editor::updateAuxiliaryText (aux_text, TRUE); } + +void +LibPinyinFullPinyinEditor::update (void) +{ + guint lookup_cursor = getLookupCursor (); + pinyin_get_full_pinyin_candidates (m_instance, lookup_cursor, m_candidates); + + updateLookupTable (); + updatePreeditText (); + updateAuxiliaryText (); +} diff --git a/src/PYPFullPinyinEditor.h b/src/PYPFullPinyinEditor.h index a3b3df4..bb92655 100644 --- a/src/PYPFullPinyinEditor.h +++ b/src/PYPFullPinyinEditor.h @@ -38,10 +38,10 @@ public: virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers); virtual void reset (void); virtual void updateAuxiliaryText (void); - + virtual void update (void); protected: - /* TODO: to be implemented. */ + virtual void updatePinyin (void); }; -- 1.7.10.4 From a727155dc7dfeac0ac52e89c101003b9b2481a86 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 9 Jul 2012 13:29:18 +0800 Subject: [PATCH 5/7] use divided table for full pinyin --- src/PYLibPinyin.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/PYLibPinyin.cc b/src/PYLibPinyin.cc index 621863b..44dcaf2 100644 --- a/src/PYLibPinyin.cc +++ b/src/PYLibPinyin.cc @@ -143,7 +143,8 @@ LibPinyinBackEnd::setPinyinOptions (Config *config) } } - pinyin_option_t options = config->option() | USE_RESPLIT_TABLE; + pinyin_option_t options = config->option() + | USE_RESPLIT_TABLE | USE_DIVIDED_TABLE; pinyin_set_options (m_pinyin_context, options); return TRUE; } -- 1.7.10.4 From 2d8a65fdcefe0a8809740adb86f3d45d8c454793 Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Mon, 9 Jul 2012 15:50:04 +0800 Subject: [PATCH 6/7] fixes updatePinyin --- src/PYPBopomofoEditor.cc | 1 + src/PYPDoublePinyinEditor.cc | 1 + src/PYPFullPinyinEditor.cc | 1 + src/PYPPhoneticEditor.cc | 1 + 4 files changed, 4 insertions(+) diff --git a/src/PYPBopomofoEditor.cc b/src/PYPBopomofoEditor.cc index 331a651..1f201b5 100644 --- a/src/PYPBopomofoEditor.cc +++ b/src/PYPBopomofoEditor.cc @@ -241,6 +241,7 @@ LibPinyinBopomofoEditor::updatePinyin (void) m_pinyin_len = 0; /* TODO: check whether to replace "" with NULL. */ pinyin_parse_more_chewings (m_instance, ""); + pinyin_guess_sentence(m_instance); return; } diff --git a/src/PYPDoublePinyinEditor.cc b/src/PYPDoublePinyinEditor.cc index 8a39a42..7e690f4 100644 --- a/src/PYPDoublePinyinEditor.cc +++ b/src/PYPDoublePinyinEditor.cc @@ -103,6 +103,7 @@ LibPinyinDoublePinyinEditor::updatePinyin (void) m_pinyin_len = 0; /* TODO: check whether to replace "" with NULL. */ pinyin_parse_more_double_pinyins (m_instance, ""); + pinyin_guess_sentence(m_instance); return; } diff --git a/src/PYPFullPinyinEditor.cc b/src/PYPFullPinyinEditor.cc index 90e3f2f..eb58b6b 100644 --- a/src/PYPFullPinyinEditor.cc +++ b/src/PYPFullPinyinEditor.cc @@ -74,6 +74,7 @@ LibPinyinFullPinyinEditor::updatePinyin (void) m_pinyin_len = 0; /* TODO: check whether to replace "" with NULL. */ pinyin_parse_more_full_pinyins (m_instance, ""); + pinyin_guess_sentence(m_instance); return; } diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index 13e6011..5e47be3 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -339,6 +339,7 @@ LibPinyinPhoneticEditor::getLookupCursor (void) { PinyinKeyVector & pinyins = m_instance->m_pinyin_keys; guint lookup_cursor = getPinyinCursor (); + /* show candidates when pinyin cursor is at end. */ if (lookup_cursor == pinyins->len && m_pinyin_len == m_text.length()) lookup_cursor = 0; -- 1.7.10.4 From 9634aef4f33bca66f1634f305860131c22c722ac Mon Sep 17 00:00:00 2001 From: Peng Wu Date: Tue, 10 Jul 2012 14:00:14 +0800 Subject: [PATCH 7/7] fixes selectCandidate for full pinyin --- src/PYPPhoneticEditor.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PYPPhoneticEditor.cc b/src/PYPPhoneticEditor.cc index 5e47be3..b89db91 100644 --- a/src/PYPPhoneticEditor.cc +++ b/src/PYPPhoneticEditor.cc @@ -367,6 +367,7 @@ LibPinyinPhoneticEditor::selectCandidate (guint i) if (DIVIDED_CANDIDATE == candidate->m_candidate_type || RESPLIT_CANDIDATE == candidate->m_candidate_type) { m_text = m_instance->m_raw_full_pinyin; + updatePinyin (); } pinyin_guess_sentence (m_instance); -- 1.7.10.4