__  __    __   __  _____      _            _          _____ _          _ _ 
 |  \/  |   \ \ / / |  __ \    (_)          | |        / ____| |        | | |
 | \  / |_ __\ V /  | |__) | __ ___   ____ _| |_ ___  | (___ | |__   ___| | |
 | |\/| | '__|> <   |  ___/ '__| \ \ / / _` | __/ _ \  \___ \| '_ \ / _ \ | |
 | |  | | |_ / . \  | |   | |  | |\ V / (_| | ||  __/  ____) | | | |  __/ | |
 |_|  |_|_(_)_/ \_\ |_|   |_|  |_| \_/ \__,_|\__\___| |_____/|_| |_|\___V 2.1
 if you need WebShell for Seo everyday contact me on Telegram
 Telegram Address : @jackleet
        
        
For_More_Tools: Telegram: @jackleet | Bulk Smtp support mail sender | Business Mail Collector | Mail Bouncer All Mail | Bulk Office Mail Validator | Html Letter private



Upload:

Command:

[email protected]: ~ $
�

q�g����SrSSKJr SSKJr SSKJr SSKJr SSKJr SSKJr SSKJr SS	K	r	SS	K
Jr SS	KrSS	K
r
SS	KrSS	KrSS	KrSS	KrSS	KrSS	KrSS	Kr\R*"S
5r\"S5qSrSr"S
S5r"SS5rg	)z7
Module for ibus-table to access the sqlite3 databases
�)�List)�Tuple)�Iterable)�Dict)�Union)�Optional)�CallableNz
ibus-table�1.00u!“”‘’《》〈〉〔〕「」『』【】〖〗()[]{}.。,、;:?!…—·ˉˇ¨々~‖∶"'`|⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯЁⅠⅡⅢⅣⅤⅥⅦⅧⅨⅩⅪⅫ⒈⒉⒊⒋⒌⒍⒎⒏⒐⒑⒒⒓⒔⒕⒖⒗⒘⒙⒚⒛㎎㎏㎜㎝㎞㎡㏄㏎㏑㏒㏕ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ⑴⑵⑶⑷⑸⑹⑺⑻⑼⑽⑾⑿⒀⒁⒂⒃⒄⒅⒆⒇€$¢£¥¤→↑←↓↖↗↘↙ァアィイゥウェエォオカガキギクグケゲコゴサザシジスズセゼソゾタダチヂッツヅテデトドナニヌネノハバパヒビピフブプヘベペホボポマミムメモャヤュユョヨラリルレロヮワヰヱヲンヴヵヶーヽヾぁあぃいぅうぇえぉおかがきぎぱくぐけげこごさざしじすずせぜそぞただちぢっつづてでとどなにぬねのはばひびぴふぶぷへべぺほぼぽまみむめもゃやゅゆょよらりるれろゎわゐゑをん゛゜ゝゞ勹灬冫艹屮辶刂匚阝廾丨虍彐卩钅冂冖宀疒肀丿攵凵犭亻彡饣礻扌氵纟亠囗忄讠衤廴尢夂丶āáǎàōóǒòêēéěèīíǐìǖǘǚǜüūúǔù+-<=>±×÷∈∏∑∕√∝∞∟∠∣∥∧∨∩∪∫∮∴∵∶∷∽≈≌≒≠≡≤≥≦≧≮≯⊕⊙⊥⊿℃°‰♂♀§№☆★○●◎◇◆□■△▲※〓#&@\^_ ̄абвгдежзийклмнопрстуфхцчшщъыьэюяёⅰⅱⅲⅳⅴⅵⅶⅷⅸⅹβγδεζηαικλμνξοπρστυφθψω①②③④⑤⑥⑦⑧⑨⑩①②③④⑤⑥⑦⑧⑨⑩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩㈠㈡㈢㈣㈤㈥㈦㈧㈨㈩ㄅㄆㄇㄈㄉㄊㄋㄌㄍㄎㄏㄐㄑㄒㄓㄔㄕㄖㄗㄘㄙㄧㄨㄩㄚㄛㄜㄝㄞㄟㄠㄡㄢㄣㄤㄥㄦc��\rSrSrSrSS\\RRS\\	\
\
4SS4SjjrS\
S\
4S	jrS\
4S
jr
Srg)
�
ImeProperties�Rz5
A class to cache the properties of an input method.
N�db�default_properties�returnc���Uc0nU(dgX lSnURU5R5nWHnUSURUS'M g! [R	S5 N8=f)uT
“db” is the handle of the sqlite3 database file obtained by
sqlite3.connect().
NzSELECT attr, val FROM main.ime;z'Cannot get ime properties from database�r)�ime_property_cache�execute�fetchall�LOGGER�	exception)�selfrr�sqlstr�results�results      �+/usr/share/ibus-table/engine/tabsqlitedb.py�__init__�ImeProperties.__init__Vsy���%�!#����"4��2��	H��j�j��(�1�1�3�G��F�17���D�#�#�F�1�I�.���	H����F�G�s�A�A.�keyc�@�XR;aURU$g)zi
Return the value for a key from the property cache

:param key: The key to lookup in the property cache
��r)rrs  r�get�ImeProperties.getks$���)�)�)��*�*�3�/�/��c�2�S[UR5-$)Nzime_property_cache = %s)�reprr�rs r�__str__�ImeProperties.__str__us��(�$�t�/F�/F�*G�G�Gr%r")NN)�__name__�
__module__�__qualname__�__firstlineno__�__doc__r�sqlite3�dbapi2�
Connectionr�strrr#r)�__static_attributes__�r%rrrRso���
7;�;?�;�����2�2�3�;�!)��c�3�h�� 8�;�EI�;�*�s��s��H��Hr%rc��\rSrSrSrSPS\S\S\S\SS4
S	jjrSQS
\S\S\S
\S\SS4Sjjr	SRSjr
SRSjrSSS
\SS4SjjrSRSjr
SRSjrS\4SjrS\4SjrS\4SjrS\4SjrS\4SjrS
\SS4SjrS\\\\4SS4SjrS\\\\4\\\\\\4444SjrS\\4SjrS\4SjrS\4S jrSTS!\\\\\\4S
\SS4S"jjrSUS
\S\S#\S\S
\S\SS4S$jjr S%\\\\4SS4S&jr!STS'\\\\\4S
\SS4S(jjr"STS)\\\\4S
\SS4S*jjr#SRS+jr$S,\SS4S-jr%SVS,\S.\SS4S/jjr&S\S\'4S0jr(SWS1\S2\\\\\\4S3\S\\\\\\44S4jjr)SXS
\S5\S3\S6\S7\S8\S9\S\\\\\\44S:jjr*SYS
\S3\S6\S7\S\\\\\\44
S;jjr+SSS<\S\\\\44S=jjr,SRS>jr-S?\SS4S@jr.S?\S\/\\\44SAjr0S?\S\4SBjr1SC\S\4SDjr2S\S\4SEjr3SZS
\S\S\4SFjjr4SZS
\S\S\4SGjjr5S[S
\S\S9\SS4SHjjr6S\S\\4SIjr7S\S
\S\S
\S\SS4
SJjjr8SRSKjr9S]SL\SM\S\\\\\\44SNjjr:SOr;g)^�TabSqliteDb�xu�Phrase database for tables

The phrases table in the database has columns with the names:

“id”, “tabkeys”, “phrase”, “freq”, “user_freq”

There are 2 databases, sysdb, userdb.

sysdb: System database for the input method, for example something
       like /usr/share/ibus-table/tables/wubi-jidian86.db
       “user_freq” is always 0 in a system database.  “freq”
       is some number in a system database indicating a frequency
       of use of that phrase relative to the other phrases in that
       database.

user_db: Database on disk where the phrases used or defined by the
       user are stored. “user_freq” is a counter which counts how
       many times that combination of “tabkeys” and “phrase” has
       been used. “freq” is equal to 0 for all combinations of
       “tabkeys” and “phrase” where an entry for that phrase is
       already in the system database which starts with the same
       “tabkeys”.
       For combinations of “tabkeys” and “phrase” which do not exist
       at all in the system database, “freq” is equal to -1 to
       indidated that this is a user defined phrase.
�filename�user_db�create_database�	unit_testrNc�J�[[[R"S555q/UlXlX l	UR5 U(d.[RRUR5(a&[R"UR5UlO[!SUR-5 URR#S5 URR#S5 URR#S5 URR#S5 URR#S5 URR#S	5 URR#S
5 URR)S5 0S
S_SS_SS_SS_SS_SS[*R,"5-_SS[.R0"S5-_SS_SS_SS_SS_SS_S S!_S"S#_S$S%_S&S'_S(S)_0S*S_S+S,_S-S._S/S._S0S._S1S._S2S._S3S._S4S._S5S,_S6S7_S8S9_S:S_S;S_S<S=_S>S_S?S,_ES,S@SA.EUlU(a}SBnSCn[5UR25H`nUUR2USD.nURR#XX5R75(aMEURR#Xh5 Mb [9URUR2SE9Ul[UR:R=S 55UlUR:R=S5Ul URC5Ul"URG5Ul$UR:R=S/5RK5S,:HUl&URO5Ul(URS5Ul*URW5Ul,[RZ"[\R^"5SF5n	[RRaUR5RcSGSH5n
[RZ"X�5Ul2U(dURg5 U(aU(agUSI:wGa][Rh"U	5(Gd�[RRkSJ5n[Rh"U5(Ga;[Rl"[RR[USK5[Rn5(a4[Rp"[RR[USK55 [Rl"[RR[USL5[Rn5(a4[Rp"[RR[USL55 [rRt"X�5 [rRv"U5 [Rx"X�5 O[Rz"U	SMSN9 [RZ"X�5n[R|"U5(d[$RSOU5 GOmUR�U5n/SPQn
Ub,USQ[�:wdUR�U5[�U
5:wGa[$RSRU5 Uc+[$RSS5 UR�USTSU9UlO�USQ[�:wa6[$RSV[�USQ5 UR�X,SQSU9UlOTUR�U5[�U
5:wa6[$RSW[�U
5UR�U55 /Ul[.R0"SX5n[$RSYX.-5 [RR}U5(a[R�"X"U-5 [RR}USZ-5(a [R�"USZ-USZ-U-5 [RR}US[-5(a [R�"US[-US[-U-5 [$RS\U5 UR�U5 [$RS]5 O[$RS^U5 [$RS`U5 URR)SaU-5 UR�Sc5 UR(a�/nURH%nUR�USUSdUSeUSfSg.5 M' ShnURR�UU5 URR�5 URR#Sj5 UR�Sc5 UR�5 g![
[4a [S5qG	N�f=f! [$R'S5 GN�=f! [$R'S_5 GN]=f! [$RSbU5 [.R0"SX5n[$RSYX.-5 [RR}U5(a[R�"X"U-5 [RR}USZ-5(a [R�"USZ-USZ-U-5 [RR}US[-5(a [R�"US[-US[-U-5 [$RS\U5 UR�U5 URR)SaU-5 GN�=f! [$R'Si5 GN)=f)kN�IBUS_TABLE_DEBUG_LEVELrzCannot open database file %szPRAGMA encoding = "UTF-8";z"PRAGMA case_sensitive_like = true;zPRAGMA page_size = 4096;zPRAGMA cache_size = 20000;zPRAGMA temp_store = MEMORY;z$PRAGMA journal_size_limit = 1000000;zPRAGMA synchronous = NORMAL;z!Error while initializing databasez:CREATE TABLE IF NOT EXISTS main.ime (attr TEXT, val TEXT);�namer!z
name.zh_cnz
name.zh_hkz
name.zh_tw�author�somebody�uuidz%s�
serial_numberz%Y%m%d�iconzibus-table.svg�license�LGPL�	languages�language_filter�valid_input_chars�abcdefghijklmnopqrstuvwxyz�max_key_length�4�commit_keys�space�select_keys�1,2,3,4,5,6,7,8,9,0�page_up_keysz!Page_Up,KP_Page_Up,KP_Prior,minus�page_down_keysz$Page_Down,KP_Page_Down,KP_Next,equal�
status_prompt�def_full_width_punct�true�def_full_width_letter�false�user_can_define_phrase�pinyin_mode�suggestion_mode�dynamic_adjust�auto_select�auto_commit�
auto_wildcard�descriptionzA IME under IBus Table�layout�us�symbol�rules�least_commit_length�0�start_chars�orientationz{})�always_show_lookup�char_promptsz9
            SELECT val FROM main.ime WHERE attr = :attr;zC
            INSERT INTO main.ime (attr, val) VALUES (:attr, :val);��attr�val�rr�tables�.dbz.cache�:memory:z~/.ibus/tablesz	debug.logzsetup-debug.logT)�exist_okz(The user database %s does not exist yet.)�id�tabkeys�phrase�freq�	user_freq�versionz.The user database %s seems to be incompatible.z0There is no version information in the database.�0.0)�old_database_versionz�The version of the database does not match (too old or too new?). ibus-table wants version=%s But the  database actually has version=%sz�The number of columns of the database does not match. ibus-table expects %s columns. But the database actually has %s columns. But the versions of the databases are identical. This should never happen!z-%Y-%m-%d_%H:%M:%Sz+Renaming the incompatible database to "%s".z-shmz-walz$Creating a new, empty database "%s".z�If user phrases were successfully recovered from the old, incompatible database, they will be used to initialize the new database.zCompatible database %s found.z-Unexpected error trying to find user databasezConnect to the database %s.a�
                ATTACH DATABASE "%s" AS user_db;
                PRAGMA user_db.encoding = "UTF-8";
                PRAGMA user_db.case_sensitive_like = true;
                PRAGMA user_db.page_size = 4096;
                PRAGMA user_db.cache_size = 20000;
                PRAGMA user_db.temp_store = MEMORY;
                PRAGMA user_db.journal_mode = WAL;
                PRAGMA user_db.journal_size_limit = 1000000;
                PRAGMA user_db.synchronous = NORMAL;
            zCould not open the database %s.r:r���rsrtrurvz�
            INSERT INTO user_db.phrases (tabkeys, phrase, freq, user_freq)
            VALUES (:tabkeys, :phrase, :freq, :user_freq)
            zError inserting old phrases�PRAGMA wal_checkpoint;)M�intr3�os�getenv�DEBUG_LEVEL�	TypeError�
ValueError�old_phrasesr9�_user_db�reset_phrases_cache�path�isfiler0�connectr�printrrr�
executescriptrB�uuid4�time�strftime�_default_ime_attributes�sortedrr�ime_propertiesr#�_mlen�_snum�
is_chinese�_is_chinese�is_cjk�_is_cjk�lowerrX�	get_rulesrc�get_possible_tabkeys_lengths�possible_tabkeys_lengths�get_start_chars�
startchars�join�ibus_table_location�	data_home�basename�replace�
cache_path�load_phrases_cache�isdir�
expanduser�access�F_OK�unlink�shutil�copytree�rmtree�symlink�makedirs�exists�debug�get_database_desc�DATABASE_VERSION�%get_number_of_columns_of_phrase_table�len�extract_user_phrases�rename�init_user_db�
create_tables�append�executemany�commit�create_indexes�generate_userdb_desc)rr9r:r;r<�
select_sqlstr�
insert_sqlstrrk�sqlargs�tables_path�
cache_name�old_tables_path�desc�phrase_table_column_names�	timestamp�sqlargs_old_phrasesrtrs                  rr�TabSqliteDb.__init__�s]
��	!��c�"�)�)�,D�"E�F�G�K�=?��� �
��
�� � �"��b�g�g�n�n�T�]�]�;�;�18������1O�D�G��0�$�-�-�?�@�
	B��G�G�O�O�8�9��G�G�O�O�@�A��G�G�O�O�6�7��G�G�O�O�8�9��G�G�O�O�9�:��G�G�O�O�B�C��G�G�O�O�:�;�	
�����H�	J�*(
��2�*(
���*(
�
��*(
�
��	*(
�

�Z�*(
�
�4�$�*�*�,�&�
*(
�
�D�4�=�=��#:�:�*(
�
�#�*(
�
�f�*(
�
��*(
�
�b�*(
�
 � <�*(
�
�S�*(
�
�'�*(
� 
�/�!*(
�"
�>�#*(
�$
�C�%*(
�&
�B�'*(
�(
#�6�)*(
�*
$�G�+*(
�,
%�W�-*(
�.
�'�/*(
�0
�g�1*(
�2
�W�3*(
�4
�'�5*(
�6
�'�7*(
�8
�V�9*(
�<
�2�=*(
�>
�T�?*(
�@
�R�A*(
�B
�B�C*(
�D
"�#�E*(
�F
�"�G*(
�H
�&�I*(
�J"(��M*(
��$�V�<�M�F�M��t�;�;�<�� ��7�7��=����w�w���}�>�G�G�I�I��G�G�O�O�M�;�
=�,��w�w�#�;�;�=�����,�,�0�0�1A�B�C��
��(�(�,�,�_�=��
��?�?�,����{�{�}���'+�':�':�'>�'>�$�(&�&+�e�g��(8��#��^�^�%��
�(,�(I�(I�(K��%��.�.�0����i�i� 3� =� =� ?��J���W�W�%�%�d�m�m�4�<�<�U�H�M�
��)�)�K�<�����#�#�%��/�
��j� ��:�:�k�*�*�"$�'�'�"4�"4�5E�"F���:�:�o�.�.��y�y������+�[�":�;=�7�7�D�D��	�	�"�'�'�,�,���"L�M��y�y������+�->�"@�AC���J�J��	�	�"�'�'�,�,�+�->�#@�A��O�O�O�A��M�M�/�2��J�J�{�<��K�K��d�;��i�i��5�G��;�;�w�'�'����>��I�AI��1�1�'�:�D�1H�-���#�I��2B�B� $� J� J� '�!)�#&�'@�#A�!B����L�#�%� �<�"�L�L�!0�1�04�/H�/H� '�e�0I�0E�D�,�!�)�_�0@�@�"�L�L�!L�!1�$�y�/�C�04�/H�/H� '�9�o�0I�0O�D�,�"�H�H� '�)�!$�%>�!?�@�#�L�L�!<�!$�$=� >� $� J� J�$+�!-�
.�02�D�,�$(�M�M�2F�$G�	����I�#�-�/��7�7�>�>�'�2�2��I�I�g�y�/@�A��7�7�>�>�'�&�.�9�9��I�I�g�f�n�g�f�n�Y�6N�O��7�7�>�>�'�&�.�9�9��I�I�g�f�n�g�f�n�Y�6N�O����B�G�M��)�)�'�2����;�<����;�W�F�%	��L�L�-�w�
8��G�G�!�!�
#��
#�

�F	
���9�%����DF���*�*��#�*�*� &�q�	�%�a�y�#�A�Y�"(��)�-�.�+��F�
@����#�#�F�,?�@�
�G�G�N�N���G�G�O�O�4�5�	
���I�&��!�!�#��_�:�&�	!��a�&�K�	!��(	B����@�A��rI��$�$�G�I��$	��L�L�:�G�D��
�
�&:�;�I��L�L�F� �*�
,��w�w�~�~�g�&�&��	�	�'�9�#4�5��w�w�~�~�g�f�n�-�-��	�	�'�&�.�'�&�.��*B�C��w�w�~�~�g�f�n�-�-��	�	�'�&�.�'�&�.��*B�C��L�L�?��I����g�&��G�G�!�!�
#��
#�

��4
@�� � �!>�?�sJ�(g�B=g2� Ih�5h�
4h,�n�g/�.g/�2h�h)�,En�n"rsrtrv�databaser�c�N�[S:�a[RSXX45 U(aU(dgSU-nUUUS.nURR	Xg5 U(aURR5 UR
U5 g! [RS5 g=f)zupdate phrase freqsrz-tabkeys=%s phrase=%s user_freq=%s database=%sNzu
        UPDATE %s.phrases SET user_freq = :user_freq
        WHERE tabkeys = :tabkeys AND phrase = :phrase
        ;)rvrsrtz,Unexpected error updating phrase in user_db.)r�rr�rrr��invalidate_phrases_cacher)rrsrtrvr�r�rr�s        r�
update_phrase�TabSqliteDb.update_phrase�s�����?��L�L�?���
6��f��
����!*�%�#�%��	M��G�G�O�O�F�,������� ��)�)�'�2��	M����K�L�s�A
B�B$c��UR5 URcgURR5 URR	S5 g)z!
Trigger a checkpoint operation.
Nr})�save_phrases_cacher�rr�rr(s r�
sync_usrdb�TabSqliteDb.sync_usrdb�s<��	
���!��=�=� �������������0�1r%c�P�[S:�a[RS5 0Ulg)z
Make the phrases cache empty
rzreset_phrases_cache()N)r�rr��_phrases_cacher(s rr��TabSqliteDb.reset_phrases_cache�s ����?��L�L�0�1�Y[��r%c��[S:�a[RS5 [SURS-5HFnUR
R
USU5(dM(UR
RUSU5 MH g)uh
Delete all phrases starting with “tabkeys” from
the phrases cache.

:param tabkeys: The keys typed
rzinvalidate_phrases_cache()rN)r�rr��ranger�r�r#�pop)rrs�is   rr��$TabSqliteDb.invalidate_phrases_cache�sh����?��L�L�5�6��q�$�*�*�q�.�)�A��"�"�&�&�w�q��|�4�4��#�#�'�'���!��5�*r%c�<�[S:�a[RS5 [R"[UR55UlURRS5nU(aXR:wa0Ulgg![a/ [S:�a"[RSUR5 gg[a/ [S:�a"[RSUR5 gg [RSUR5 g=f)z
Load phrases cache from disk
rzload_phrases_cache()rCzFile %s not foundzPermission error reading %szUnknown error reading %sN)r�rr��json�load�openr�r�r#r��FileNotFoundError�PermissionError)r�snums  rr��TabSqliteDb.load_phrases_cache�s�����?��L�L�/�0�	F�"&�)�)�D����,A�"B�D���&�&�*�*�?�;�D��D�J�J�.�&(��#�/�� �	:��Q�����'����:���	D��Q�����1�4�?�?�D��	F��L�L�3�T�_�_�E�s�A&B	�	4D�3D�8!Dc�b�[S:�a[RS5 URURS'UR
S-n[R"UR[US55 [R"XR
5 g! [RS5 g=f)z
Save phrases cache from disk
rzsave_phrases_cache()rCz.tmp�wz)Unexpected error in save_phrases_cache().N)r�rr�r�r�r�r��dumpr�rr�r)r�_cache_paths  rr��TabSqliteDb.save_phrases_cache�s�����?��L�L�/�0�	J�37�:�:�D����0��/�/�F�2�K�
�I�I�d�)�)�4��S�+A�B��J�J�{�O�O�4��	J����H�I�s�A3B�B.c���URRS5nU(a?URS5nUH(nUR5R	S5S:wdM( g g)zO
Check whether this input method is classified as Chinese
in the the database.
rG�,�zh���TF)r�r#�splitr��find)rrG�langs�langs    rr��TabSqliteDb.is_chinesesV��
�'�'�+�+�K�8�	���O�O�C�(�E����:�:�<�$�$�T�*�b�0���r%c���URRS5nU(aJURS5nUH3nSH*nUR5R	U5(dM)  g M5 g)z`
Check whether this input method is classified as Chinese,
Japanese, or Korean in the database.
rGr�)r��ja�koTF)r�r#r��strip�
startswith)r�
languages_strrG�languager�s     rr��TabSqliteDb.is_cjksa��
�+�+�/�/��<�
��%�+�+�C�0�I�%��.�D��~�~�'�2�2�4�8�8�#�/�&�r%c�b�URRS5nUS;a[US5$g)a}
Get the default Chinese mode from the database

0 means to show simplified Chinese only
1 means to show traditional Chinese only
2 means to show all characters but show simplified Chinese first
3 means to show all characters but show traditional Chinese first
4 means to show all characters

If no mode is specified in the database, return 4 to avoid all
filtering of characters.
rH)�cm0�cm1�cm2�cm3�cm4r��)r�r#r~)rrHs  r�get_chinese_mode�TabSqliteDb.get_chinese_mode*s7���-�-�1�1�2C�D���A�A���r�*�+�+�r%c�L�URRS5nU(aU$g)z;
Get the keys used to select a candidate from the database
rOrP�r�r#)r�rets  r�get_select_keys�TabSqliteDb.get_select_keys<s%���!�!�%�%�m�4����J�$r%c�x�[URRS55$![[4a gf=f)zAGet the default orientation of the lookup table from the databasergr)r~r�r#r�r�r(s r�get_orientation�TabSqliteDb.get_orientationEs:��	��t�*�*�.�.�}�=�>�>���:�&�	��	�s�#&�9�9c�D�US:Xa`SU-nURRU5 SU-nURRU5 SU-nURRU5 SU-nURRU5 URR5 g)z%Create tables that contain all phrase�mainzp
            CREATE TABLE IF NOT EXISTS %s.goucima
            (zi TEXT PRIMARY KEY, goucima TEXT);
            zp
            CREATE TABLE IF NOT EXISTS %s.pinyin
            (pinyin TEXT, zi TEXT, freq INTEGER);
            zk
            CREATE TABLE IF NOT EXISTS %s.suggestion
            (phrase TEXT, freq INTEGER);
            z�
        CREATE TABLE IF NOT EXISTS %s.phrases
        (id INTEGER PRIMARY KEY, tabkeys TEXT, phrase TEXT,
        freq INTEGER, user_freq INTEGER);
        N)rrr�)rr�rs   rr��TabSqliteDb.create_tablesLs����v�����F�
�G�G�O�O�F�#����F�
�G�G�O�O�F�#����F�
�G�G�O�O�F�#���	��
	
������������r%�attrsc�|�SnSnSnUHoupVXVS.nURRX'5R5(aURRX75 MTURRXG5 Mq URR5 [	URUR
S9Ul[URRS55Ul	UR5UlURRS5R5S:HUl
UR5Ulg	)
z�Update or insert attributes in ime table, attrs is a iterable object
Like [(attr,val), (attr,val), ...]

This is called only by tabcreatedb.py.
z+SELECT val from main.ime WHERE attr = :attrz2UPDATE main.ime SET val = :val WHERE attr = :attr;z6INSERT INTO main.ime (attr, val) VALUES (:attr, :val);rjrmrKrXrUN)rrrr�rr�r�r~r#r�r�r�r�rXr�rc)rrr��
update_sqlstrr�rkrlr�s        r�
update_ime�TabSqliteDb.update_imegs���F�
�L�
�D�	��I�D�#�0�G��w�w���}�6�?�?�A�A������
�7������
�7��	
������+��w�w�#�;�;�=�����,�,�0�0�1A�B�C��
��?�?�,���'+�':�':�'>�'>�$�(&�&+�e�g��(8��#��^�^�%��
r%c
���0n[R"S5n[R"S5nUR(d0$URR	S5n/nU(aUR5R
S5nUGH.nURU5nU(Ga/nURS5S:Xa[URS55US'URS	5R
S
5n	[U	5UR:�a[SU-5  U$U	H`n
URU
5nU(dMUR[URS55[URS5545 Mb X�[URS55'GM [SU-5 GM1 U$![a [R!S
5 U$f=f)aJGet phrase construct rules

Example:

The wubi-jidian86.txt table source contains:

RULES = ce2:p11+p12+p21+p22;ce3:p11+p21+p31+p32;ca4:p11+p21+p31+p-11

and the return value of this function becomes:

{2: [(1, 1), (1, 2), (2, 1), (2, 2)],
 3: [(1, 1), (2, 1), (3, 1), (3, 2)],
 'above': 4,
 4: [(1, 1), (2, 1), (3, 1), (-1, 1)]}
zc([ea])(\d):(.*)zp(-{0,1}\d)(-{0,1}\d)rc�;r�arz�abover{�+zrule: "%s" over max key lengthznot a legal rule: "%s"z Unexpected error in get_rules().)�re�compilerXr�r#r�r��match�groupr~r�r�r�r��	Exceptionrr)rrc�patt_r�patt_p�
_rules_str�_rules�rule�res�cms�_cms�_cm�cm_ress            rr��TabSqliteDb.get_rules�s��� KM�����/�0�����4�5���*�*��I�	A��,�,�0�0��9�J� "�F��#�)�)�+�1�1�#�6�����l�l�4�(����C��y�y��|�s�*�),�S�Y�Y�q�\�):��g���9�9�Q�<�-�-�c�2�D��4�y�4�:�:�-��>��D�E���� $��!'���c�!2��!�6��J�J��F�L�L��O�(<�(+�F�L�L��O�(<�(>�?� $�
03�#�c�i�i��l�+�,��2�D�8�9�#�(����	A����?�@���	A�s �CF>�#F>�A9F>�>G!� G!c��UR(aHURSn[SUS-5Vs/sHn[URU5PM snSS$[URRS55nUS:�a![[X0RS-55$/$s snf![[4a SnNBf=f)unReturn a list of the possible lengths for tabkeys in this table.

Example:

If the table source has rules like:

    RULES = ce2:p11+p12+p21+p22;ce3:p11+p21+p22+p31;ca4:p11+p21+p31+p41

self._rules will be set to

    self._rules = {
        2: [(1, 1), (1, 2), (2, 1), (2, 2)],
        3: [(1, 1), (1, 2), (2, 1), (3, 1)],
        4: [(1, 1), (2, 1), (3, 1), (-1, 1)],
        'above': 4}

and then this function returns “[4, 4, 4]”

Or, if the table source has no RULES but LEAST_COMMIT_LENGTH=2
and MAX_KEY_LENGTH = 4, then it returns “[2, 3, 4]”

I cannot find any tables which use LEAST_COMMIT_LENGTH though.
rrzrNrdr)
rcr�r�r~r�r#r�r��listr�)r�max_len�x�least_commit_lens    rr��(TabSqliteDb.get_possible_tabkeys_lengths�s���0�:�:��j�j��)�G�05�a����0C�D�0C�1�C��
�
�1�
�&�0C�D�Q�G�G�	!�"��#�#�'�'�(=�>� @���a����.�
�
�Q��?�@�@��	��E���:�&�	!� ��	!�s�"B(�$B-�-C�Cc�8�URRS5$)z"return possible start chars of IMErfrr(s rr��TabSqliteDb.get_start_chars�s���"�"�&�&�}�5�5r%c�<�URRS5nU$)z6Get the characters which engine should not change freq�no_check_charsr)r�_charss  r�get_no_check_chars�TabSqliteDb.get_no_check_chars�s���$�$�(�(�)9�:���
r%�phrasesc��[S:�a([RS[[	U555 SRUS9n/nUH-upVpxUR
UUUUS.5 URU5 M/ URRX45 URR5 URRS5 g)uPAdd many phrases to database fast. Used by tabcreatedb.py when
creating the system database from scratch.

“phrases” is a iterable object which looks like:

    [(tabkeys, phrase, freq ,user_freq),
     (tabkeys, phrase, freq, user_freq), ...]

This function does not check whether phrases are already
there.  As this function is only used while creating the
system database, it is not really necessary to check whether
phrases are already there because the database is initially
empty anyway. And the caller should take care that the
“phrases” argument does not contain duplicates.

rzlen(phrases)=%s��
        INSERT INTO {database}.phrases
        (tabkeys, phrase, freq, user_freq)
        VALUES (:tabkeys, :phrase, :freq, :user_freq);
        �r�r|r}N)r�rr�r�r'�formatr�r�rr�r�r)	rr3r�r��insert_sqlargsrsrtrurvs	         r�add_phrases�TabSqliteDb.add_phrases�s���(��?��L�L�*�C��W�
�,>�?��
�F�H�F�%�		�
��29�.�W�d��!�!�"� ��&�	#(�
)�

�)�)�'�2�
3:�	
�����M�:������������0�1r%ruc�n�[S:�a[RSXX45 U(aU(dgSRUS9nXS.nURRXx5R
5n	U	(a"[S:�a[RSXxU	5 gSRUS9n
UUUUS	.n[S:�a[RS
X�5 URRX�5 U(aURR5 URU5 g! [RS5 g=f)zQAdd phrase to database, phrase is a object of
(tabkeys, phrase, freq ,user_freq)
rz4add_phrase tabkeys=%s phrase=%s freq=%s user_freq=%sNzi
        SELECT * FROM {database}.phrases
        WHERE tabkeys = :tabkeys AND phrase = :phrase;
        r6�rsrtzKselect_sqlstr=%(sql)s select_sqlargs=%(arg)s already there!: results=%(r)s r5r|z"insert_sqlstr=%s insert_sqlargs=%sz Unexpected error in add_phrase())
r�rr�r7rrrr�r�r)rrsrtrurvr�r�r��select_sqlargsrr�r8s            r�
add_phrase�TabSqliteDb.add_phrases#����?��L�L�'���
2��f���
�F�H�F�%�	�&-�?���'�'�/�/�-�@�I�I�K����Q�����5�!�7�<�
��
�F�H�F�%�		����"�	$��
��?��L�L�4��
/�	A��G�G�O�O�M�:������� ��)�)�'�2��	A����?�@�s
�
A
D�D4�goucimasc�V�Sn/nUHupEURXES.5 M URR5 URRX#5 URR5 URR	S5 g! [
R
S5 g=f)ziAdd goucima into database, goucimas is iterable object
Like goucimas = [(zi,goucima), (zi,goucima), ...]
zP
        INSERT INTO main.goucima (zi, goucima) VALUES (:zi, :goucima);
        )�zi�goucimar}z"Unexpected error in add_goucima().N)r�rr�r�rrr)rr@rr�rBrCs      r�add_goucima�TabSqliteDb.add_goucima?s�������#�K�B��N�N�"�9�:�$�	C��G�G�N�N���G�G����0��G�G�N�N���G�G�O�O�4�5��	C����A�B�s�A*B�B(�pinyinsc	��SU-nSnUH|upVnUS-
nURSS5RSS5RSS	5RS
S5RSS
5nURRX5XgS.5 M~ URR
5 g![a [RSXEXg5 M�f=f)zhAdd pinyin to database, pinyins is a iterable object
Like: [(zi,pinyin, freq), (zi, pinyin, freq), ...]
zX
        INSERT INTO %s.pinyin (pinyin, zi, freq) VALUES (:pinyin, :zi, :freq);
        rr�1�!�2�@�3�#rL�$�5�%)�pinyinrBruzHError when inserting into pinyin table. count=%s pinyin=%s zi=%s freq=%sN)r�rrrrrr�)rrFr�r�countrQrBrus        r�
add_pinyin�TabSqliteDb.add_pinyinQs��������� '��F���Q�J�E��^�^��S��!�'����%�g��S�"�")�'���#&�&-�g� #�S�'*�	
�
-�������R�F�H�!(� 	
��������
-�� � �7��2�-�
-�s�(B%�%!C
�	C
�suggestionsc���SU-nSnUH)upVUS-
nURRX5US.5 M+ URR5 g![a [R	SXEU5 Mlf=f)zpAdd suggestion phrase to database, suggestions is a iterable object
Like: [(phrase, freq), (phrase, freq), ...]
zS
        INSERT INTO %s.suggestion (phrase, freq) VALUES (:phrase, :freq);
        rr)rtruzFError when inserting into suggestion table. count=%s phrase=%s freq=%sN)rrrrrr�)rrUr�rrRrtrus       r�add_suggestion�TabSqliteDb.add_suggestionns���������'�L�F��Q�J�E�
)�������t�<�>�(�	
��������
)�� � �1��4�)�
)�s�A�!A7�6A7c��SnURRU5 URRS5 URR5 g)zM
Optimize the database by copying the contents
to temporary tables and back.
a�
            CREATE TABLE tmp AS SELECT * FROM main.phrases;
            DELETE FROM main.phrases;
            INSERT INTO main.phrases SELECT * FROM tmp ORDER BY
            tabkeys ASC, phrase ASC, user_freq DESC, freq DESC, id ASC;
            DROP TABLE tmp;
            CREATE TABLE tmp AS SELECT * FROM main.goucima;
            DELETE FROM main.goucima;
            INSERT INTO main.goucima SELECT * FROM tmp ORDER BY zi, goucima;
            DROP TABLE tmp;
            CREATE TABLE tmp AS SELECT * FROM main.pinyin;
            DELETE FROM main.pinyin;
            INSERT INTO main.pinyin SELECT * FROM tmp ORDER BY pinyin ASC, freq DESC;
            DROP TABLE tmp;
            CREATE TABLE tmp as SELECT * FROM main.suggestion;
            DELETE FROM main.suggestion;
            INSERT INTO main.suggestion SELECT * FROM tmp ORDER by phrase ASC, freq DESC;
            DROP TABLE tmp;
            zVACUUM;N)rr�r�)rrs  r�optimize_database�TabSqliteDb.optimize_database�s=��
��&	
�����f�%������i�(������r%�	_databasec�D�[S:�a[RS5 gg)z�Drop the indexes in the database to reduce its size

We do not use any indexes at the moment, therefore this
function does nothing.
rzdrop_indexes()N�r�rr�)rr\s  r�drop_indexes�TabSqliteDb.drop_indexes�s����?��L�L�)�*�r%�_commitc�D�[S:�a[RS5 gg)u�Create indexes for the database.

We do not use any indexes at the moment, therefore
this function does nothing. We used indexes before,
but benchmarking showed that none of them was really
speeding anything up, therefore we deleted all of them
to get much smaller databases (about half the size).

If some index turns out to be very useful in future, it could
be created here (and dropped in “drop_indexes()”).
rzcreate_indexes()Nr^)rr\ras   rr��TabSqliteDb.create_indexes�s����?��L�L�+�,�r%c�P�URS5nU$![a SnU$f=f)z�
Encode a string in Big5 or, if that is not possible,
return something higher than any Big5 code.

:param phrase: String to be encoded in Big5 encoding
�Big5���)�encode�UnicodeEncodeError)rrt�big5s   r�	big5_code�TabSqliteDb.big5_code�s7��	��=�=��(�D����"�	��D���	�s��%�%�
typed_tabkeys�
candidates�chinese_modec�r^^^^�Sn[RRUR5R	SS5nSmUS;aUR
mUR(aU4SjmOSmUS;a0UR(aUS	:XaS
mOS	m[UUUUU4SjS9S
U$[UUUU4SjS9S
U$)u�
“candidates” is an array containing something like:
[(tabkeys, phrase, freq, user_freq), ...]

“typed_tabkeys” is key sequence the user really typed, which
maybe only the beginning part of the “tabkeys” in a matched
candidate.
�dror!c��g�Nrfr5�r)s r�<lambda>�-TabSqliteDb.best_candidates.<locals>.<lambda>����r%��cangjie3�cangjie5zcangjie-bigz
quick-classic�quick3�quick5c�F>�[TUSS:H=(a USS;5*$)Nr�z!@#$%)r~)r)rls �rrtru�s'����m�q��"�v�-�C�1�R�5�G�3C�D�Dr%c��g)Nrr5rss rrtru�s��Qr%)rzr{rzrc��>�[TUS:H5*T"US5SUS-T[R"US5-*SUS-[US5UST"USS5[	USS54	$)Nrr�r{rrz)r~�chinese_variants�detect_chinese_categoryr��ord)r)�bitmask�code_point_function�pinyin_exact_match_functionrls ����rrtru�s���� #�"/�1�Q�4�"7�! � �:�!�A�$�?� ��1��g�!(�"2�"J�"J�$%�a�D�#*�!*�+�!��1��g�!�!�A�$�i���d�1�!�A�$�q�'�:�!�!�A�$�q�'�l�!)r%�rNc�>�[TUS:H5*T"US5SUS-SUS-[US5UST"USS5[USS54$)Nrr�r{rzr�r~r�r�)r)r�r�rls ���rrtru�sv����+�q��t�3���6�a��d�;��Q�q�T�'��Q�q�T�'��a��d�)��A�$�-�a��d�1�g�6��a��d�1�g�,�%r%)rr�r�r9r�rjr�r�)	rrlrmrn�maximum_number_of_candidates�engine_namer�r�r�s	 `    @@@r�best_candidates�TabSqliteDb.best_candidates�s����(+�$��g�g�&�&�t�}�}�5�=�=�e�R�H��6M���5�5�#'�.�.�����A�'�+8�'��6�!�d�&6�&6��q� �!��!���*���$;�:�%<�
<�&�j��
�7�6�
8�
	8r%�onechar�single_wildcard_char�multi_wildcard_charr^r[c��U(d/$URRU5nU(aU$Sn	U(aSn	UR(dU(aSRU	S9n
OSRU	S9n
SnSHnX�U4;dMUnM Un
U
R	X�U-5n
SXE4;aU
R	SUS-5n
S	XE4;aU
R	S	US	-5n
U(aU
R	US	5n
U(aU
R	US
5n
U(aU
S
-
n
X�S.n[
S:�a [RS
U
[U55 URRX�5R5nSnUS:XaSnOUS:XaSnU(dUnO?/nUH7nU[R"US5-(dM&URU5 M9 0nUHYnUSUS4nUU;aUUU'MURUU[!USUUS5[!USUUS54-4/5 M[ UR#UUR%5US9n[
S:�a[RS[U55 X�RU'U$)z5
Get matching phrases for tabkeys from the database.
r!z AND length(phrase)=1 a�
            SELECT tabkeys, phrase, freq, user_freq FROM
            (
                SELECT tabkeys, phrase, freq, user_freq FROM main.phrases
                WHERE tabkeys LIKE :tabkeys ESCAPE :escapechar {one_char_condition}
                UNION ALL
                SELECT tabkeys, phrase, freq, user_freq FROM user_db.phrases
                WHERE tabkeys LIKE :tabkeys ESCAPE :escapechar {one_char_condition}
            )
            )�one_char_conditionz�
            SELECT tabkeys, phrase, freq, user_freq FROM main.phrases
            WHERE tabkeys LIKE :tabkeys ESCAPE :escapechar {one_char_condition}
            u☺z!@#rP�_�%%)rs�
escapecharrzsqlstr=%s sqlargs=%sNrrzr{�rlrmrnzbest=%s)r�r#rXr7r�r�rr�r'rrrrr�r��update�maxr��values)rrsr�rnr�r�r^r[�bestr�rr��char�tabkeys_for_liker��unfiltered_resultsr�rr�phrase_frequenciesrs                     r�select_words�TabSqliteDb.select_wordss�����I��"�"�&�&�w�/����K����!9���&�&�.�	���*<��=�
����*<��=�
��
��D��2E�F�F�!�
��#��+�3�3��:�-�/���+�A�A�/�7�7��Z��^�L���+�A�A�/�7�7��Z��^�L���/�7�7�$�c� +���/�7�7�#�T� +�����$��.�I����?��L�L�/���g��G�!�W�W�_�_�V�=�F�F�H�����1���G�
�Q�
��G��(�G��G�,���*�B�B�6�!�9�M�N�N��N�N�6�*�-� ���F��!�9�f�Q�i�(�C��,�,�*0�"�3�'�"�)�)����F�1�I�'9�#�'>�q�'A�B��F�1�I�'9�#�'>�q�'A�B�D�D�,�+����#�#�!�)�0�0�2�%�$�'����?��L�L��D��J�/�'+���G�$��r%c���U(d/$SnUnU(aURUS5nU(aURUS5nUS-
nSU0nURRXW5R5nSn	US:XaSn	OUS:XaSn	/n
UHWup�n
U	(dU
R	X�U
S45 M#U	[
R"U5-(dMCU
R	X�U
S45 MY URUU
US	9$)
zP
Get Chinese characters matching the pinyin given by tabkeys
from the database.
z}
        SELECT pinyin, zi, freq FROM main.pinyin WHERE pinyin LIKE :tabkeys
        ORDER BY freq DESC, pinyin ASC;
        r�r�rsNrrrzr�)r�rrrr�rr�r�)rrsrnr�r�rr�r�rr�r�rQrBrus              r�#select_chinese_characters_by_pinyin�/TabSqliteDb.select_chinese_characters_by_pinyinns����I���#���/�7�7�$�c� +���/�7�7�#�T� +���D� ���.�/���'�'�/�/�&�2�;�;�=�����1���G�
�Q�
��G�>@��")��V���"�)�)�6�t�Q�*?�@��-�E�E�b�I�I�I�&�-�-�v�4��.C�D�#*��#�#�!�)�%�$�'�	'r%�prefixc
�.^�U(d/$SnUS-nSU0nURRX$5R5n0nUH6upxXv;aXx4Xg'MURUU[	X�US544/5 M8 UR5n	[S:�a[RS[U	55 Sn
[RRUR5RSS5nS	mUS
;aURm[!U	U4SjS9S
U
$)z;
Get Chinese phrase matching the prefix from the database.
z�
        SELECT phrase, freq FROM main.suggestion WHERE phrase LIKE :prefix
        ORDER BY length(phrase) DESC, freq DESC, phrase ASC;
        r�r�rz
candidates=%srpror!c��grrr5rss rrt�9TabSqliteDb.select_suggestion_candidate.<locals>.<lambda>�rvr%rwc	�>�[[US55*SUS-T"USS5T"USS5[USS5[USS54$)Nrr�rr�)r)r�s �rrtr��sc�����A�a�D�	�N�*��Q�q�T�'�-�a��d�1�g�6�-�a��d�1�g�6��a��d�1�g�,��a��d�1�g�,�	%r%r�N)rrrr�r�r�r�rr�r'rr�r�r9r�rjr�)
rr�r�prefix_for_liker�rr�rtrurmr�r�r�s
            @r�select_suggestion_candidate�'TabSqliteDb.select_suggestion_candidate�s1���
��I���!�4�-���_�-���'�'�/�/�&�2�;�;�=����#�L�F��/�.4�^�"�*�"�)�)���s�4�F�)C�A�)F�G�H�J�K�L�	$�(�.�.�0�
���?��L�L��$�z�*:�;�'*�$��g�g�&�&�t�}�}�5�=�=�e�R�H��6M���5�5�#'�.�.���j�	�
�7�6�
8�
	8r%c�0�SnURRU5 SnURRUS[45 SnURRUS5 URR	5 g! [
R
S5 g=f)zc
Add a description table to the user database

This adds the database version and  the create time
zBCREATE TABLE IF NOT EXISTS user_db.desc (name PRIMARY KEY, value);z2INSERT OR IGNORE INTO user_db.desc  VALUES (?, ?);rwzMINSERT OR IGNORE INTO user_db.desc  VALUES (?, DATETIME("now", "localtime"));)zcreate-timez+Unexpected error in generate_userdb_desc().N)rr�rr�r�rr)r�	sqlstrings  rr�� TabSqliteDb.generate_userdb_desc�s���
	L�/�
�
�G�G�!�!�)�,�L�I��G�G�O�O�I�	�3C�'D�E�>�
�
�G�G�O�O�I�'8�9��G�G�N�N���	L����J�K�s�A9A<�<B�db_filec��US:Xag[R"U5(d8[R"U5nUR	S5 UR5 gg)z�
Initialize the user database unless it is an in-memory database

:param db_file: Full path of the database file.
:type db_file: String
rpNax
                PRAGMA encoding = "UTF-8";
                PRAGMA case_sensitive_like = true;
                PRAGMA page_size = 4096;
                PRAGMA cache_size = 20000;
                PRAGMA temp_store = MEMORY;
                PRAGMA journal_mode = WAL;
                PRAGMA journal_size_limit = 1000000;
                PRAGMA synchronous = NORMAL;
            )r�r�r0r�r�r�)rr�rs   rr��TabSqliteDb.init_user_db�sO���j� ���{�{�7�#�#�����)�B����	�	
�
�I�I�K�$r%c��[R"U5(dg[R"U5n0nUR	S5R5H
nUSX4S'M UR
5 U$! g=f)z�
Get the description table from the database

:param db_file: Full path of the database file.
:type db_file: String
:rtype: Dictionary
NzSELECT * FROM desc;rr)r�r�r0r�rr�close)rr�rr��rows     rr��TabSqliteDb.get_database_desc�ss���{�{�7�#�#��	�����)�B��D��z�z�"7�8�A�A�C��"�1�v���V��D��H�H�J��K��	��s�AA8�8A<c��[R"U5(dg[R"U5nUR	S5R5nSR
USSR55n[R"SU5nU(a+URS5RS5n[U5$g! g=f)a�
Get the number of columns in the 'phrases' table in
the database in db_file.

Determines the number of columns by parsing this:

sqlite> select sql from sqlite_master where name='phrases';
CREATE TABLE phrases
        (id INTEGER PRIMARY KEY, tabkeys TEXT, phrase TEXT,
        freq INTEGER, user_freq INTEGER)
sqlite>

This result could be on a single line, as above, or on multiple
lines.

:param db_file: Full path of the database file.
:rtype: Integer
rz3select sql from sqlite_master where name='phrases';� z
.*\((.*)\)rr�)
r�r�r0r�rrr��
splitlinesrrrr�r�)rr�r�tp_res�stringr �tps       rr��1TabSqliteDb.get_number_of_columns_of_phrase_tables���&�{�{�7�#�#��	�����)�B��Z�Z�E���h�j�
�
�X�X�f�Q�i��l�5�5�7�8�F��(�(�=�&�1�C���Y�Y�q�\�'�'��,���2�w����	��s�B"C�CrBc���U(dgSnURRUSU05R5nSnU(aUSSn[S:�a[RSU5 U$)zGet goucima of given characterr!z0SELECT goucima FROM main.goucima WHERE zi = :zi;rBrrz
goucima=%s)rrrr�rr�)rrBrrrCs     r�get_goucima�TabSqliteDb.get_goucima0s]����C���'�'�/�/�&�4��*�5�>�>�@������a�j��m�G���?��L�L��w�/��r%c��[S:�a [RSXR5 U(dg[	U5S:XaURU5$UR(dg[	U5UR;aUR[	U5nO|[
URS[5(a9[	U5URS:�aURURSnO![RSXR5 g[
U[5(d:[	U5UR:�a![RSX R5 gSn[
U[5(agUH>upEUS:�aUS-nUS:�aUS-nURX5UnU(d gX6-
nM@ [S:�a[RSU5 U$)	ujParse phrase to get its table code

Example:

Let’s assume we use wubi-jidian86. The rules in the source of
that table are:

  RULES = ce2:p11+p12+p21+p22;ce3:p11+p21+p31+p32;ca4:p11+p21+p31+p-11

“ce2” is a rule for phrases of length 2, “ce3” is a rule
for phrases of length 3, “ca4” is a rule for phrases of
length 4 *and* for all phrases with a length greater then
4. “pnm” in such a rule means to use the n-th character of
the phrase and take the m-th character of the table code of
that character. I.e. “p-11” is the first character of the
table code of the last character in the phrase.

Let’s assume the phrase is “天下大事”. The goucima (構詞碼
= “word formation keys”) for these 4 characters when
using the wubi-jidian86 table are:

    character goucima
    天        gdi
    下        ghi
    大        dddd
    事        gkvh

(If no special goucima are defined by the user, the longest
encoding for a single character in a table is the goucima for
that character).

The length of the phrase “天下大事” is 4 characters,
therefore the rule ca4:p11+p21+p31+p-11 applies, i.e. the
table code for “天下大事” is calculated by using the first,
second, third and last character of the phrase and taking the
first character of the goucima for each of these. Therefore,
the table code for “天下大事” is “ggdg”.

rzphrase=%s rules%sr!rz2No rule for this phrase length. phrase=%s rules=%sz6Rule exceeds maximum key length. rule=%s self._mlen=%srz
tabkeys=%s)	r�rr�rcr�r��
isinstancer~r�)rrtrrsrB�ma�tabkeys       r�parse_phrase�TabSqliteDb.parse_phrase=s���P��?��L�L�,�f�j�j�A����v�;�!���#�#�F�+�+��z�z���v�;�$�*�*�$��:�:�c�&�k�*�D�����G�,�c�2�2��f�+��
�
�7� 3�3��:�:�d�j�j��1�2�D��L�L�D��
�
�
$���$��$�$��T��T�Z�Z�)?��L�L�(�)-�z�z�
;�����d�C� � ���H�R��A�v��a����A�v��a����%�%�f�j�1�"�5�F�����G����?��L�L��w�/��r%c��[S:�a[RSX5 U(aU(dgSnUS-US.nURR	X45R5n[S:�a[RSXU5 [
U5$)uv
Checks whether “phrase” can be matched in the system database
with a key sequence *starting* with “tabkeys”.
r�tabkeys=%s phrase=%sFzf
        SELECT * FROM main.phrases
        WHERE tabkeys LIKE :tabkeys AND phrase = :phrase;
        r�r<ztabkeys=%s phrase=%s results=%s)r�rr�rrr�bool)rrsrtrr�rs      r�is_in_system_database�!TabSqliteDb.is_in_system_database�s{����?��L�L�/��A��f����&�d�l�f�=���'�'�/�/�&�2�;�;�=����?��L�L�1���
*��G�}�r%c�0�[S:�a[RSX5 U(aU(dgSnXS.nURR	X45R5n[S:�a[RSU5 U(a[
USS5$g)u�
Return how often a conversion result “phrase” for the typed keys
“tabkeys” has been happened by checking the user database.

:param tabkeys: The keys typed
:param phrase: A conversion result for these tabkeys
rr�rz�
        SELECT sum(user_freq) FROM user_db.phrases
        WHERE tabkeys = :tabkeys AND phrase = :phrase GROUP BY tabkeys, phrase;
        r<z	result=%s)r�rr�rrrr~)rrsrtrr�rs      r�user_frequency�TabSqliteDb.user_frequency�s|����?��L�L�/��A��f����&�8��������1�:�:�<����?��L�L��f�-���v�a�y��|�$�$�r%c�&�[S:�a[RSX5 U(aU(dgUR(aU[;agU(dxUR
(aUR(dgUR
U5nU(dgURXS9(agURXS9S:�agURXSSSS9 gURXS9(a<URXS9nUS:�aURXUS-S	9 gURXSSSS9 gUR
(aUR(dgUR
U5nU(dgURXS9nUS:�aURXUS-S	9 gURXSSSS9 g)
z�Adjust user_freq in user database if necessary.

Also, if the phrase is not in the system database, and it is a
Chinese table, and defining user phrases is allowed, add it as
a user defined phrase to the user database if it is not yet
there.
rztabkey=%s phrase=%sNr<rr�r:)rsrtrurvr�)rsrtrv)r�rr�r��CHINESE_NOCHECK_CHARSrXr�r�r�r>r�)rrsrtr[rvs     r�check_phrase�TabSqliteDb.check_phrase�s�����?��L�L�.��@��f������*?� ?����.�.�d�6F�6F���'�'��/�G����)�)�'�)�I���"�"�7�"�B�Q�F���O�O��R�1�"�
�
$��)�)�'�)�I� �/�/��/�O�	��q�=��&�&� '�)�A�+�'�O��O�O� '�Q�!�!*�$�,��2�2�$�:J�:J���+�+�F�3���� �/�/��/�O�	��q�=��&�&� '�)�A�+�'�O��O�O� '�R�1�!*�$�,r%c��SnSU0nURRX#5R5nUVs/sHoUSPM	 nnU$s snf)uS
Return the list of possible tabkeys for a phrase.

For example, if “phrase” is “你” and the table is wubi-jidian.86.txt,
the result will be ['wq', 'wqi', 'wqiy'] because that table
contains the following 3 lines matching that phrase exactly:

wq      你       597727619
wqi     你       1490000000
wqiy    你       1490000000
zo
        SELECT tabkeys FROM main.phrases WHERE phrase = :phrase
        ORDER by length(tabkeys) ASC;
        rtr)rrr)rrtrr�rr)�list_of_possible_tabkeyss       r�find_zi_code�TabSqliteDb.find_zi_code�sR�����V�$���'�'�/�/�&�2�;�;�=��29�#:�'�Q�a�D�'� �#:�'�'��$;s�Ac�0�[RSXX45 U(dgU(aSRUS9nOSRUS9nXS.nURR	XV5 U(aURR5 UR
U5 g)z$Remove phrase from database
        z5Removing tabkeys=%s, phrase=%s, database=%s commit=%sNzs
            DELETE FROM {database}.phrases
            WHERE tabkeys = :tabkeys AND phrase = :phrase;
            r6z\
            DELETE FROM {database}.phrases
            WHERE phrase = :phrase;
            r<)r�infor7rrr�r�)rrsrtr�r��
delete_sqlstr�delete_sqlargss       r�
remove_phrase�TabSqliteDb.remove_phrases���	���K��X�	7���������)�
�
�����)�
�&-�?�������
�6���G�G�N�N���%�%�g�.r%c�:�[RS5 URRS5 URR	5 URRS5 UR5 g![a [RS5 gf=f)z^
Remove all phrases from the user database, i.e. delete all the
data learned from user input.
z,Removing all phrases from the user database.zDELETE FROM user_db.phrases;r}z4Unexpected error removing all phrases from database.N)rr�rrr�r�rrr(s r�remove_all_phrases_from_user_db�+TabSqliteDb.remove_all_phrases_from_user_db/sv��
	���B�C�	H��G�G�O�O�:�;��G�G�N�N���G�G�O�O�4�5��$�$�&���	H����F�
H�	H�s�A A8�8B�B�
database_fileryc�x�[RS5 [R"U5nUR	S5 US:�a^UR	S5R5nUR
5 [USS9n[RS[U55 USS$/nUR	S	5R5nUH�nS
nSUS0nURR	Xx5R5n	U	(a#URU	SSUSSUS
45 M_URUS5n
U
(dM|URX�SSUS
45 M� UR
5 [USS9n[RS[U55 USS$! [RS5 /s$=f)z"extract user phrases from databasezBTrying to recover the phrases from the old, incompatible database.r}r
z�
                    SELECT tabkeys, phrase, freq, sum(user_freq) FROM phrases
                    GROUP BY tabkeys, phrase, freq;
                    c�&�USUSUSUS4$�Nrrrzr{r5rss rrt�2TabSqliteDb.extract_user_phrases.<locals>.<lambda>Ss��A�a�D�!�A�$��!��a��d�+Cr%r�z3Recovered phrases from the old database: phrases=%sNz;SELECT phrase, sum(user_freq) FROM phrases GROUP BY phrase;z�
                SELECT tabkeys FROM main.phrases WHERE phrase = :phrase
                ORDER BY length(tabkeys) DESC;
                rtrrr�c�&�USUSUSUS4$r�r5rss rrtr�ys���!��a��d�A�a�D�!�A�$�'?r%z8Recovered phrases from the very old database: phrases=%sz*Unexpected error in extract_user_phrases())
rr�r0r�rrr�r�r'rr�r�r)rr�ryrr3rrrr��tabkeys_resultsrss           rr�� TabSqliteDb.extract_user_phrases>s���	���
%�	&�9	�����/�B��J�J�/�0�#�v�-��*�*���
�(�*�����
� ��!C�E�����I���M�#��q�z�!�
�G��j�j�2���h�j�
�"����$�V�A�Y�/��"&�'�'�/�/��#%�%-�X�Z� �"��N�N�(��+�A�.��q�	�1�f�Q�i�H�J�#�/�/��q�	�:�G��w� ������B��q�	�'J�K�+"�,
�H�H�J���?�A�G��L�L��"�7�m�
-��1�:���	����I�J��I�s�B
F�"BF�AF�F9)r�r�r�r�r�r�r�r�rr9r�r�r�rcr�rX)r!r!FF)r!r!rr:T)rN)r!)r
)r!r!rrr
T)T)r!r5r�)r!Fr�r!r!FF)r!r�r!r!)r!r!)r!r!F)r!r!r:T)r!rx)<r+r,r-r.r/r3r�rr~r�r�r�r�r�r�r�r�r�rrr�rrrrrrr�r�r�r1r9r>rDrSrWrZr_r��bytesrjr�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r4r5r%rr7r7xs���8��$)�#�X$��X$��X$�"�	X$�
�X$�
)-�X$�x���%��
M��M��M��	M�
�M��
M�%)�
M�:2�\�6��6�T�6�F�,J� �D������#��$%��%�����c��d��6&���s�C�x�� 9�&�d�&�8.�4��c�3�h���s�D��s�C�x��<Q�7Q�1R� R�S�.�`"�d�3�i�"�H6��6��C��#�%2��e�C��c�3�$6�7�8�%2��%2�(,�%2�R����"��6A��6A��6A��	6A�
�6A��
6A��6A�%)�6A�pC�H�U�3��8�_�$=�C�$�C�*#���e�C��c�M�2�3����(,��@#��!�%��S��/�2����(,��.�8+�c�+�d�+�
-��
-�d�
-�d�
-������"$�>@� !�	?8��?8�!��s�C��c�'9�!:�;�?8��	?8�'/�u�S�#�s�C�5G�/H�&I�	?8�F�!� !�(*�')�"'�#(�e��e��e��	e�
#&�e�"%�
e� �e�!�e�.6�e�C��c�3�<N�6O�-P�e�R� !�(*�')�+'��+'��+'�#&�	+'�
"%�+'�
/7�u�S�#�s�C�=O�7P�.Q�+'�\!#�-8��-8�'+�E�#�s�(�O�'<�-8�^L�*�C��D��0����$�s�C�x�.�1I��(#�S�#�S�#�J�c��c��R�3�R�3�R�j46����-0��:>��,�c����S��4��#(�	=,��=,��=,�!�	=,�.2�	=,�~(�3�(�4��9�(�.��%��/��/��/��	/�
�/�
%)�/�8
H�""$�(-�B��B�#&�B�
�e�C��c�3�&�'�	(�	B�Br%r7)r/�typingrrrrrrr	r�os.pathr�r�r0rBr�r�loggingr�rr��	getLoggerrr~r�r�r�rr7r5r%r�<module>r�s���,��������	��
����	�����	�	�	�<�	(���!�f����.��@$H�$H�LH�Hr%

Filemanager

Name Type Size Permission Actions
chinese_variants.cpython-313.pyc File 434.02 KB 0644
factory.cpython-313.pyc File 5.61 KB 0644
ibus_table_location.cpython-313.pyc File 4.87 KB 0644
it_active_window.cpython-313.pyc File 13.01 KB 0644
it_sound.cpython-313.pyc File 23.38 KB 0644
it_util.cpython-313.pyc File 45.11 KB 0644
main.cpython-313.pyc File 18.03 KB 0644
tabcreatedb.cpython-313.pyc File 23.86 KB 0644
table.cpython-313.pyc File 188.3 KB 0644
tabsqlitedb.cpython-313.pyc File 68.79 KB 0644
version.cpython-313.pyc File 423 B 0644
Filemanager