[ibus-typing-booster] libyokan_port_20130711: With libyokan, you get suggestions from libyokan library itself, so update_candidate function should be present in the engine class not in the editor class (d209a6b)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
>---------------------------------------------------------------
commit d209a6bb297fccf3ac38ce643b17857213cd2468
Author: anish <apatil(a)redhat.com>
Date: Tue Jul 9 19:18:12 2013 +0530
With libyokan,you get suggestions from libyokan library itself, so update_candidate function should be present in the engine class not in the editor class
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 108 ++++++++++----------------
1 files changed, 40 insertions(+), 68 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index e59c46a..e16fe5f 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -288,73 +288,6 @@ class editor(object):
'''
self._typed_string_cursor = len(self._typed_string)
- def append_candidate_to_lookup_table(self, phrase=u'', user_freq=0):
- '''append candidate to lookup_table'''
- if not phrase:
- return
- phrase = unicodedata.normalize('NFC', phrase)
- transliterated_string = unicodedata.normalize('NFC', self._transliterated_string)
- attrs = IBus.AttrList ()
- if not phrase.startswith(transliterated_string):
- # this is a candidate which does not start exactly
- # as the transliterated user input, i.e. it is a suggestion
- # for a spelling correction:
- if debug_level > 0:
- phrase = phrase + u' ✓'
- attrs.append(IBus.attr_foreground_new(rgb(0xff,0x00,0x00), 0, len(phrase)))
- elif user_freq > 10:
- # this is a frequently used phrase:
- attrs.append(IBus.attr_foreground_new(rgb(0xff,0x7f,0x00), 0, len(phrase)))
- else:
- # this is a system phrase that has been used less then 10 times or maybe never:
- attrs.append(IBus.attr_foreground_new(rgb(0x00,0x00,0x00), 0, len(phrase)))
- if debug_level > 0:
- phrase += u' ' + str(user_freq)
- attrs.append(IBus.attr_foreground_new(
- rgb(0x00,0xff,0x00), len(phrase) - len(str(user_freq)), len(phrase)))
- text = IBus.Text.new_from_string(phrase)
- i = 0
- while attrs.get(i) != None:
- attr = attrs.get(i)
- text.append_attribute(attr.get_attr_type(),
- attr.get_value(),
- attr.get_start_index(),
- attr.get_end_index())
- i += 1
- self._lookup_table.append_candidate(text)
- self._lookup_table.set_cursor_visible(False)
-
- def update_candidates (self):
- '''Update lookuptable'''
- if self._typed_string == self._typed_string_when_update_candidates_was_last_called:
- # The input did not change since we came here last, do nothing and leave
- # candidates and lookup table unchanged:
- return True
- self._typed_string_when_update_candidates_was_last_called = self._typed_string[:]
- self._lookup_table.clear()
- self._lookup_table.set_cursor_visible(False)
- self._candidates = []
- prefix_length = 0
- prefix = u''
- if self._transliterated_string:
- stripped_transliterated_string = itb_util.lstrip_token(self._transliterated_string)
- if stripped_transliterated_string:
- prefix_length = len(self._transliterated_string) - len(stripped_transliterated_string)
- if prefix_length:
- prefix = self._transliterated_string[0:prefix_length]
- try:
- self._candidates = self.db.select_words(stripped_transliterated_string, p_phrase=self._p_phrase, pp_phrase=self._pp_phrase)
- except:
- import traceback
- traceback.print_exc()
- if self._candidates:
- if prefix:
- self._candidates = map(lambda x: (prefix+x[0], x[1]), self._candidates)
- map(lambda x:
- self.append_candidate_to_lookup_table(phrase=x[0], user_freq=x[1]),
- self._candidates)
- return True
-
def arrow_down(self):
'''Process Arrow Down Key Event
Move Lookup Table cursor down'''
@@ -556,6 +489,43 @@ class tabengine (IBus.Engine):
def preedit_signal_cb(self,arg):
self._update_ui ()
+ self.update_candidates()
+
+ def update_candidates(self):
+ self._candidates = self._editor.yokan.get_suggestions();
+ print self._candidates
+ if self._candidates:
+ self.update_lookup_table(self._editor.get_lookup_table(), True)
+ map(lambda x:
+ self.append_candidate_to_lookup_table(phrase=x, user_freq=1),
+ self._candidates)
+ else:
+ self.hide_lookup_table()
+ return True
+
+ def append_candidate_to_lookup_table(self, phrase=u'', user_freq=0):
+ '''append candidate to lookup_table'''
+ if not phrase:
+ return
+ #phrase = unicodedata.normalize('NFC', phrase)
+ #transliterated_string = unicodedata.normalize('NFC', self._transliterated_string)
+ attrs = IBus.AttrList ()
+ attrs.append(IBus.attr_foreground_new(rgb(0x00,0x00,0x00), 0, len(phrase)))
+ if debug_level > 0:
+ phrase += u' ' + str(user_freq)
+ attrs.append(IBus.attr_foreground_new(
+ rgb(0x00,0xff,0x00), len(phrase) - len(str(user_freq)), len(phrase)))
+ text = IBus.Text.new_from_string(phrase)
+ i = 0
+ while attrs.get(i) != None:
+ attr = attrs.get(i)
+ text.append_attribute(attr.get_attr_type(),
+ attr.get_value(),
+ attr.get_start_index(),
+ attr.get_end_index())
+ i += 1
+ self._editor._lookup_table.append_candidate(text)
+ self._editor._lookup_table.set_cursor_visible(False)
def reset (self):
self._editor.clear_input()
@@ -628,6 +598,8 @@ class tabengine (IBus.Engine):
def _update_lookup_table (self):
'''Update Lookup Table in UI'''
+ self.update_lookup_table(self._editor.get_lookup_table(), True)
+ return
if self._editor.is_empty ():
if self._tab_enable:
# if everything has been cleared from the editor
@@ -654,7 +626,7 @@ class tabengine (IBus.Engine):
def _update_ui (self):
'''Update User Interface'''
- self._update_lookup_table ()
+ #self._update_lookup_table ()
self._update_preedit ()
self._update_aux ()
10 years, 10 months
[ibus-typing-booster] libyokan_port_20130711: Added signal handling for commit signal (dcc0c84)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
>---------------------------------------------------------------
commit dcc0c8429cc203f775babfdf1596cad41658ba50
Author: anish <apatil(a)redhat.com>
Date: Tue Jul 9 11:42:56 2013 +0530
Added signal handling for commit signal
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 9 +++++----
1 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index 61b82ae..e59c46a 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -546,11 +546,15 @@ class tabengine (IBus.Engine):
self._tab_enable = self.db.ime_properties.get('tab_enable').lower() == u'true'
self._commit_happened_after_focus_in = False
self._editor.yokan.connect("commit-signal",self.commit_signal_cb)
+ self._editor.yokan.connect("preedit-signal",self.preedit_signal_cb)
self.reset ()
def commit_signal_cb(self,arg):
commit_phrase = self._editor.yokan.get_commit()
+ super(tabengine, self).update_preedit_text(IBus.Text.new_from_string(u''), 0, False)
self.commit_string(commit_phrase)
+
+ def preedit_signal_cb(self,arg):
self._update_ui ()
def reset (self):
@@ -573,8 +577,6 @@ class tabengine (IBus.Engine):
# editor.get_caret() should also use NFC!
_str = unicodedata.normalize('NFC', self._editor.get_transliterated_string())
_str = self._editor.yokan.get_preedit()
- print "update preedit"
- print _str
if _str == u'' or _str == None:
super(tabengine, self).update_preedit_text(IBus.Text.new_from_string(u''), 0, False)
else:
@@ -657,7 +659,6 @@ class tabengine (IBus.Engine):
self._update_aux ()
def commit_string (self, commit_phrase, input_phrase=u''):
- print "commit_string"
if self._tab_enable:
# After each commit, disable a tab enabled lookup
# table again, i.e. one needs to press tab again
@@ -745,7 +746,7 @@ class tabengine (IBus.Engine):
result = self._editor.yokan.process_key_event(keyevent)
if result == False:
return result
- self._update_ui ()
+ #self._update_ui ()
#result = self._process_key_event (key)
return result
10 years, 10 months
[ibus-typing-booster] libyokan_port_20130711: Initial changes (db7f3ad)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
>---------------------------------------------------------------
commit db7f3ad7e803de9ce652891c98aa567b978219fe
Author: anish <apatil(a)redhat.com>
Date: Mon Jul 1 15:04:35 2013 +0530
Initial changes
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 37 +++++++++++++++++++++-----
1 files changed, 30 insertions(+), 7 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index da04927..7277893 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -29,6 +29,7 @@ import re
from gi.repository import IBus
from gi.repository import GLib
import itb_util
+from gi.repository import libyokan
debug_level = int(0)
@@ -104,7 +105,7 @@ class editor(object):
round=True)
self._lookup_table.clear()
self._lookup_table.set_cursor_visible(False)
-
+ self.yokan = libyokan.Yokan.new("/usr/share/libyokan-data/","en_US.db","en","")
self._m17ndb = 'm17n'
self.trans = None
@@ -544,8 +545,13 @@ class tabengine (IBus.Engine):
if self._tab_enable == None:
self._tab_enable = self.db.ime_properties.get('tab_enable').lower() == u'true'
self._commit_happened_after_focus_in = False
+ self._editor.yokan.connect("commit-signal",self.commit_signal_cb)
self.reset ()
+ def commit_signal_cb(self,arg):
+ commit_phrase = self._editor.yokan.get_commit()
+ self.commit_string(commit_phrase)
+
def reset (self):
self._editor.clear_input()
self._update_ui ()
@@ -565,7 +571,8 @@ class tabengine (IBus.Engine):
'''Update Preedit String in UI'''
# editor.get_caret() should also use NFC!
_str = unicodedata.normalize('NFC', self._editor.get_transliterated_string())
- if _str == u'':
+ _str = self._editor.yokan.get_preedit()
+ if _str == u'' or _str == None:
super(tabengine, self).update_preedit_text(IBus.Text.new_from_string(u''), 0, False)
else:
attrs = IBus.AttrList()
@@ -580,7 +587,7 @@ class tabengine (IBus.Engine):
attr.get_start_index(),
attr.get_end_index())
i += 1
- super(tabengine, self).update_preedit_text(text, self._editor.get_caret(), True)
+ super(tabengine, self).update_preedit_text(text,len(_str), True)
def _update_aux (self):
'''Update Aux String in UI'''
@@ -617,6 +624,11 @@ class tabengine (IBus.Engine):
def _update_lookup_table (self):
'''Update Lookup Table in UI'''
if self._editor.is_empty ():
+ if self._tab_enable:
+ # if everything has been cleared from the editor
+ # for example by backspace, disable a tab enabled
+ # lookup table again:
+ self.is_lookup_table_enabled_by_tab = False
self.hide_lookup_table()
return
# Also make sure to hide lookup table if there are
@@ -642,10 +654,16 @@ class tabengine (IBus.Engine):
self._update_aux ()
def commit_string (self, commit_phrase, input_phrase=u''):
+ if self._tab_enable:
+ # After each commit, disable a tab enabled lookup
+ # table again, i.e. one needs to press tab again
+ # while typing the next word to show the lookup table
+ # again:
+ self.is_lookup_table_enabled_by_tab = False
if not input_phrase:
input_phrase = self._editor.get_transliterated_string()
# commit always in NFC:
- commit_phrase = unicodedata.normalize('NFC', commit_phrase)
+ #commit_phrase = unicodedata.normalize('NFC', commit_phrase)
super(tabengine,self).commit_text(IBus.Text.new_from_string(commit_phrase))
self._editor.clear_input()
self._update_ui ()
@@ -716,9 +734,14 @@ class tabengine (IBus.Engine):
key = KeyEvent(keyval, state & IBus.ModifierType.RELEASE_MASK == 0, state)
# ignore NumLock mask
key.mask &= ~IBus.ModifierType.MOD2_MASK
-
- result = self._process_key_event (key)
- return result
+ if key.mask & IBus.ModifierType.RELEASE_MASK:
+ return True
+ state = state & (IBus.ModifierType.SHIFT_MASK |IBus.ModifierType.CONTROL_MASK | IBus.ModifierType.MOD1_MASK |IBus.ModifierType.MOD5_MASK | IBus.ModifierType.RELEASE_MASK);
+ keyevent = libyokan.KeyEvent.from_x_event(keyval,keycode,libyokan.ModifierType(state))
+ result = self._editor.yokan.process_key_event(keyevent)
+ self._update_ui ()
+ #result = self._process_key_event (key)
+ return True
def _process_key_event (self, key):
'''Internal method to process key event
10 years, 10 months
[ibus-typing-booster] libyokan_port_20130711: if you press space key with no preedit string in this case you should not call _update_ui method (ddc1a95)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
>---------------------------------------------------------------
commit ddc1a95398f131b6a6defa903eda21ffad109cdb
Author: anish <apatil(a)redhat.com>
Date: Wed Jul 3 18:12:23 2013 +0530
if you press space key with no preedit string in this case you should not call _update_ui method
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 7 ++++++-
1 files changed, 6 insertions(+), 1 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index acb8c3d..61b82ae 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -573,6 +573,8 @@ class tabengine (IBus.Engine):
# editor.get_caret() should also use NFC!
_str = unicodedata.normalize('NFC', self._editor.get_transliterated_string())
_str = self._editor.yokan.get_preedit()
+ print "update preedit"
+ print _str
if _str == u'' or _str == None:
super(tabengine, self).update_preedit_text(IBus.Text.new_from_string(u''), 0, False)
else:
@@ -655,6 +657,7 @@ class tabengine (IBus.Engine):
self._update_aux ()
def commit_string (self, commit_phrase, input_phrase=u''):
+ print "commit_string"
if self._tab_enable:
# After each commit, disable a tab enabled lookup
# table again, i.e. one needs to press tab again
@@ -667,7 +670,7 @@ class tabengine (IBus.Engine):
#commit_phrase = unicodedata.normalize('NFC', commit_phrase)
super(tabengine,self).commit_text(IBus.Text.new_from_string(commit_phrase))
self._editor.clear_input()
- self._update_ui ()
+ #self._update_ui ()
self._commit_happened_after_focus_in = True
if self.client_capabilities & IBus.Capabilite.SURROUNDING_TEXT:
# If a character ending a sentence is committed (possibly
@@ -740,6 +743,8 @@ class tabengine (IBus.Engine):
state = state & (IBus.ModifierType.SHIFT_MASK |IBus.ModifierType.CONTROL_MASK | IBus.ModifierType.MOD1_MASK |IBus.ModifierType.MOD5_MASK | IBus.ModifierType.RELEASE_MASK);
keyevent = libyokan.KeyEvent.from_x_event(keyval,keycode,libyokan.ModifierType(state))
result = self._editor.yokan.process_key_event(keyevent)
+ if result == False:
+ return result
self._update_ui ()
#result = self._process_key_event (key)
return result
10 years, 10 months
[ibus-typing-booster] libyokan_port_20130711: Fixed commit char issue (cc8762a)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : libyokan_port_20130711
>---------------------------------------------------------------
commit cc8762a407f2e2ca7c1fe0b9b191a6f3ff8bb145
Author: anish <apatil(a)redhat.com>
Date: Mon Jul 1 16:46:18 2013 +0530
Fixed commit char issue
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index 7277893..acb8c3d 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -551,6 +551,7 @@ class tabengine (IBus.Engine):
def commit_signal_cb(self,arg):
commit_phrase = self._editor.yokan.get_commit()
self.commit_string(commit_phrase)
+ self._update_ui ()
def reset (self):
self._editor.clear_input()
@@ -741,7 +742,7 @@ class tabengine (IBus.Engine):
result = self._editor.yokan.process_key_event(keyevent)
self._update_ui ()
#result = self._process_key_event (key)
- return True
+ return result
def _process_key_event (self, key):
'''Internal method to process key event
10 years, 10 months
[ibus-typing-booster] miketmp-debug: Add an option to try completion only when a minimum number of characters has been typed (b27c2f3)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : miketmp-debug
>---------------------------------------------------------------
commit b27c2f3c24dce197c48b204c1a2a0da0d38628bd
Author: Mike FABIAN <mfabian(a)redhat.com>
Date: Mon Jul 8 18:17:30 2013 +0200
Add an option to try completion only when a minimum number of characters has been typed
Some users reported that they find it distracting when the lookup
table pops up all the time and requested an option to try completion
only if a certain number of character has been typed already. I.e. use
completion only for longer words. Short strings are still in preëdit
until committed and added to the database, but no lookup table pops up
anymore when the number of characters typed is still below the limit.
For very fast typists, this may be better then popping up the lookup
table after the first character typed.
Of course, to save as many keystrokes as possible, completion should
be tried as early as possible. Therefore, the default is 1,
i.e. completion is attempted after the first character typed.
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 16 ++++++-
ibus-typing-booster/setup/main.py | 12 +++++
ibus-typing-booster/setup/setup.glade | 60 ++++++++++++++++++++++---
3 files changed, 79 insertions(+), 9 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index 5f82747..43e71f9 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -89,6 +89,15 @@ class editor(object):
self._config = config
self._name = self.db.ime_properties.get('name')
self._config_section = "engine/typing-booster/%s" % self._name
+ self._min_char_complete = variant_to_value(self._config.get_value(
+ self._config_section,
+ 'mincharcomplete'))
+ if self._min_char_complete == None:
+ self._min_char_complete = 1 # default
+ if self._min_char_complete < 1:
+ self._min_char_complete = 1 # minimum
+ if self._min_char_complete > 9:
+ self._min_char_complete = 9 # maximum
self._typed_string = u''
self._typed_string_cursor = 0
self._typed_string_when_update_candidates_was_last_called = u''
@@ -337,7 +346,7 @@ class editor(object):
prefix = u''
if self._transliterated_string:
stripped_transliterated_string = itb_util.lstrip_token(self._transliterated_string)
- if stripped_transliterated_string:
+ if len(stripped_transliterated_string) >= self._min_char_complete:
prefix_length = len(self._transliterated_string) - len(stripped_transliterated_string)
if prefix_length:
prefix = self._transliterated_string[0:prefix_length]
@@ -1023,6 +1032,11 @@ class tabengine (IBus.Engine):
round=True)
self.reset()
return
+ if name == "mincharcomplete":
+ if value >= 1 and value <= 9:
+ self._editor._min_char_complete = value
+ self.reset()
+ return
if name == "shownumberofcandidates":
if value == True:
self._show_number_of_candidates = True
diff --git a/ibus-typing-booster/setup/main.py b/ibus-typing-booster/setup/main.py
index 32cc81f..8dd905d 100644
--- a/ibus-typing-booster/setup/main.py
+++ b/ibus-typing-booster/setup/main.py
@@ -152,6 +152,14 @@ class SetupUI:
self.page_size_adjustment.set_value(6)
self.page_size_adjustment.connect('value-changed', event_handler.onPageSizeAdjustmentValueChanged)
+ self.min_char_complete_adjustment = self.builder.get_object("min_char_complete_adjustment")
+ self.min_char_complete = self.variant_to_value(self.config.get_value(self.config_section, 'mincharcomplete'))
+ if self.min_char_complete:
+ self.min_char_complete_adjustment.set_value(int(self.min_char_complete))
+ else:
+ self.min_char_complete_adjustment.set_value(1)
+ self.min_char_complete_adjustment.connect('value-changed', event_handler.onMinCharCompleteAdjustmentValueChanged)
+
self.other_ime = self.tabsqlitedb.ime_properties.get('other_ime').lower() == u'true'
ime_combobox = self.builder.get_object("input_method_combobox")
ime_label = self.builder.get_object("input_method_label")
@@ -311,6 +319,10 @@ class EventHandler:
self.page_size = SetupUi.page_size_adjustment.get_value()
SetupUi.config.set_value(SetupUi.config_section,'pagesize',GLib.Variant.new_int32(self.page_size))
+ def onMinCharCompleteAdjustmentValueChanged(self,widget):
+ self.min_char_complete = SetupUi.min_char_complete_adjustment.get_value()
+ SetupUi.config.set_value(SetupUi.config_section,'mincharcomplete',GLib.Variant.new_int32(self.min_char_complete))
+
def onImeComboboxChanged(self,widget):
tree_iter = widget.get_active_iter()
if tree_iter != None:
diff --git a/ibus-typing-booster/setup/setup.glade b/ibus-typing-booster/setup/setup.glade
index c70cc29..f823489 100644
--- a/ibus-typing-booster/setup/setup.glade
+++ b/ibus-typing-booster/setup/setup.glade
@@ -1,10 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
- <object class="GtkAdjustment" id="page_size_adjustment">
+ <object class="GtkAdjustment" id="min_char_complete_adjustment">
<property name="lower">1</property>
<property name="upper">9</property>
- <property name="value">6</property>
<property name="step_increment">1</property>
</object>
<object class="GtkDialog" id="main_dialog">
@@ -69,7 +68,7 @@
<object class="GtkTable" id="table4">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="n_rows">4</property>
+ <property name="n_rows">5</property>
<property name="n_columns">2</property>
<property name="column_spacing">8</property>
<property name="row_spacing">4</property>
@@ -113,7 +112,7 @@
<property name="can_focus">True</property>
<property name="invisible_char">●</property>
<property name="adjustment">page_size_adjustment</property>
- <property name="climb_rate">0.97999999999999998</property>
+ <property name="climb_rate">1</property>
</object>
<packing>
<property name="expand">False</property>
@@ -138,8 +137,8 @@
<property name="label" translatable="yes">Input Method:</property>
</object>
<packing>
- <property name="top_attach">3</property>
- <property name="bottom_attach">4</property>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
<property name="x_options">GTK_FILL</property>
<property name="y_options"/>
</packing>
@@ -152,8 +151,8 @@
<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>
+ <property name="top_attach">4</property>
+ <property name="bottom_attach">5</property>
<property name="y_options"/>
</packing>
</child>
@@ -175,6 +174,46 @@
<property name="y_options">GTK_FILL</property>
</packing>
</child>
+ <child>
+ <object class="GtkBox" id="min_chars_completion_box">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="spacing">8</property>
+ <child>
+ <object class="GtkLabel" id="min_chars_completion_label">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="label" translatable="yes">Minimum number of chars for completion:</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkSpinButton" id="min_chars_completion">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="invisible_char">●</property>
+ <property name="adjustment">min_char_complete_adjustment</property>
+ <property name="climb_rate">1</property>
+ </object>
+ <packing>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="position">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="right_attach">2</property>
+ <property name="top_attach">3</property>
+ <property name="bottom_attach">4</property>
+ <property name="x_options">GTK_FILL</property>
+ <property name="y_options">GTK_FILL</property>
+ </packing>
+ </child>
</object>
</child>
</object>
@@ -399,4 +438,9 @@
<action-widget response="0">close_button</action-widget>
</action-widgets>
</object>
+ <object class="GtkAdjustment" id="page_size_adjustment">
+ <property name="lower">1</property>
+ <property name="upper">9</property>
+ <property name="step_increment">1</property>
+ </object>
</interface>
10 years, 10 months
[ibus-typing-booster] miketmp-debug: WIP timestamps (d7a58a4)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : miketmp-debug
>---------------------------------------------------------------
commit d7a58a4a715ac911f5b065aba66b96577259a85b
Author: Mike FABIAN <mfabian(a)redhat.com>
Date: Thu Jun 27 17:42:43 2013 +0200
WIP timestamps
>---------------------------------------------------------------
ibus-typing-booster/engine/tabsqlitedb.py | 50 +++++++++++++++++------------
1 files changed, 29 insertions(+), 21 deletions(-)
diff --git a/ibus-typing-booster/engine/tabsqlitedb.py b/ibus-typing-booster/engine/tabsqlitedb.py
index 39d2acd..306fb54 100755
--- a/ibus-typing-booster/engine/tabsqlitedb.py
+++ b/ibus-typing-booster/engine/tabsqlitedb.py
@@ -29,7 +29,7 @@ import re
import itb_util
import hunspell_suggest
-user_database_version = '0.64'
+user_database_version = '0.65'
class ImeProperties:
def __init__(self, configfile_path=None):
@@ -61,7 +61,7 @@ class tabsqlitedb:
The phrases table in the database has columns with the names:
- “id”, “input_phrase”, “phrase”, “p_phrase”, “pp_phrase”, “user_freq”
+ “id”, “input_phrase”, “phrase”, “p_phrase”, “pp_phrase”, “user_freq”, “timestamp”
There are 2 databases, sysdb, userdb.
@@ -81,7 +81,7 @@ class tabsqlitedb:
def __init__(self, name = 'table.db', user_db = None, filename = None ):
# use filename when you are creating db from source
# use name when you are using db
- self._phrase_table_column_names = ['id', 'input_phrase', 'phrase', 'p_phrase', 'pp_phrase', 'user_freq']
+ self._phrase_table_column_names = ['id', 'input_phrase', 'phrase', 'p_phrase', 'pp_phrase', 'user_freq', 'timestamp']
self.old_phrases=[]
@@ -192,11 +192,11 @@ class tabsqlitedb:
if self.old_phrases:
sqlargs = []
map(lambda x: sqlargs.append(
- {'input_phrase': x[0], 'phrase': x[0], 'p_phrase': u'', 'pp_phrase': u'', 'user_freq': x[1]}),
+ {'input_phrase': x[0], 'phrase': x[0], 'p_phrase': u'', 'pp_phrase': u'', 'user_freq': x[1], 'timestamp': time.time()}),
self.old_phrases)
sqlstr = '''
- INSERT INTO user_db.phrases (input_phrase, phrase, p_phrase, pp_phrase, user_freq)
- VALUES (:input_phrase, :phrase, :p_phrase, :pp_phrase, :user_freq)
+ INSERT INTO user_db.phrases (input_phrase, phrase, p_phrase, pp_phrase, user_freq, timestamp)
+ VALUES (:input_phrase, :phrase, :p_phrase, :pp_phrase, :user_freq, :timestamp)
;'''
try:
self.db.executemany(sqlstr, sqlargs)
@@ -240,16 +240,21 @@ class tabsqlitedb:
self._normalization_form_internal, pp_phrase)
sqlstr = '''
UPDATE %(database)s.phrases
- SET user_freq = :user_freq
+ SET user_freq = :user_freq, timestamp = :timestamp
WHERE input_phrase = :input_phrase
AND phrase = :phrase AND p_phrase = :p_phrase AND pp_phrase = :pp_phrase
;''' %{'database':database}
sqlargs = {'user_freq': user_freq,
'input_phrase': input_phrase,
- 'phrase': phrase, 'p_phrase': p_phrase, 'pp_phrase': pp_phrase}
- self.db.execute(sqlstr, sqlargs)
- if commit:
- self.db.commit()
+ 'phrase': phrase, 'p_phrase': p_phrase, 'pp_phrase': pp_phrase,
+ 'timestamp': time.time()}
+ try:
+ self.db.execute(sqlstr, sqlargs)
+ if commit:
+ self.db.commit()
+ except:
+ import traceback
+ traceback.print_exc()
def sync_usrdb (self):
'''
@@ -263,7 +268,7 @@ class tabsqlitedb:
sqlstr = '''CREATE TABLE IF NOT EXISTS %s.phrases
(id INTEGER PRIMARY KEY,
input_phrase TEXT, phrase TEXT, p_phrase TEXT, pp_phrase TEXT,
- user_freq INTEGER);''' % database
+ user_freq INTEGER, timestamp REAL);''' % database
self.db.execute(sqlstr)
self.db.commit()
@@ -295,12 +300,12 @@ class tabsqlitedb:
insert_sqlstr = '''
INSERT INTO %(database)s.phrases
- (input_phrase, phrase, p_phrase, pp_phrase, user_freq)
- VALUES (:input_phrase, :phrase, :p_phrase, :pp_phrase, :user_freq)
+ (input_phrase, phrase, p_phrase, pp_phrase, user_freq, timestamp)
+ VALUES (:input_phrase, :phrase, :p_phrase, :pp_phrase, :user_freq, :timestamp)
;''' %{'database': database}
insert_sqlargs = {'input_phrase': input_phrase,
'phrase': phrase, 'p_phrase': p_phrase, 'pp_phrase': pp_phrase,
- 'user_freq': user_freq}
+ 'user_freq': user_freq, 'timestamp': time.time()}
try:
self.db.execute (insert_sqlstr, insert_sqlargs)
if commit:
@@ -541,7 +546,7 @@ class tabsqlitedb:
Determines the number of columns by parsing this:
sqlite> select sql from sqlite_master where name='phrases';
-CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_phrase TEXT, pp_phrase TEXT, user_freq INTEGER)
+CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_phrase TEXT, pp_phrase TEXT, user_freq INTEGER, timestamp REAL)
sqlite>
This result could be on a single line, as above, or on multiple
@@ -673,7 +678,7 @@ CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_
def read_training_data_from_file(self, filename):
if not os.path.isfile(filename):
return False
- rows = self.db.execute('SELECT input_phrase, phrase, p_phrase, pp_phrase, user_freq FROM phrases;').fetchall()
+ rows = self.db.execute('SELECT input_phrase, phrase, p_phrase, pp_phrase, user_freq, timestamp FROM phrases;').fetchall()
p_token = u''
pp_token = u''
database_dict = {}
@@ -683,7 +688,8 @@ CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_
'phrase': x[1],
'p_phrase': x[2],
'pp_phrase': x[3],
- 'user_freq': x[4]}
+ 'user_freq': x[4],
+ 'timestamp': x[5]}
)]), rows)
with codecs.open(filename, encoding='UTF-8') as file:
lines = map(lambda x: unicodedata.normalize(self._normalization_form_internal, x), file.readlines())
@@ -692,19 +698,21 @@ CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_
key = (token, token, p_token, pp_token)
if key in database_dict:
database_dict[key]['user_freq'] += 1
+ database_dict[key]['timestamp'] = time.time()
else:
database_dict[key] = {'input_phrase': token,
'phrase': token,
'p_phrase': p_token,
'pp_phrase': pp_token,
- 'user_freq': 1}
+ 'user_freq': 1,
+ 'timestamp': time.time()}
pp_token = p_token
p_token = token
sqlargs = []
map(lambda x: sqlargs.append(database_dict[x]), database_dict.keys())
sqlstr = '''
- INSERT INTO user_db.phrases (input_phrase, phrase, p_phrase, pp_phrase, user_freq)
- VALUES (:input_phrase, :phrase, :p_phrase, :pp_phrase, :user_freq)
+ INSERT INTO user_db.phrases (input_phrase, phrase, p_phrase, pp_phrase, user_freq, timestamp)
+ VALUES (:input_phrase, :phrase, :p_phrase, :pp_phrase, :user_freq, :timestamp)
;'''
try:
self.db.execute('DELETE FROM phrases;')
10 years, 10 months
[ibus-typing-booster] miketmp-debug: add sys.stderr.write("mike ..." debug messages) (c9e8a1e)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : miketmp-debug
>---------------------------------------------------------------
commit c9e8a1ed197829cfe19222f05a6c7c6d156f803d
Author: Mike FABIAN <mfabian(a)redhat.com>
Date: Wed Jun 12 15:55:07 2013 +0200
add sys.stderr.write("mike ..." debug messages)
>---------------------------------------------------------------
ibus-typing-booster/engine/factory.py | 1 +
ibus-typing-booster/engine/hunspell_suggest.py | 3 +++
ibus-typing-booster/engine/hunspell_table.py | 19 +++++++++++++++++++
ibus-typing-booster/engine/tabsqlitedb.py | 19 +++++++++++++++++++
4 files changed, 42 insertions(+), 0 deletions(-)
diff --git a/ibus-typing-booster/engine/factory.py b/ibus-typing-booster/engine/factory.py
index 8307e07..138a447 100755
--- a/ibus-typing-booster/engine/factory.py
+++ b/ibus-typing-booster/engine/factory.py
@@ -22,6 +22,7 @@ from gi.repository import IBus
import hunspell_table
import tabsqlitedb
import os
+import sys
from re import compile as re_compile
path_patt = re_compile(r'[^a-zA-Z0-9_/]')
diff --git a/ibus-typing-booster/engine/hunspell_suggest.py b/ibus-typing-booster/engine/hunspell_suggest.py
index 9e9e1ed..33dd4a4 100755
--- a/ibus-typing-booster/engine/hunspell_suggest.py
+++ b/ibus-typing-booster/engine/hunspell_suggest.py
@@ -103,6 +103,7 @@ class Hunspell:
self.pyhunspell_object = None
def words_start(self,word):
+ sys.stderr.write("mike in words_start word=%s\n" %word.encode('UTF-8'))
if type(word) != type(u''):
word = word.decode('utf8')
# http://pwet.fr/man/linux/fichiers_speciaux/hunspell says:
@@ -146,6 +147,7 @@ class Hunspell:
start_words.append(suggestion)
else:
start_words = [u'☹ %(loc)s%(dict_name)s not found.' %{'loc': self.loc, 'dict_name': self.dict_name}, u'☹ please install hunspell dictionary!']
+# sys.stderr.write("mike words=%(w)s\n" %{'w': list(set(start_words[0:max_words]))})
return list(set(start_words[0:max_words]))
def suggest(self, input_phrase):
@@ -158,6 +160,7 @@ class Hunspell:
# to match words longer than that just wastes time.
if len(input_phrase) > 40:
return []
+# sys.stderr.write("mike in suggest word=%(ip)s\n" %{'ip': input_phrase.encode('UTF-8')})
return self.words_start(input_phrase)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index 43e71f9..3eea0af 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -22,6 +22,7 @@ __all__ = (
)
import os
+import sys
import string
import unicodedata
import curses.ascii
@@ -85,6 +86,7 @@ class editor(object):
'''Hold user inputs chars and preedit string'''
def __init__ (self, config, database):
+ sys.stderr.write("mike editor __init__\n")
self.db = database
self._config = config
self._name = self.db.ime_properties.get('name')
@@ -151,6 +153,7 @@ class editor(object):
self.trans_m17n_mode = True
try:
#self.trans = Translit.Transliterator.get(self._m17ndb, self._current_ime)
+ sys.stderr.write("mike calling Transliterator.get(%(m17n)s, %(cur)s)\n" %{'m17n': self._m17ndb, 'cur': self._current_ime})
self.trans = Transliterator.get(self._m17ndb, self._current_ime)
except:
import traceback
@@ -175,12 +178,19 @@ class editor(object):
self._typed_string)[0].decode('UTF-8')
else:
self._transliterated_string = self._typed_string
+ sys.stderr.write("mike in update_transliterated_string() self._typed_string=%s\n" %self._typed_string.encode('UTF-8'))
+ sys.stderr.write("mike in update_transliterated_string() repr(self._typed_string)=%s\n" %repr(self._typed_string))
+ sys.stderr.write("mike in update_transliterated_string() self._transliterated_string=%s\n" %self._transliterated_string.encode('UTF-8'))
+ sys.stderr.write("mike in update_transliterated_string() repr(self._transliterated_string)=%s\n" %repr(self._transliterated_string))
def get_transliterated_string(self):
return self._transliterated_string
def insert_string_at_cursor(self, string_to_insert):
'''Insert typed string at cursor position'''
+ sys.stderr.write("mike in insert_string_at_cursor() string_to_insert=%s\n" %string_to_insert.encode('UTF-8'))
+ sys.stderr.write("mike in insert_string_at_cursor() self._typed_string=%s\n" %self._typed_string.encode('UTF-8'))
+ sys.stderr.write("mike in insert_string_at_cursor() self._typed_string_cursor=%s\n" %self._typed_string_cursor)
self._typed_string = self._typed_string[:self._typed_string_cursor] \
+string_to_insert \
+self._typed_string[self._typed_string_cursor:]
@@ -334,6 +344,7 @@ class editor(object):
def update_candidates (self):
'''Update lookuptable'''
+ sys.stderr.write("mike in update_candidates() self._typed_string=%s\n" %self._typed_string.encode('UTF-8'))
if self._typed_string == self._typed_string_when_update_candidates_was_last_called:
# The input did not change since we came here last, do nothing and leave
# candidates and lookup table unchanged:
@@ -503,6 +514,7 @@ class tabengine (IBus.Engine):
'''The IM Engine for Tables'''
def __init__ (self, bus, obj_path, db ):
+ sys.stderr.write("mike in tabengine __init__() obj_path=%s\n" %obj_path)
super(tabengine,self).__init__ (connection=bus.get_connection(),object_path=obj_path)
global debug_level
try:
@@ -567,6 +579,7 @@ class tabengine (IBus.Engine):
def _change_mode (self):
'''Shift input mode, TAB -> EN -> TAB
'''
+ sys.stderr.write("mike in hunspell_table.py _change_mode()\n")
self.reset ()
self._update_ui ()
@@ -722,7 +735,10 @@ class tabengine (IBus.Engine):
Key Events include Key Press and Key Release,
modifier means Key Pressed
'''
+ sys.stderr.write("mike in process_key_event keyval=%(kv)s keycode=%(kc)s state=%(st)s\n" %{'kv': keyval, 'kc': keycode, 'st': state})
key = KeyEvent(keyval, state & IBus.ModifierType.RELEASE_MASK == 0, state)
+ sys.stderr.write("mike after KeyEvent() in process_key_event key.code=%(kc)s\n" %{'kc': key.code})
+ sys.stderr.write("mike after KeyEvent() in process_key_event key.code=%(kc)s IBus.keyval_to_unicode(key.code)=%(uc)s\n" %{'kc': key.code, 'uc': IBus.keyval_to_unicode(key.code)})
# ignore NumLock mask
key.mask &= ~IBus.ModifierType.MOD2_MASK
@@ -743,6 +759,9 @@ class tabengine (IBus.Engine):
return True
if self._editor.is_empty ():
+ sys.stderr.write("mike self._editor.is_empty ():\n")
+ sys.stderr.write("mike key.code=%(key.code)s IBus.keyval_to_unicode(key.code)=%(keychar)s\n" %{'key.code': key.code, 'keychar': IBus.keyval_to_unicode(key.code)})
+ sys.stderr.write("mike IBus.keyval_name(key.code)=%s\n" %IBus.keyval_name(key.code))
# This is the first character typed since the last commit
# there is nothing in the preëdit yet.
if key.code < 32:
diff --git a/ibus-typing-booster/engine/tabsqlitedb.py b/ibus-typing-booster/engine/tabsqlitedb.py
index 306fb54..6cd7f68 100755
--- a/ibus-typing-booster/engine/tabsqlitedb.py
+++ b/ibus-typing-booster/engine/tabsqlitedb.py
@@ -248,6 +248,8 @@ class tabsqlitedb:
'input_phrase': input_phrase,
'phrase': phrase, 'p_phrase': p_phrase, 'pp_phrase': pp_phrase,
'timestamp': time.time()}
+ sys.stderr.write("mike update_phrase() sqlstr=%s\n" %sqlstr)
+ sys.stderr.write("mike update_phrase() sqlargs=%s\n" %sqlargs)
try:
self.db.execute(sqlstr, sqlargs)
if commit:
@@ -260,8 +262,10 @@ class tabsqlitedb:
'''
Trigger a checkpoint operation.
'''
+ sys.stderr.write("mike sync_userdb() commit and execute checkpoint ...\n")
self.db.commit()
self.db.execute('PRAGMA wal_checkpoint;')
+ sys.stderr.write("mike sync_userdb() commit and execute checkpoint done.\n")
def create_tables (self, database):
'''Create table for the phrases.'''
@@ -276,6 +280,7 @@ class tabsqlitedb:
'''
Add phrase to database
'''
+ sys.stderr.write("mike in add_phrase() input_phrase=%(ip)s phrase=%(p)s user_freq=%(uf)s database=%(db)s\n" %{'ip': input_phrase.encode('UTF-8'), 'p': phrase.encode('UTF-8'), 'uf': user_freq, 'db': database})
if not input_phrase or not phrase:
return
input_phrase = unicodedata.normalize(
@@ -306,6 +311,8 @@ class tabsqlitedb:
insert_sqlargs = {'input_phrase': input_phrase,
'phrase': phrase, 'p_phrase': p_phrase, 'pp_phrase': pp_phrase,
'user_freq': user_freq, 'timestamp': time.time()}
+ sys.stderr.write("mike add_phrase() insert_sqlstr=%s\n" %insert_sqlstr)
+ sys.stderr.write("mike add_phrase() insert_sqlargs=%s\n" %insert_sqlargs)
try:
self.db.execute (insert_sqlstr, insert_sqlargs)
if commit:
@@ -378,8 +385,10 @@ class tabsqlitedb:
self._normalization_form_internal, p_phrase)
pp_phrase = unicodedata.normalize(
self._normalization_form_internal, pp_phrase)
+ sys.stderr.write("mike in select_words() input_phrase=%(ip)s p_phrase=%(p)s pp_phrase=%(pp)s\n" %{'ip': input_phrase.encode('UTF-8'), 'p': p_phrase.encode('UTF-8'), 'pp': pp_phrase.encode('UTF-8')})
phrase_frequencies = {}
map(lambda x: phrase_frequencies.update([(x, 0)]), self.hunspell_obj.suggest(input_phrase))
+ sys.stderr.write("mike in select_words() hunspell: best_candidates=%s\n" %self.best_candidates(phrase_frequencies))
# Now phrase_frequencies might contain something like this:
#
# {u'code': 0, u'communicability': 0, u'cold': 0, u'colour': 0}
@@ -445,6 +454,7 @@ class tabsqlitedb:
# Updating the phrase_frequency dictionary with the normalized results gives:
# {u'conspiracy': 6/11, u'code': 0, u'communicability': 0, u'cold': 1/11, u'colour': 4/11}
map(lambda x: phrase_frequencies.update([(x[0], x[1]/float(count))]), results_uni)
+ sys.stderr.write("mike in select_words() Unigram best_candidates=%s\n" %self.best_candidates(phrase_frequencies))
if not p_phrase:
# If no context for bigram matching is available, return what we have so far:
return self.best_candidates(phrase_frequencies)
@@ -468,6 +478,7 @@ class tabsqlitedb:
# combination of the unigram and the bigram results, giving
# both the weight of 0.5:
map(lambda x: phrase_frequencies.update([(x[0], 0.5*x[1]/float(count_p_phrase)+0.5*phrase_frequencies[x[0]])]), results_bi)
+ sys.stderr.write("mike in select_words() Bigram best_candidates=%s\n" %self.best_candidates(phrase_frequencies))
if not pp_phrase:
# If no context for trigram matching is available, return what we have so far:
return self.best_candidates(phrase_frequencies)
@@ -493,6 +504,7 @@ class tabsqlitedb:
# unigram + 0.25 * bigram + 0.5 * trigram, i.e. the trigrams
# get higher weight):
map(lambda x: phrase_frequencies.update([(x[0], 0.5*x[1]/float(count_pp_phrase_p_phrase)+0.5*phrase_frequencies[x[0]])]), results_tri)
+ sys.stderr.write("mike in select_words() Trigram best_candidates=%s\n" %self.best_candidates(phrase_frequencies))
return self.best_candidates(phrase_frequencies)
def generate_userdb_desc (self):
@@ -598,6 +610,8 @@ CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_
input_phrase = unicodedata.normalize(
self._normalization_form_internal, input_phrase)
+ sys.stderr.write("mike check_phrase() phrase=%(p)s, input_phrase=%(t)s, database=%(d)s\n" %{'p': phrase.encode('UTF-8'), 't': input_phrase.encode('UTF-8'), 'd': database})
+
# There should never be more than 1 database row for the same
# input_phrase *and* phrase. So the following query on
# the database should match at most one database
@@ -614,7 +628,10 @@ CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_
;'''
sqlargs = {'input_phrase': input_phrase,
'phrase': phrase, 'p_phrase': p_phrase, 'pp_phrase': pp_phrase}
+ sys.stderr.write("mike sqlstr=%s\n" %sqlstr)
+ sys.stderr.write("mike sqlargs=%s\n" %sqlargs)
result = self.db.execute(sqlstr, sqlargs).fetchall()
+ sys.stderr.write("mike result=%s\n" %result)
if len(result) > 0:
# A match was found in user_db, increase user frequency by 1
self.update_phrase(input_phrase = input_phrase,
@@ -636,6 +653,8 @@ CREATE TABLE phrases (id INTEGER PRIMARY KEY, input_phrase TEXT, phrase TEXT, p_
Or, if “input_phrase” is “None”, remove all rows matching “phrase”
no matter for what input phrase from the database.
'''
+ sys.stderr.write("mike remove_phrase() phrase=%(p)s\n" %{'p': phrase.encode('UTF-8')})
+ sys.stderr.write("mike remove_phrase() database=%s\n" %database)
if not phrase:
return
phrase = unicodedata.normalize(
10 years, 10 months
[ibus-typing-booster] miketmp-debug: Commit immediately when certain punctuation characters are typed and transliteration is not used (f117eb4)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : miketmp-debug
>---------------------------------------------------------------
commit f117eb4469ab62ce142c00e3b58e9f335c0833d2
Author: Mike FABIAN <mfabian(a)redhat.com>
Date: Sat Jul 6 23:41:24 2013 +0200
Commit immediately when certain punctuation characters are typed and transliteration is not used
- Improve committing punctuation immediately when the preëdit is empty
and no transliteration is used: don’t just check ascii punctuation
but check for Unicode categories.
- commit punctuation immediately as well when the preëdit is not empty
anymore and no transliteration is used.
rhbz#981179 - RFE: punctuation marks should commit the preedit buffer
See: https://bugzilla.redhat.com/show_bug.cgi?id=981179
>---------------------------------------------------------------
ibus-typing-booster/engine/hunspell_table.py | 47 +++++++++++++++----------
ibus-typing-booster/engine/itb_util.py | 16 +++++++++
2 files changed, 44 insertions(+), 19 deletions(-)
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index da04927..5f82747 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -746,28 +746,32 @@ class tabengine (IBus.Engine):
# if the first character is a space, just pass it through
# it makes not sense trying to complete:
return False
- if key.code >= 32 and key.code <= 127 and (not (key.mask & (IBus.ModifierType.MOD1_MASK | IBus.ModifierType.CONTROL_MASK))):
- # If the first character typed is punctuation or a digit,
- # we might want to avoid completion and commit something
- # immediately:
- if curses.ascii.ispunct(key.code):
+ if key.code >= 32 and (not (key.mask & (IBus.ModifierType.MOD1_MASK | IBus.ModifierType.CONTROL_MASK))):
+ typed_character = IBus.keyval_to_unicode(key.code).decode('UTF-8')
+ # If the first character typed is a character which is
+ # very unlikely to be part of a word
+ # (e.g. punctuation, a symbol, ..), we might want to
+ # avoid completion and commit something immediately:
+ if typed_character and unicodedata.category(typed_character) in itb_util.categories_to_trigger_immediate_commit:
if not self._editor.trans_m17n_mode:
- # If the first character is punctuation and no
- # transliteration is used, don’t just pass it through.
- # Commit it so it gets added to the remembered context:
- punctuation = IBus.keyval_to_unicode(key.code).decode('UTF-8')
- self.commit_string(punctuation, input_phrase = punctuation)
+ # Do not just pass the character through,
+ # commit it properly. For example if it is a
+ # “.” we might want to remove whitespace
+ # between the “.” and the previous word and this is
+ # done in commit_string().
+ self.commit_string(typed_character, input_phrase = typed_character)
return True
# If transliteration is used, we may need to
- # handle a punctuation character. For example,
- # “.c” is transliterated to “ċ” in the
- # “t-latn-pre” transliteration method, therefore
- # we cannot just pass it through. Just add it to
- # the input so far and see what comes next:
- self._editor.insert_string_at_cursor(IBus.keyval_to_unicode(key.code).decode('UTF-8'))
+ # handle a punctuation or symbol character. For
+ # example, “.c” is transliterated to “ċ” in
+ # the “t-latn-pre” transliteration method,
+ # therefore we cannot just pass it through. Just
+ # add it to the input so far and see what comes
+ # next:
+ self._editor.insert_string_at_cursor(typed_character)
self._update_ui()
return True
- if curses.ascii.isdigit(key.code):
+ if typed_character and unicodedata.digit(typed_character, -1) != -1:
if not self._editor.trans_m17n_mode:
# If a digit has been typed and no transliteration
# is used, we can pass it through
@@ -778,7 +782,7 @@ class tabengine (IBus.Engine):
# want “3” to be converted to “३”. So we try
# to transliterate and commit the result:
transliterated_digit = self._editor.trans.transliterate(
- IBus.keyval_to_unicode(key.code))[0].decode('utf8')
+ typed_character)[0].decode('utf8')
self.commit_string(transliterated_digit, input_phrase=transliterated_digit)
return True
@@ -944,7 +948,12 @@ class tabengine (IBus.Engine):
# first key typed, we will try to complete something now
# get the context if possible
self.get_context()
- self._editor.insert_string_at_cursor(IBus.keyval_to_unicode(key.code).decode('UTF-8'))
+ typed_character = IBus.keyval_to_unicode(key.code).decode('UTF-8')
+ self._editor.insert_string_at_cursor(typed_character)
+ if typed_character and unicodedata.category(typed_character) in itb_util.categories_to_trigger_immediate_commit:
+ input_phrase = self._editor.get_transliterated_string()
+ if input_phrase and input_phrase[-1] == typed_character and not self._editor.trans_m17n_mode:
+ self.commit_string(input_phrase + u' ', input_phrase = input_phrase)
self._update_ui()
return True
diff --git a/ibus-typing-booster/engine/itb_util.py b/ibus-typing-booster/engine/itb_util.py
index 9ea842a..d017fd3 100755
--- a/ibus-typing-booster/engine/itb_util.py
+++ b/ibus-typing-booster/engine/itb_util.py
@@ -19,6 +19,22 @@
import re
import unicodedata
+# If a character of one of these categories is typed and no
+# transliteration is used, the preëdit can be committed immediately.
+# However, if transliteration is used, we may need to handle a
+# punctuation or symbol character. For example, “.c” is
+# transliterated to “ċ” in the “t-latn-pre” transliteration
+# method, therefore we cannot just pass it through, we have to add
+# it to the input and see what comes next.
+#
+# This list is very similar to the list of categories to strip from
+# tokens. But I removed the 'Pd' (Punctuation, Dash) category because
+# of words like “up-to-date”. Triggering a commit at the first “-”
+# prevents learning such words from user input. I.e. the list of
+# categories to trigger immediate commit should contain only categories
+# which are very unlikely to appear as parts of words.
+categories_to_trigger_immediate_commit = ['Po', 'Pi', 'Pf', 'Ps', 'Pe', 'Pc', 'Sm', 'Sc', 'Cf']
+
categories_to_strip_from_tokens = ['Po', 'Pi', 'Pf', 'Ps', 'Pe', 'Pc', 'Pd', 'Sm', 'Sc', 'Cf']
def lstrip_token(token):
10 years, 10 months