B
    P?[                 @   sJ   d Z dddZedkrFddlZddlmZ d	d
ddgZee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,   tdY nX t| } |  |rdtttj|tttj|  n||   fddt	t
 D }|rtt| \}}nd }}|j||ddd	 |jtt	t
||d
d |dt
| || |d |  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
        )pylabzPThe plot function requires matplotlib to be installed.See http://matplotlib.org/c                s6   g | ].}t tD ]} | | kr||fqqS  )rangelen).0xy)text_to_compwords_to_compr   3lib/python3.7/site-packages/nltk/draw/dispersion.py
<listcomp>,   s   z#dispersion_plot.<locals>.<listcomp>r   zb|g?)Zscalexb)ZcolorzWord OffsetN)Z
matplotlibr   ImportError
ValueErrorlistreversemapstrlowerr   r   zipZplotZyticksZylimtitleZxlabelZshow)textwordsZignore_caser   r   Zpointsr   r	   r   )r
   r   r   dispersion_plot   s.    

r   __main__r   N)	gutenbergZElinorZMarianneZEdwardZ
Willoughbyzausten-sense.txt)Fr   )__doc__r   __name__Znltk.compatZnltkZnltk.corpusr   r   r   r   r   r   <module>
   s   
0