Mini Shell

Direktori : /usr/lib/python3.6/site-packages/enchant/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/enchant/__pycache__/pypwl.cpython-36.opt-1.pyc

3

��]B$�@s@dZddlmZddlZddlZGdd�d�ZGdd�d�ZdS)aC

pypwl:  pure-python personal word list in the style of Enchant
==============================================================

This module provides a pure-python version of the personal word list
functionality found in the spellchecking package Enchant.  While the
same effect can be achieved (with better performance) using the python
bindings for Enchant, it requires a C extension.

This pure-python implementation uses the same algorithm but without any
external dependencies or C code (in fact, it was the author's original
prototype for the C version found in Enchant).

�)�
generatorsNc@sVeZdZdZffdd�Zdd�Zdd�Zdd	d
�Zdge_dd
�Z	dd�Z
dd�ZdS)�Triez�Class implementing a trie-based dictionary of words.

    A Trie is a recursive data structure storing words by their prefix.
    "Fuzzy matching" can be done by allowing a certain number of missteps
    when traversing the Trie.
    cCs(d|_i|_x|D]}|j|�qWdS)NF)�_eos�_keys�insert)�selfZwords�w�r	�/usr/lib/python3.6/pypwl.py�__init__;s
z
Trie.__init__cCs^|dkrd|_nJ|d}y||}Wn"tk
rFt�}|||<YnX|j|dd��dS)N�Tr�)r�KeyErrorrr)r�word�key�subtrier	r	r
rAszTrie.insertcCsP|dkrd|_n<|d}y||}Wntk
r8YnX|j|dd��dS)NrFrr
)rr�remove)rrrrr	r	r
rMszTrie.removerc	$Cs�g}|dkr|S|dkr0|dkr0|jr0|jd�yP||d}|j|dd�|�}x*|D]"}|d|}||krX|j|�qXWWnttfk
r�YnXy<|j|dd�|d�}x|D]}||kr�|j|�q�WWntfk
r�YnXyTxN|jD]D}||j||d�}x*|D]"}||}||k�r|j|��qWq�WWnttfk
�r\YnXy^xX|jD]N}||j|dd�|d�}x*|D]"}||}||k�r�|j|��q�W�qhWWnttfk
�r�YnX|S)z�Search for the given word, possibly making errors.
        
        This method searches the trie for the given <word>, making
        precisely <nerrs> errors.  It returns a list of words found.
        rrr
N)r�append�search�
IndexErrorrr)	rr�nerrs�resrZsubresr�w2�kr	r	r
rYsR






zTrie.searchrcCs
|j|S)N)r)rrr	r	r
�__getitem__�szTrie.__getitem__cCs||j|<dS)N)r)rr�valr	r	r
�__setitem__�szTrie.__setitem__ccs>|jrdVx,|jD]"}x|j|D]}||Vq$WqWdS)Nr)rr)rrrr	r	r
�__iter__�s
z
Trie.__iter__N)r)�__name__�
__module__�__qualname__�__doc__rrrr�_DOC_ERRORSrrrr	r	r	r
r3s
6rc@s|eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zddge_dd�Z
dd�Zdd�Zdd�ZdS)�PyPWLz�Pure-python implementation of Personal Word List dictionary.
    This class emulates the PWL objects provided by PyEnchant, but
    implemented purely in python.
    NcCsnd|_t�|_|dk	r^tjj|�|_|j|_t|�}x|D]}|j	�}|j
|�q:W|j�nd|_d|_dS)aaPyPWL constructor.
        This method takes as its only argument the name of a file
        containing the personal word list, one word per line.  Entries
        will be read from this file, and new entries will be written to
        it automatically.

        If <pwl> is not specified or None, the list is maintained in
        memory only.
        Nr#)Zproviderr�_words�os�path�abspath�pwl�tag�file�strip�add_to_session�close)rr(�pwlF�lnrr	r	r
r�s


zPyPWL.__init__cCs|jj|�}t|�S)z�Check spelling of a word.
        
        This method takes a word in the dictionary language and returns
        True if it is correctly spelled, and false otherwise.
        )r$r�bool)rrrr	r	r
�check�szPyPWL.checkcCsrd}d}d}|jj||�}xJt|�|krd||krd|d7}x(|jj||�D]}||krH|j|�qHWqW|d|�S)z�Suggest possible spellings for a word.
        
        This method tries to guess the correct spelling for a given
        word, returning the possibilities in a list.
        �
�rr
N)r$r�lenr)rr�limitZmaxdepth�depthrrr	r	r
�suggest�sz
PyPWL.suggestcCs@|jdk	r2t|jd�}|jd|j�f�|j�|j|�dS)znAdd a word to the user's personal dictionary.
        For a PWL, this means appending it to the file.
        N�az%s
)r(r*�writer+r-r,)rrr.r	r	r
�add�s

z	PyPWL.addcCstjdtdd�|j|�dS)znAdd a word to the user's personal dictionary.
        For a PWL, this means appending it to the file.
        z4PyPWL.add_to_pwl is deprecated, please use PyPWL.add�)�category�
stacklevelN)�warnings�warn�DeprecationWarningr:)rrr	r	r
�
add_to_pwl�s
zPyPWL.add_to_pwlcCsR|jj|�|jdk	rNt|jd�}x"|jD]}|jd|j�f�q*W|j�dS)z/Add a word to the user's personal exclude list.NZwtz%s
)r$rr(r*r9r+r-)rrr.rr	r	r
r�s
zPyPWL.removecCs|jj|�dS)zAdd a word to the session list.N)r$r)rrr	r	r
r,�szPyPWL.add_to_sessioncCsdS)atStore a replacement spelling for a miss-spelled word.
        
        This method makes a suggestion to the spellchecking engine that the 
        miss-spelled word <mis> is in fact correctly spelled as <cor>.  Such
        a suggestion will typically mean that <cor> appears early in the
        list of suggested spellings offered for later instances of <mis>.
        Nr	)r�misZcorr	r	r
�store_replacement�s	zPyPWL.store_replacementrBcCs
|j|�S)z2Check whether a word is in the personal word list.)r1)rrr	r	r
�is_addedszPyPWL.is_addedcCsdS)z5Check whether a word is in the personal exclude list.Fr	)rrr	r	r
�
is_removed
szPyPWL.is_removedcCsdS)Nr	)r�msgr	r	r
�_check_thisszPyPWL._check_thiscCsdS)Nr	)rr	r	r
�_freeszPyPWL._free)N)rrr r!rr1r7r:rArr,rCr"rDrErGrHr	r	r	r
r#�s
	


r#)r!Z
__future__rr%r>rr#r	r	r	r
�<module>,s
l