a
     ˜ëjg  ã                   @   sR   d Z ddd„ZedkrNddlmZ ddlmZ g d	¢Zee d
¡eƒ e 	¡  dS )z.
A utility for displaying lexical dispersion.
FúLexical Dispersion Plotc              
      s>  zddl m} W n. ty> } ztdƒ|‚W Y d}~n
d}~0 0 ‡ fdd„tt|ƒƒD ƒ}g g  }}t| ƒD ]>\}	}
ˆ r€|
 ¡ n|
}
| |
¡}|durl| |	¡ | |¡ ql|ddd… }| ¡ \}}| 	||d¡ dt
| ƒd  |j_|j_|jd	d
� |jttt
|ƒƒƒ|dd� | dt
|ƒ¡ | |¡ | d¡ |S )a†  
    Generate a lexical dispersion plot.

    :param text: The source text
    :type text: list(str) or iter(str)
    :param words: The target words
    :type words: list of str
    :param ignore_case: flag to set if case should be ignored when searching text
    :type ignore_case: bool
    :return: a matplotlib Axes object that may still be modified before plotting
    :rtype: Axes
    é    NzRThe plot function requires matplotlib to be installed. See https://matplotlib.org/c                    s"   i | ]\}}ˆ r|  ¡ n||“qS © )Úcasefold)Ú.0ÚyÚword©Úignore_caser   úS/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/nltk/draw/dispersion.pyÚ
<dictcomp>#   s   ÿz#dispersion_plot.<locals>.<dictcomp>éÿÿÿÿú|é   Úx)ZaxisZC0)ÚcolorzWord Offset)Úmatplotlib.pyplotÚpyplotÚImportErrorÚ	enumerateÚreversedr   ÚgetÚappendZsubplotsZplotÚlenZdataLimZx0Úx1Z	autoscaleZ
set_yticksÚlistÚrangeZset_ylimÚ	set_titleZ
set_xlabel)ÚtextÚwordsr	   ÚtitleÚpltÚeZword2yÚxsZysr   Útokenr   Ú_Úaxr   r   r
   Údispersion_plot   s8    ÿý

þ




r&   Ú__main__r   N)Ú	gutenberg)ZElinorZMarianneZEdwardZ
Willoughbyzausten-sense.txt)Fr   )
Ú__doc__r&   Ú__name__r   r   r    Znltk.corpusr(   r   Úshowr   r   r   r
   Ú<module>   s   
/