ó
ù`]c           @   sl   d  Z  e d d „ Z e d k rh d d l Z d d l m Z d d d	 d
 g Z e e j d ƒ e ƒ n  d S(   s.   
A utility for displaying lexical dispersion.
s   Lexical Dispersion Plotc   
      C   s‘  y d d l  m } Wn t k
 r3 t d ƒ ‚ n Xt |  ƒ }  | j ƒ  | rƒ t t t j | ƒ ƒ } t t t j |  ƒ ƒ } n | } |  } g  t	 t
 | ƒ ƒ D]? } t	 t
 | ƒ ƒ D]& } | | | | k r¸ | | f ^ q¸ q¢ }	 |	 rt t |	 Œ  ƒ \ } } n
 d } } | j | | d d d ƒ| j t t	 t
 | ƒ ƒ ƒ | d d ƒ| j d t
 | ƒ ƒ | j | ƒ | j d	 ƒ | j ƒ  d
 S(   s$  
    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
    iÿÿÿÿ(   t   pylabsP   The plot function requires matplotlib to be installed.See http://matplotlib.org/s   b|t   scalexgš™™™™™¹?t   colort   bs   Word OffsetN(    (   t
   matplotlibR    t   ImportErrort
   ValueErrort   listt   reverset   mapt   strt   lowert   ranget   lent   zipt   plott   ytickst   ylimt   titlet   xlabelt   show(
   t   textt   wordst   ignore_caseR   R    t   words_to_compt   text_to_compt   xt   yt   points(    (    s3   lib/python2.7/site-packages/nltk/draw/dispersion.pyt   dispersion_plot   s2    
)
(t   __main__iÿÿÿÿN(   t	   gutenbergt   Elinort   Mariannet   Edwardt
   Willoughbys   austen-sense.txt(	   t   __doc__t   FalseR   t   __name__t   nltk.compatt   nltkt   nltk.corpusR   R   (    (    (    s3   lib/python2.7/site-packages/nltk/draw/dispersion.pyt   <module>
   s   0