Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

rebase master #2

Open
wants to merge 17 commits into from

1 participant

Commits on Oct 20, 2010
  1. @yurenju

    add options for enter key, original feature is commit original englis…

    yurenju authored
    …h text, new feature is commit first candidate phrase
  2. @yurenju
Commits on Oct 21, 2010
  1. @yurenju
Commits on Oct 25, 2010
  1. @yurenju

    Merge ../ibus-pinyin-old

    yurenju authored
Commits on Oct 26, 2010
  1. @yurenju
Commits on Oct 28, 2010
  1. @yurenju
Commits on Oct 31, 2010
  1. @yurenju
  2. @yurenju

    refactory code

    yurenju authored
  3. @yurenju
Commits on Nov 4, 2010
  1. @yurenju

    add create_chewing_db.py

    yurenju authored
Commits on Nov 9, 2010
  1. @yurenju
  2. @yurenju
  3. @yurenju
  4. @yurenju

    refactory code

    yurenju authored
  5. @yurenju
  6. @yurenju

    add create_chewing_db.py

    yurenju authored
  7. @yurenju
This page is out of date. Refresh to see the latest.
View
9 po/zh_CN.po
@@ -324,3 +324,12 @@ msgstr "输出原本的英文字"
msgid "Commit first candidate"
msgstr "输出第一个候选词"
+
+msgid "Feature of Space key:"
+msgstr ":"
+
+msgid "Chinese first tone"
+msgstr "作為陰平聲調(一聲)"
+
+msgid "Guide key"
+msgstr "作為導引鍵"
View
9 po/zh_HK.po
@@ -319,3 +319,12 @@ msgstr "輸出原本的英文字"
msgid "Commit first candidate"
msgstr "輸出第一個候選詞"
+
+msgid "Feature of Space key:"
+msgstr "空白键功能:"
+
+msgid "Chinese first tone"
+msgstr "作为阴平声调(一声)"
+
+msgid "Guide key"
+msgstr "作为导引键"
View
9 po/zh_TW.po
@@ -319,3 +319,12 @@ msgstr "輸出原本的英文字"
msgid "Commit first candidate"
msgstr "輸出第一個候選詞"
+
+msgid "Feature of Space key:"
+msgstr "空白鍵功能:"
+
+msgid "Chinese first tone"
+msgstr "作為陰平聲調(一聲)"
+
+msgid "Guide key"
+msgstr "作為導引鍵"
View
157 scripts/create_chewing_db.py
@@ -0,0 +1,157 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+from pydict import *
+from id import *
+from valid_hanzi import *
+import sys
+import bopomofo
+
+def get_sheng_yun(pinyin):
+ if pinyin == None:
+ return None, None
+ if pinyin == "ng":
+ return "", "en"
+ for i in xrange(2, 0, -1):
+ t = pinyin[:i]
+ if t in SHENGMU_DICT:
+ return t, pinyin[len(t):]
+ return "", pinyin
+
+def parse_key2bpmf (buf):
+ result = {}
+ flag = False
+ for line in buf.split(u'\n'):
+ if flag == False and not "%keyname begin" in line:
+ continue
+ elif flag == False:
+ flag = True
+ continue
+
+ if "%keyname end" in line:
+ break
+ key, bpmf = line.split (' ', 2)
+ result[key] = bpmf
+ return result
+
+def get_firstline (lines):
+ for line in lines:
+ if "%chardef begin" in line:
+ return lines.index (line)+1
+ return 0
+
+def get_pinyin (keys, key2bpmf):
+ bpmf = ""
+ for k in keys:
+ if key2bpmf[k] == u"ˇ" or \
+ key2bpmf[k] == u"ˋ" or \
+ key2bpmf[k] == u"ˊ" or \
+ key2bpmf[k] == u"˙":
+ continue
+ bpmf = bpmf + key2bpmf[k]
+ return find_pinyin (bpmf)
+
+def find_pinyin (bpmf):
+ for key in bopomofo.bopomofo_pinyin_map.keys():
+ if bpmf == unicode(key,'utf8'):
+ return bopomofo.bopomofo_pinyin_map[key]
+ return None
+
+def bpmf2pinyin (bpmf):
+ for tone in [u"ˇ", u"ˋ", u"ˊ", u"˙"]:
+ bpmf = bpmf.replace (tone, "")
+ bpmf_list = bpmf.split()
+ pinyin = [find_pinyin (bpmf) for bpmf in bpmf_list]
+ return pinyin
+
+def read_phrases(cin, tsi):
+ buf = file (tsi).read()
+ buf = unicode(buf, "utf8")
+ buf = buf.strip()
+ lines = buf.split(u'\n')
+ for line in buf.split(u'\n'):
+ hanzi, freq, bpmf = line.split (u' ', 2)
+ try:
+ freq = float (freq) + 0.1
+ except:
+ continue
+ pinyin = bpmf2pinyin (bpmf)
+ if len(pinyin) == 0 or pinyin[0] == None: continue
+ yield hanzi, freq, pinyin
+
+'''
+ buf = file(cin).read()
+ buf = unicode(buf, "utf8")
+ buf = buf.strip()
+ key2bpmf = parse_key2bpmf (buf)
+ lines = buf.split(u'\n')
+ first = get_firstline (lines)
+ for i in range (first, len(lines)):
+ #hanzi, freq, flag, pinyin = lines[i].split(u' ', 2)
+ if "%chardef end" in lines[i]:
+ break
+ keys, hanzi = lines[i].split(u' ', 2)
+ freq = float(0.1)
+ pinyin = get_pinyin (keys, key2bpmf)
+ if pinyin == None: continue
+ yield hanzi, freq, [pinyin]
+'''
+
+
+def create_db(phone, tsi):
+ # import sqlite3
+ # con = sqlite3.connect("main.db")
+ # con.execute ("PRAGMA synchronous = NORMAL;")
+ # con.execute ("PRAGMA temp_store = MEMORY;")
+ # con.execute ("PRAGMA default_cache_size = 5000;")
+ print "PRAGMA synchronous = NORMAL;"
+ print "PRAGMA temp_store = MEMORY;"
+ print "PRAGMA default_cache_size = 5000;"
+
+
+ sql = "CREATE TABLE py_phrase_%d (phrase TEXT, freq INTEGER, %s);"
+ for i in range(0, 16):
+ column = []
+ for j in range(0, i + 1):
+ column.append ("s%d INTEGER" % j)
+ column.append ("y%d INTEGER" % j)
+ print sql % (i, ",".join(column))
+ # con.execute(sql % (i, column))
+ # con.commit()
+
+ records = list(read_phrases(phone, tsi))
+ records.sort(lambda a, b: 1 if a[1] > b[1] else -1)
+ records_new = []
+ i = 0
+ max_freq = 0.0
+ for hanzi, freq, pinyin in records:
+ if max_freq / freq < 1 - 0.001:
+ max_freq = freq
+ i = i + 1
+ records_new.append((hanzi, i, pinyin))
+ records_new.reverse()
+
+ print "BEGIN;"
+ insert_sql = "INSERT INTO py_phrase_%d VALUES (%s);"
+ for hanzi, freq, pinyin in records_new:
+ columns = []
+ for py in pinyin:
+ s, y = get_sheng_yun(py)
+ try:
+ s, y = pinyin_id[s], pinyin_id[y]
+ except:
+ print "hanzi: %s, pinyin: %s" % (hanzi, pinyin)
+ sys.exit(1)
+ columns.append(s)
+ columns.append(y)
+ values = "'%s', %d, %s" % (hanzi.encode("utf8"), freq, ",".join(map(str,columns)))
+
+ sql = insert_sql % (len(hanzi) - 1, values)
+ print sql
+ print "COMMIT;"
+ print "VACUUM;"
+
+def main():
+ create_db(sys.argv[1], sys.argv[2])
+
+if __name__ == "__main__":
+ main()
View
60 setup/ibus-pinyin-preferences.ui
@@ -863,19 +863,6 @@
</packing>
</child>
<child>
- <object class="GtkCheckButton" id="GuideKey">
- <property name="label" translatable="yes">Enable Guidekey for Candidates Selection</property>
- <property name="visible">True</property>
- <property name="can_focus">True</property>
- <property name="receives_default">False</property>
- <property name="active">True</property>
- <property name="draw_indicator">True</property>
- </object>
- <packing>
- <property name="position">1</property>
- </packing>
- </child>
- <child>
<object class="GtkCheckButton" id="AuxiliarySelectKey_F">
<property name="label" translatable="yes">Enable Auxiliary Select Keys F1 .. F10</property>
<property name="visible">True</property>
@@ -885,7 +872,7 @@
<property name="draw_indicator">True</property>
</object>
<packing>
- <property name="position">2</property>
+ <property name="position">1</property>
</packing>
</child>
<child>
@@ -898,7 +885,7 @@
<property name="draw_indicator">True</property>
</object>
<packing>
- <property name="position">3</property>
+ <property name="position">2</property>
</packing>
</child>
</object>
@@ -976,6 +963,49 @@
<property name="bottom_attach">4</property>
</packing>
</child>
+ <child>
+ <object class="GtkLabel" id="LabelSpace">
+ <property name="visible">True</property>
+ <property name="xalign">0</property>
+ <property name="label" translatable="yes">Feature of Space key:</property>
+ </object>
+ <packing>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="GuideKey">
+ <property name="label" translatable="yes">Guide key</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="draw_indicator">True</property>
+ <property name="group">FirstTone</property>
+ </object>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkRadioButton" id="FirstTone">
+ <property name="label" translatable="yes">Chinese first tone</property>
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="receives_default">False</property>
+ <property name="active">True</property>
+ <property name="draw_indicator">True</property>
+ </object>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ </packing>
+ </child>
</object>
</child>
</object>
View
11 src/PYBopomofo.h
@@ -62,10 +62,11 @@
#define BOPOMOFO_ANG (35)
#define BOPOMOFO_ENG (36)
#define BOPOMOFO_ER (37)
-#define BOPOMOFO_TONE_2 (38)
-#define BOPOMOFO_TONE_3 (39)
-#define BOPOMOFO_TONE_4 (40)
-#define BOPOMOFO_TONE_5 (41)
+#define BOPOMOFO_TONE_1 (38)
+#define BOPOMOFO_TONE_2 (39)
+#define BOPOMOFO_TONE_3 (40)
+#define BOPOMOFO_TONE_4 (41)
+#define BOPOMOFO_TONE_5 (42)
const static wchar_t bopomofo_char[] = {
L'\0', L'', L'', L'', L'', L'', L'', L'', L'', L'', L'',
@@ -74,7 +75,7 @@ const static wchar_t bopomofo_char[] = {
L'', L'', L'', L'', L'', L'', L'', L'', L'', L'', L'',
L'', L'', L'', L'', L'',
- L'ˊ', L'ˇ', L'ˋ', L'˙',
+ L'ˉ', L'ˊ', L'ˇ', L'ˋ', L'˙',
};
#endif /* __PY_BOPOMOFO_H_ */
View
45 src/PYBopomofoEditor.cc
@@ -63,6 +63,14 @@ BopomofoEditor::insert (gint ch)
if (G_UNLIKELY (m_text.length () >= MAX_PINYIN_LEN))
return TRUE;
+ /* enable first tone & first char is space */
+ if (!m_config.guideKey () &&
+ keyvalToBopomofo (ch) == BOPOMOFO_TONE_1 &&
+ m_text.length () == 0)
+ {
+ return FALSE;
+ }
+
m_text.insert (m_cursor++, ch);
if (G_UNLIKELY (!(m_config.option () & PINYIN_INCOMPLETE_PINYIN))) {
@@ -322,12 +330,30 @@ BopomofoEditor::processBopomofo (guint keyval, guint keycode, guint modifiers)
if (keyvalToBopomofo (keyval) == BOPOMOFO_ZERO)
return FALSE;
+ if (keyvalToBopomofo (keyval) == BOPOMOFO_TONE_1 &&
+ m_select_mode == TRUE)
+ return FALSE;
+
m_select_mode = FALSE;
return insert (keyval);
}
gboolean
+BopomofoEditor::processEnter (guint keyval, guint keycode, guint modifiers)
+{
+ if (m_config.enterKey())
+ {
+ m_select_mode = TRUE;
+ return commitFirstCandidate (keyval, keycode, modifiers);
+ }
+ else
+ {
+ return PhoneticEditor::processFunctionKey (keyval, keycode, modifiers);
+ }
+}
+
+gboolean
BopomofoEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
{
modifiers &= (IBUS_SHIFT_MASK |
@@ -353,6 +379,9 @@ BopomofoEditor::processKeyEvent (guint keyval, guint keycode, guint modifiers)
m_select_mode = TRUE;
return processSpace (keyval, keycode, modifiers);
+ case IBUS_Return:
+ case IBUS_KP_Enter:
+ return processEnter (keyval, keycode, modifiers);
case IBUS_Up:
case IBUS_KP_Up:
case IBUS_Down:
@@ -429,7 +458,7 @@ BopomofoEditor::updateAuxiliaryText (void)
for (guint sj = 0; m_pinyin[i]->bopomofo[sj] == bopomofo_char[keyvalToBopomofo(m_text.c_str()[si])] ; si++,sj++);
if (si < m_text_len) {
gint ch = keyvalToBopomofo(m_text.c_str()[si]);
- if (ch >= BOPOMOFO_TONE_2 && ch <= BOPOMOFO_TONE_5) {
+ if (ch >= BOPOMOFO_TONE_1 && ch <= BOPOMOFO_TONE_5) {
m_buffer.appendUnichar(bopomofo_char[ch]);
++si;
}
@@ -456,12 +485,7 @@ BopomofoEditor::commit (void)
m_buffer.clear ();
- if (!m_select_mode && m_config.enterKey ()) {
- m_phrase_editor.selectCandidate(0);
- }
-
-
- if (m_select_mode || m_config.enterKey ()) {
+ if (m_select_mode) {
m_buffer << m_phrase_editor.selectedString ();
const gchar *p;
@@ -630,4 +654,11 @@ BopomofoEditor::keyvalToBopomofo(gint ch)
return brs[1];
}
+void
+BopomofoEditor::candidateClicked (guint index, guint button, guint state)
+{
+ m_select_mode = TRUE;
+ selectCandidateInPage (index);
+}
+
};
View
3  src/PYBopomofoEditor.h
@@ -45,6 +45,9 @@ class BopomofoEditor : public PhoneticEditor {
gboolean processSelectKey (guint keyval, guint keycode, guint modifiers);
gboolean processBopomofo (guint keyval, guint keycode, guint modifiers);
gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers);
+ gboolean processEnter (guint keyval, guint keycode, guint modifiers);
+
+ void candidateClicked (guint index, guint button, guint state);
void updateAuxiliaryText ();
void updateLookupTable ();
View
6 src/PYBopomofoKeyboard.h
@@ -25,8 +25,9 @@
#include "PYBopomofo.h"
static const guint8
-bopomofo_keyboard[][41][2] = {
+bopomofo_keyboard[][42][2] = {
{
+ { ' ' , BOPOMOFO_TONE_1 },
{ ',' , BOPOMOFO_E2 },
{ '-' , BOPOMOFO_ER },
{ '.' , BOPOMOFO_OU },
@@ -70,6 +71,7 @@ bopomofo_keyboard[][41][2] = {
{ 'z' , BOPOMOFO_F },
},
{
+ { ' ' , BOPOMOFO_TONE_1 },
{ '\'', BOPOMOFO_V },
{ ',' , BOPOMOFO_E2 },
{ '-' , BOPOMOFO_I },
@@ -113,6 +115,7 @@ bopomofo_keyboard[][41][2] = {
{ 'z' , BOPOMOFO_TONE_4 },
},
{
+ { ' ' , BOPOMOFO_TONE_1 },
{ '\'', BOPOMOFO_C },
{ ',' , BOPOMOFO_ZH },
{ '-' , BOPOMOFO_ENG },
@@ -156,6 +159,7 @@ bopomofo_keyboard[][41][2] = {
{ 'z' , BOPOMOFO_AO },
},
{
+ { ' ' , BOPOMOFO_TONE_1 },
{ ',' , BOPOMOFO_TONE_3 },
{ '-' , BOPOMOFO_H },
{ '.' , BOPOMOFO_TONE_4 },
View
2  src/PYConfig.cc
@@ -458,7 +458,7 @@ BopomofoConfig::readDefaultValues (void)
m_select_keys = read (CONFIG_SELECT_KEYS, 0);
if (m_select_keys >= 9) m_select_keys = 0;
- m_guide_key = read (CONFIG_GUIDE_KEY, true);
+ m_guide_key = read (CONFIG_GUIDE_KEY, false);
m_auxiliary_select_key_f = read (CONFIG_AUXILIARY_SELECT_KEY_F, true);
m_auxiliary_select_key_kp = read (CONFIG_AUXILIARY_SELECT_KEY_KP, true);
m_enter_key = read (CONFIG_ENTER_KEY, true);
View
6 src/PYPhoneticEditor.cc
@@ -39,6 +39,12 @@ PhoneticEditor::PhoneticEditor (PinyinProperties & props, Config & config)
gboolean
PhoneticEditor::processSpace (guint keyval, guint keycode, guint modifiers)
{
+ return commitFirstCandidate (keyval, keycode, modifiers);
+}
+
+gboolean
+PhoneticEditor::commitFirstCandidate (guint keyval, guint keycode, guint modifiers)
+{
if (!m_text)
return FALSE;
if (cmshm_filter (modifiers) != 0)
View
1  src/PYPhoneticEditor.h
@@ -47,6 +47,7 @@ class PhoneticEditor : public Editor {
virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers);
virtual gboolean processSpace (guint keyval, guint keycode, guint modifiers);
virtual gboolean processFunctionKey (guint keyval, guint keycode, guint modifiers);
+ virtual gboolean commitFirstCandidate (guint keyval, guint keycode, guint modifiers);
virtual void updateLookupTable ();
virtual void updateLookupTableFast ();
virtual gboolean fillLookupTableByPage ();
View
3  src/PYPinyinParser.cc
@@ -291,7 +291,8 @@ bopomofo_cmp (const void *p1, const void *p2)
gboolean
PinyinParser::isBopomofoToneChar (const wchar_t ch)
{
- return ch == bopomofo_char[BOPOMOFO_TONE_2]
+ return ch == bopomofo_char[BOPOMOFO_TONE_1]
+ || ch == bopomofo_char[BOPOMOFO_TONE_2]
|| ch == bopomofo_char[BOPOMOFO_TONE_3]
|| ch == bopomofo_char[BOPOMOFO_TONE_4]
|| ch == bopomofo_char[BOPOMOFO_TONE_5];
Something went wrong with that request. Please try again.