o
    rZhg                     @   sV   d Z dddZedkr)ddlmZ ddlmZ g d	Zeed
e e	  dS dS )z.
A utility for displaying lexical dispersion.
FLexical Dispersion Plotc              
      s2  zddl m} W n ty } ztd|d}~ww  fddtt|D }g g }}t| D ]\}	}
 r:|
 n|
}
||
}|durO||	 || q0|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   C/var/www/auris/lib/python3.10/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word2yZxsZysr   tokenr   _axr   r   r
   dispersion_plot   s>   







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   
/