[ibus-typing-booster] miketmp-debug: add sys.stderr.write("mike ..." debug messages) (e9217fe)
by mfabian@fedoraproject.org
Repository : http://git.fedorahosted.org/git/?p=ibus-typing-booster.git
On branch : miketmp-debug
>---------------------------------------------------------------
commit e9217feda74c4f95cb6f79c3a2a45bc2528ec8e9
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 | 2 ++
ibus-typing-booster/engine/hunspell_table.py | 18 ++++++++++++++++++
ibus-typing-booster/engine/tabsqlitedb.py | 19 +++++++++++++++++++
4 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/ibus-typing-booster/engine/factory.py b/ibus-typing-booster/engine/factory.py
index 84e64d6..3b61ebf 100755
--- a/ibus-typing-booster/engine/factory.py
+++ b/ibus-typing-booster/engine/factory.py
@@ -23,6 +23,7 @@ import hunspell_table
import tabsqlitedb
import os
import re
+import sys
from gettext import dgettext
_ = lambda a : dgettext ("ibus-typing-booster", a)
diff --git a/ibus-typing-booster/engine/hunspell_suggest.py b/ibus-typing-booster/engine/hunspell_suggest.py
index d04895d..9ddf9b0 100755
--- a/ibus-typing-booster/engine/hunspell_suggest.py
+++ b/ibus-typing-booster/engine/hunspell_suggest.py
@@ -110,6 +110,7 @@ class Hunspell:
def load_dictionaries(self):
self.dictionaries = []
+ print("mike dictionary_names=%s\n" %self.dictionary_names)
for dictionary_name in self.dictionary_names:
self.dictionaries.append(Dictionary(name=dictionary_name))
@@ -125,6 +126,7 @@ class Hunspell:
return []
if type(input_phrase) != type(u''):
input_phrase = input_phrase.decode('utf8')
+ sys.stderr.write("mike in suggest input_phrase=%(ip)s\n" %{'ip': input_phrase.encode('UTF-8')})
# http://pwet.fr/man/linux/fichiers_speciaux/hunspell says:
#
# > A dictionary file (*.dic) contains a list of words, one per
diff --git a/ibus-typing-booster/engine/hunspell_table.py b/ibus-typing-booster/engine/hunspell_table.py
index d09ea34..d0cf723 100644
--- a/ibus-typing-booster/engine/hunspell_table.py
+++ b/ibus-typing-booster/engine/hunspell_table.py
@@ -84,6 +84,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')
@@ -140,6 +141,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
@@ -169,12 +171,19 @@ class editor(object):
'NFKD', self._transliterated_string)
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:]
@@ -333,6 +342,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:
@@ -501,6 +511,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:
@@ -564,6 +575,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 ()
@@ -731,7 +743,10 @@ class tabengine (IBus.Engine):
if self._has_input_purpose and self._input_purpose in [IBus.InputPurpose.PASSWORD, IBus.InputPurpose.PIN]:
return False
+ 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)
+ 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
@@ -752,6 +767,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 78a4b26..2815503 100755
--- a/ibus-typing-booster/engine/tabsqlitedb.py
+++ b/ibus-typing-booster/engine/tabsqlitedb.py
@@ -241,6 +241,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:
@@ -253,8 +255,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.'''
@@ -269,6 +273,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(
@@ -299,6 +304,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:
@@ -368,9 +375,11 @@ 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 = {}
for x in self.hunspell_obj.suggest(input_phrase):
phrase_frequencies.update([(x, 0)])
+ 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}
@@ -437,6 +446,7 @@ class tabsqlitedb:
# {u'conspiracy': 6/11, u'code': 0, u'communicability': 0, u'cold': 1/11, u'colour': 4/11}
for x in results_uni:
phrase_frequencies.update([(x[0], x[1]/float(count))])
+ 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)
@@ -461,6 +471,7 @@ class tabsqlitedb:
# both the weight of 0.5:
for x in results_bi:
phrase_frequencies.update([(x[0], 0.5*x[1]/float(count_p_phrase)+0.5*phrase_frequencies[x[0]])])
+ 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)
@@ -487,6 +498,7 @@ class tabsqlitedb:
# get higher weight):
for x in results_tri:
phrase_frequencies.update([(x[0], 0.5*x[1]/float(count_pp_phrase_p_phrase)+0.5*phrase_frequencies[x[0]])])
+ 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):
@@ -592,6 +604,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
@@ -608,7 +622,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,
@@ -630,6 +647,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(