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(