3
d                 @   sB   d Z dddZedkr>ddlmZ dd	d
dgZeejde dS )z.
A utility for displaying lexical dispersion.
FLexical Dispersion Plotc       	         s  yddl m} W n, tk
r< } ztd|W Y dd}~X nX t| } |j  |rttttj|tttj|  n||   fddt	t
 D }|rtt| \}}nf  }}|j||ddd	 |jtt	t
||d
d |jdt
| |j| |jd |j  dS )a$  
    Generate a lexical dispersion plot.

    :param text: The source text
    :type text: list(str) or enum(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
        )pylabzQThe plot function requires matplotlib to be installed.See https://matplotlib.org/Nc                s6   g | ].}t tD ]} | | kr||fqqS  )rangelen).0xy)text_to_compwords_to_compr   4/tmp/pip-build-v9q4h5k9/nltk/nltk/draw/dispersion.py
<listcomp>,   s   z#dispersion_plot.<locals>.<listcomp>zb|g?)Zscalexb)color   zWord Offset)Z
matplotlibr   ImportError
ValueErrorlistreversemapstrlowerr   r   zipZplotZyticksZylimtitleZxlabelshow)	textwordsZignore_caser   r   eZpointsr   r	   r   )r
   r   r   dispersion_plot   s0    

r   __main__r   )	gutenbergZElinorZMarianneZEdwardZ
Willoughbyzausten-sense.txtN)Fr   )__doc__r   __name__Znltk.corpusr!   r   r   r   r   r   <module>
   s
   
0