diff --git a/po/zh_CN.po b/po/zh_CN.po
index 805fa44..39105b5 100644
--- a/po/zh_CN.po
+++ b/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 "作為導引鍵"
diff --git a/po/zh_HK.po b/po/zh_HK.po
index 02f8832..0265a21 100644
--- a/po/zh_HK.po
+++ b/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 "作为导引键"
diff --git a/po/zh_TW.po b/po/zh_TW.po
index 02f8832..8a784f3 100644
--- a/po/zh_TW.po
+++ b/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 "作為導引鍵"
diff --git a/scripts/create_chewing_db.py b/scripts/create_chewing_db.py
new file mode 100755
index 0000000..76e4ec3
--- /dev/null
+++ b/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()
diff --git a/setup/ibus-pinyin-preferences.ui b/setup/ibus-pinyin-preferences.ui
index 5be2914..a388a6c 100644
--- a/setup/ibus-pinyin-preferences.ui
+++ b/setup/ibus-pinyin-preferences.ui
@@ -862,19 +862,6 @@
0
-
-
-
- 1
-
-
- 2
+ 1
@@ -898,7 +885,7 @@
True
- 3
+ 2
@@ -976,6 +963,49 @@
4
+
+
+
+ 3
+ 4
+
+
+
+
+
+ 1
+ 2
+ 3
+ 4
+
+
+
+
+
+ 2
+ 3
+ 3
+ 4
+
+
diff --git a/src/PYBopomofo.h b/src/PYBopomofo.h
index abd9813..74fd016 100644
--- a/src/PYBopomofo.h
+++ b/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_ */
diff --git a/src/PYBopomofoEditor.cc b/src/PYBopomofoEditor.cc
index e0a76c1..864d44c 100644
--- a/src/PYBopomofoEditor.cc
+++ b/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,11 +330,29 @@ 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)
{
@@ -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);
+}
+
};
diff --git a/src/PYBopomofoEditor.h b/src/PYBopomofoEditor.h
index 8ad9784..d45dd9b 100644
--- a/src/PYBopomofoEditor.h
+++ b/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 ();
diff --git a/src/PYBopomofoKeyboard.h b/src/PYBopomofoKeyboard.h
index f23d6a2..914aee9 100644
--- a/src/PYBopomofoKeyboard.h
+++ b/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 },
diff --git a/src/PYConfig.cc b/src/PYConfig.cc
index 114b74c..e05e91d 100644
--- a/src/PYConfig.cc
+++ b/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);
diff --git a/src/PYPhoneticEditor.cc b/src/PYPhoneticEditor.cc
index 44e0004..30d620e 100644
--- a/src/PYPhoneticEditor.cc
+++ b/src/PYPhoneticEditor.cc
@@ -38,6 +38,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;
diff --git a/src/PYPhoneticEditor.h b/src/PYPhoneticEditor.h
index 7ff07d9..b4cf0ec 100644
--- a/src/PYPhoneticEditor.h
+++ b/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 ();
diff --git a/src/PYPinyinParser.cc b/src/PYPinyinParser.cc
index 5114606..9253de9 100644
--- a/src/PYPinyinParser.cc
+++ b/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];