3
­d£  ã               @   s   d dl mZ G dd„ dƒZdS )é    )Údefaultdictc               @   sF   e Zd ZdZddd„Zdd„ Zddd	„Zddd„Zdd„ Zdd„ Z	dS )Ú
MinimalSeta¬  
    Find contexts where more than one possible target value can
    appear.  E.g. if targets are word-initial letters, and contexts
    are the remainders of words, then we would like to find cases like
    "fat" vs "cat", and "training" vs "draining".  If targets are
    parts-of-speech and contexts are words, then we would like to find
    cases like wind (noun) 'air in rapid motion', vs wind (verb)
    'coil, wrap'.
    Nc             C   sJ   t ƒ | _t ƒ | _tt ƒ| _i | _|rFx |D ]\}}}| j|||ƒ q*W dS )z¯
        Create a new minimal set.

        :param parameters: The (context, target, display) tuples for the item
        :type parameters: list(tuple(str, str, str))
        N)ÚsetÚ_targetsÚ	_contextsr   Ú_seenÚ	_displaysÚadd)ÚselfZ
parametersÚcontextÚtargetÚdisplay© r   ú4/tmp/pip-build-v9q4h5k9/nltk/nltk/misc/minimalset.pyÚ__init__   s    
zMinimalSet.__init__c             C   s:   | j | j|ƒ | jj|ƒ | jj|ƒ || j||f< dS )a€  
        Add a new item to the minimal set, having the specified
        context, target, and display form.

        :param context: The context in which the item of interest appears
        :type context: str
        :param target: The item of interest
        :type target: str
        :param display: The information to be reported for each item
        :type display: str
        N)r   r	   r   r   r   )r
   r   r   r   r   r   r   r	   &   s    zMinimalSet.addé   c                s   ‡ ‡fdd„ˆj D ƒS )zÆ
        Determine which contexts occurred with enough distinct targets.

        :param minimum: the minimum number of distinct target forms
        :type minimum: int
        :rtype: list
        c                s"   g | ]}t ˆj| ƒˆ kr|‘qS r   )Úlenr   )Ú.0Úc)Úminimumr
   r   r   ú
<listcomp>D   s    z'MinimalSet.contexts.<locals>.<listcomp>)r   )r
   r   r   )r   r
   r   Úcontexts<   s    zMinimalSet.contextsÚ c             C   s$   ||f| j kr| j ||f S |S d S )N)r   )r
   r   r   Údefaultr   r   r   r   F   s    zMinimalSet.displayc             C   s2   g }x(| j D ]}| j||ƒ}|r|j|ƒ qW |S )N)r   r   Úappend)r
   r   Úresultr   Úxr   r   r   Údisplay_allL   s    zMinimalSet.display_allc             C   s   | j S )N)r   )r
   r   r   r   ÚtargetsT   s    zMinimalSet.targets)N)r   )r   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r	   r   r   r   r   r   r   r   r   r      s   	



r   N)Úcollectionsr   r   r   r   r   r   Ú<module>   s   