
    -i                        d dl Z d dlZd dlZd dlZej                            ej                            e          d          Z	d dl
mZ  G d d          Zedk    rd dddd	d
dZ ede          Zg dZeD ]Z ed           e                    e          Z ee           eD ]]Z ee                    ed                              d                     e                    e          Z e ee                     ^dS dS )    Nzdata/collocations.sqlitec                   4    e Zd ZdZd
dZd Zd Zd ZddZd	S )collocationDictionaryz
        Arabic dictionary Class
        Used to allow abstract acces to lexicon of arabic language,
        can get indexed and hashed entries from the  basic lexicon
        add also, support to extract attributtes from entries
    unvocalizedc                    i | _         || _        || _        i | _        | j                                        D ]}| j        |         }|| j        |<   || _        	 t          j        t                    | _	        t          j
        | j	        _        | j	                                        | _        dS #  t          dt                     Y dS xY w)zn
        initialisation of dictionary from a data dictionary, create indexes to speed up the access.

        z(Fatal Error Can't find the database fileN)
dictionaryattribIndexkeyAttributeattribNumIndexkeys	tableNamesqliteconnectFILE_DB	dbConnectRowrow_factorycursorprint)selfr   r   r	   kvs         [/var/www/html/speakWrite/venv/lib/python3.11/site-packages/maskouk/collocationdictionary.py__init__zcollocationDictionary.__init__   s     $' !&&(( 	& 	&Aq!A#$D"" 	G#^G44DN)/DN&.//11DKKK	G<gFFFFFFs   AB, ,Cc                 J    | j         r| j                                          dS dS )zH
        Delete instance and close database connection
        
        N)r   close)r   s    r   __del__zcollocationDictionary.__del__:   s2    
 > 	$N  """""	$ 	$    c                     d| j         |fz  }	 | j                            |           | j        r1| j        D ])}i }| j        D ]}| j        |         }||         ||<   |c S n#  Y dS xY wdS )z Get dictionary entry by id from the dictionary
        @param id word identifier
        @type id: integer
        @param attribute the attribute name
        @type attribute: unicode
        @return: all attributes
        @rtype: dict
        select * FROM %s WHERE id=%dF)r   r   executer
   )r   idsqlrow	entryDictnumKeytextKeys          r   getEntryByIdz"collocationDictionary.getEntryByIdB   s     .t~b.AA
	K$$${ &; & &C I"&"5 9 9"&"5f"=-0[	'**$$$$	55us   AA! !A&c                    | j                             |          r| j         |         }ndS d| j        |fz  }	 | j                            |           i }| j        r| j        D ]}||         c S n#  t          d           Y dS xY wdS )a   Get attribute value by id from the dictionary
        @param id word identifier
        @type id: integer
        @param attribute the attribute name
        @type attribute: unicode
        @return: The attribute
        value
        @rtype: mix.
        Fr   z"error in request getattribut by id)r   has_keyr   r   r    r   )r   r!   	attributeattnumr"   r$   r#   s          r   getAttribByIdz#collocationDictionary.getAttribById_   s    $ ##I.. 	#I.FF5-t~b.AA	K$$$I{ ,; , ,C #F+++	677755us   5A/ /BFc                     g }|rd| j         d|d}nd| j         d|d}	 | j                            |           | j        r| j        D ]}|                    |           |S #  g cY S xY w)z
        look up for all word forms in the dictionary
        @param normalized the normalized word.
        @type text: unicode.
        @return: list of dictionary entries IDs.
        @rtype: list.
        zselect * FROM z WHERE first = ''z WHERE unvocalized = ')r   r   r    append)r   text
singlewordidListr"   r#   s         r   lookupzcollocationDictionary.lookup   s      	U 	U:>...$$$OCC	U AEtttTC	K$$${ ,; , ,Cc****M	IIIs   AA% %A+N)r   )F)	__name__
__module____qualname____doc__r   r   r'   r,   r3    r   r   r   r      sx         G G G G6$ $ $  :! ! !F     r   r   __main__               )r!   	vocalizedr   rulecategorynotecollocations)u   صلاة الفجرu   كرة القدمu   دولة قطرjjjjjjjjr?   utf8)resqlite3r   sysospathjoindirname__file__r   pyarabic.arabyarabyr   r4   Collocation_DICTIONARY_INDEXmydictwordlistwordr   r3   idlistr!   r,   encoder'   myentryreprr8   r   r   <module>rX      s   
			     



 				 ',,rwx002M
N
N      H H H H H H H HV z 		" "  ! 1MNNFNNNH ! !j}}T""f 	! 	!BE&&&r<88??GGHHH((,,GE$$w--    	!# ! !r   