łň
4ŇÇIc           @   s\   d  Z  d   Z e d j o< d d k l Z d d d d g Z e e i d	  e  n d
 S(   s.   
A utility for displaying lexical dispersion.
c         C   s8  y d d k  } Wn t j
 o t d   n Xt |   }  | i   g  } t t |    D]E } t t |   D], } |  | | | j o | | | f qu qu q_ ~ } t |   \ } } | i | | d d d | i	 t t |   | d d | i
 d t |   | i d	  | i d
  | i   d S(   sÂ   
    Generate a lexical dispersion plot.

    @param text: The source text
    @type text: C{list} or C{enum} of C{str}
    @param words: The target words
    @type words: C{list} of C{str}
    i˙˙˙˙NsX   The plot function requires the matplotlib package.See http://matplotlib.sourceforge.net/s   b|t   scalexgš?t   colort   bs   Lexical Dispersion Plots   Word Offset(   t   pylabt   ImportErrort
   ValueErrort   listt   reverset   ranget   lent   zipt   plott   ytickst   ylimt   titlet   xlabelt   show(   t   textt   wordsR   t   _[1]t   xt   yt   points(    (    s*   /p/zhu/06/nlp/nltk/nltk/draw/dispersion.pyt   dispersion_plot   s     

2"t   __main__i˙˙˙˙(   t	   gutenbergt   Elinort   Mariannet   Edwardt
   Willoughbys   austen-sense.txtN(   t   __doc__R   t   __name__t   nltk.corpusR   R   (    (    (    s*   /p/zhu/06/nlp/nltk/nltk/draw/dispersion.pys   <module>
   s
   	