³ò
3ÒÇIc           @   s–   d  Z  d d k Z d d k l Z l Z l Z d d k Td d k Td d k l	 Z	 d e
 f d „  ƒ  YZ d „  Z e d	 j o e ƒ  n d
 g Z d S(   se  
A graphical tool for exploring the shift-reduce parser.

The shift-reduce parser maintains a stack, which records the structure
of the portion of the text that has been parsed.  The stack is
initially empty.  Its contents are shown on the left side of the main
canvas.

On the right side of the main canvas is the remaining text.  This is
the portion of the text which has not yet been considered by the
parser.

The parser builds up a tree structure for the text using two
operations: 

  - "shift" moves the first token from the remaining text to the top
    of the stack.  In the demo, the top of the stack is its right-hand
    side.
  - "reduce" uses a grammar production to combine the rightmost stack
    elements into a single tree token.

You can control the parser's operation by using the "shift" and
"reduce" buttons; or you can use the "step" button to let the parser
automatically decide which operation to apply.  The parser uses the
following rules to decide which operation to apply:

  - Only shift if no reductions are available.
  - If multiple reductions are available, then apply the reduction
    whose CFG production is listed earliest in the grammar.

The "reduce" button applies the reduction whose CFG production is
listed earliest in the grammar.  There are two ways to manually choose
which reduction to apply:

  - Click on a CFG production from the list of available reductions,
    on the left side of the main window.  The reduction based on that
    production will be applied to the top of the stack.
  - Click on one of the stack elements.  A popup window will appear, 
    containing all available reductions.  Select one, and it will be
    applied to the top of the stack.

Note that reductions can only be applied to the top of the stack.

Keyboard Shortcuts::
      [Space]	 Perform the next shift or reduce operation
      [s]	 Perform a shift operation
      [r]	 Perform a reduction operation
      [Ctrl-z]	 Undo most recent operation
      [Delete]	 Reset the parser
      [g]	 Show/hide available production list
      [Ctrl-a]	 Toggle animations
      [h]	 Help
      [Ctrl-p]	 Print
      [q]	 Quit
iÿÿÿÿN(   t   parset   tokenizet   in_idle(   t   *(   t	   CFGEditort   ShiftReduceAppc           B   sO  e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d  „  Z" d! „  Z# d" „  Z$ d# „  Z% d$ „  Z& RS(%   sÅ  
    A graphical tool for exploring the shift-reduce parser.  The tool
    displays the parser's stack and the remaining text, and allows the
    user to control the parser's operation.  In particular, the user
    can shift tokens onto the stack, and can perform reductions on the
    top elements of the stack.  A "step" button simply steps through
    the parsing process, performing the operations that
    C{parse.ShiftReduceParser} would use.
    i    c         C   s$  | |  _  t i | | ƒ |  _ t ƒ  |  _ |  i i d ƒ d |  _ t |  i ƒ |  _	 |  i	 i
 d ƒ t |  i ƒ |  _ |  i i
 d ƒ |  i |  i ƒ |  i ƒ  |  i |  i ƒ |  i |  i ƒ |  i |  i ƒ |  i |  i ƒ |  i |  i ƒ t |  i d d ƒ|  _ |  i ƒ  d |  i d <d  S(   Ns   Shift Reduce Parser Applicationi    i
   i   t   tearofft    t   text(   t   _sentR    t   SteppingShiftReduceParsert   _parsert   Tkt   _topt   titlet   _animating_lockt   IntVart   _animatet   sett   _show_grammart   _init_fontst   _init_bindingst   _init_menubart   _init_buttonst   _init_feedbackt   _init_grammart   _init_canvast   Menut   _canvast   _reduce_menut   resett
   _lastoper1(   t   selft   grammart   sentt   trace(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyt   __init__a   s&    		

c         C   s¬   t  i d t ƒ  d ƒ |  _ | i d |  i ƒ t | ƒ |  _ |  i i |  i i d ƒ ƒ t  i d d d d d |  i i	 ƒ  ƒ |  _
 t  i d d d |  i i	 ƒ  ƒ |  _ d  S(   Nt   fonts   *Fontt   sizet   familyt	   helveticat   weightt   bold(   t   tkFontt   Fontt   Buttont   _sysfontt
   option_addR   t   _sizeR   t   cgett   gett	   _boldfontt   _font(   R    t   root(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   ‹   s    c         C   sÒ  t  | ƒ |  _ } |  i i d d d d d d ƒ t |  i d |  i d d	 ƒ|  _ |  i i ƒ  t |  i d
 d d d d d d d d |  i d d d d ƒ|  _ |  i i d d d d d d ƒ t	 |  i
 i ƒ  i ƒ  ƒ |  _ x( |  i D] } |  i i d d | ƒ qæ W|  i i d t t |  i ƒ d ƒ ƒ t |  i d d ƒ} |  i i d | i ƒ | i d  |  i i ƒ | i d d d d! ƒ |  i i d" |  i ƒ d# |  _ |  i i d$ |  i ƒ |  i i d% |  i ƒ d  S(&   Nt   fillt   botht   sidet   leftt   padxi   R%   R   s   Available Reductionst
   selectmodet   singlet   relieft   groovet
   backgroundt   whitet
   foregrounds   #909090t   selectforegrounds   #004040t   selectbackgrounds   #c0f0c0t   rightt   expandi   t   ends    %st   heighti   t   orientt   verticalt   yscrollcommandt   commandt   ys   <<ListboxSelect>>iÿÿÿÿs   <Motion>s   <Leave>(   t   Framet
   _prodframet   packt   LabelR3   t   _prodlist_labelt   ListboxR4   t	   _prodlistt   listR   R!   t   productionst   _productionst   insertt   configt   mint   lent	   ScrollbarR   t   yviewt   bindt   _prodlist_selectt   _hovert   _highlight_hovert   _clear_hover(   R    t   parentt	   listframet
   productiont
   listscroll(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   ™   s6    		
 %		c         C   s<  |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d	 |  i ƒ |  i  i d
 |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i ƒ |  i  i d |  i	 ƒ |  i  i d |  i	 ƒ |  i  i d |  i
 ƒ |  i  i d |  i ƒ |  i  i d |  i d „ ƒ |  i  i d |  i d „ ƒ |  i  i d |  i d „ ƒ d  S(   Ns   <Control-q>s   <Control-x>s   <Alt-q>s   <Alt-x>s   <space>s   <s>s   <Alt-s>s   <Control-s>s   <r>s   <Alt-r>s   <Control-r>s   <Delete>s   <u>s   <Alt-u>s   <Control-u>s   <Control-z>s   <BackSpace>s   <Control-p>s   <Control-h>s   <F1>s   <Control-g>s   <Control-t>t   -c         S   s   | i  d  ƒ S(   i   (   R   (   t   et   a(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyt   <lambda>Ý   s    t   =c         S   s   | i  d  ƒ S(   i
   (   R   (   Rg   Rh   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRi   Þ   s    t   +c         S   s   | i  d  ƒ S(   i   (   R   (   Rg   Rh   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRi   ß   s    (   R   R]   t   destroyt   stept   shiftt   reduceR   t   undot
   postscriptt   helpt   edit_grammart   edit_sentenceR   (   R    (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   ¿   s2    c         C   s  t  | ƒ |  _ } | i d d d d ƒ t | d d d d d	 d
 d |  i ƒi d d ƒ t | d d d d d d d	 d
 d |  i ƒi d d ƒ t | d d d d d d d	 d
 d |  i ƒi d d ƒ t | d d d d d d d	 d
 d |  i ƒi d d ƒ d  S(   NR6   t   noneR8   t   bottomR   t   StepR?   s   #90c0d0RA   t   blackRK   R9   t   Shiftt	   underlinei    s   #90f090t   Reducet   Undos   #f0a0a0(   RM   t   _buttonframeRO   R-   Rm   Rn   Ro   Rp   (   R    Rb   t   buttonframe(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   á   s    c   	      C   s—  t  | ƒ } t  | d d ƒ} | i d d d d d |  i d d ƒ | i d d	 d d d |  i d d
 ƒ | i d d d d d |  i d d ƒ | i d d d d d | ƒ t  | d d ƒ} | i d d d d d |  i d d ƒ | i d d d d d |  i d d ƒ | i d d d d d | ƒ t  | d d ƒ} | i d d d d d |  i d d ƒ | i	 ƒ  | i d d d d d |  i
 d d ƒ | i d d d d d |  i d d ƒ | i	 ƒ  | i d d d d d |  i d d ƒ | i d d d d d | ƒ t  | d d ƒ} | i d d d d d  |  i d |  i ƒ | i	 ƒ  | i d d! d  |  i d d d" d# d |  i ƒ | i d d$ d  |  i d d d" d% d |  i ƒ | i d d& d  |  i d d d" d' d |  i ƒ | i d d( d  |  i d d d" d) d |  i ƒ | i d d* d  |  i d d d" d+ d |  i ƒ | i d d, d d d | ƒ t  | d d ƒ} | i d d- d d d  |  i d" d ƒ | i d d. d d d  |  i d" d/ d d0 ƒ | i d d1 d d d  |  i d" d# d d2 ƒ | i d d3 d d d  |  i d" d4 d d5 ƒ | i d d6 d d d | ƒ t  | d d ƒ} | i d d7 d d d |  i ƒ | i d d8 d d d |  i d d9 ƒ | i d d: d d d | ƒ | i d | ƒ d  S(;   NR   i    t   labels   Reset ParserRz   RK   t   acceleratort   Dels   Print to Postscripts   Ctrl-pt   Exiti   s   Ctrl-xt   Filet   menus   Edit Grammari   s   Ctrl-gs	   Edit Texts   Ctrl-tt   EditRw   t   SpaceRy   s   Ctrl-sR{   s   Ctrl-rR|   s   Ctrl-ut   Applys   Show Grammart   variablet   Tinyt   valuei
   t   Smalli   t   Mediumi   t   Largei   t   Hugei   t   Views   No Animations   Slow Animationi   Rf   s   Normal AnimationRj   s   Fast Animationi   Rk   t   Animatet   Aboutt   Instructionst   F1t   Help(   R   t   add_commandR   Rq   Rl   t   add_cascadeRs   Rt   Rm   t   add_separatorRn   Ro   Rp   t   add_checkbuttonR   t   _toggle_grammart   add_radiobuttonR0   t   resizeR   t   aboutRr   RX   (	   R    Rb   t   menubart   filemenut   editmenut   rulemenut   viewmenut   animatemenut   helpmenu(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   ò   s‚    		

	


c         C   s*  t  | ƒ |  _ } | i d d d d d d d d ƒ t | d d	 d
 |  i ƒ|  _ |  i i d d ƒ t  | d d d d ƒ} | i d d d d d d d d ƒ t | d d d d d
 |  i ƒ|  _ t | d d d d d d d d d
 |  i ƒ|  _ |  i i d d ƒ |  i i d d d d d d ƒ d  S(   NR6   t   xR8   Rv   R:   i   t   padyR   s   Last Operation:R%   R9   R=   t   sunkent   borderi   RD   RE   i   RA   s   #007070R?   s   #f0f0f0t   anchort   wt   widthi   s   #004040(   RM   t   _feedbackframeRO   RP   R4   t   _lastoper_labelR   t
   _lastoper2(   R    Rb   t   feedbackframet   lastoperframe(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   =  s    ""c         C   sb  t  | d d d d d d d d d	 d
 ƒ|  _ |  i i d d d d d d d d ƒ |  i i ƒ  } |  _ g  |  _ g  |  _ | i d d d d d d d d ƒ|  _ | i	 d d d d d d ƒ|  _
 | i	 d d d d d d ƒ|  _ |  i i ƒ  d } t | d d d d |  i ƒ|  _ t | d d d d |  i ƒ|  _ |  i i |  i ƒ |  i i |  i ƒ d  S(   NR?   R@   Rª   i  t   closeenoughi
   R§   i   R=   R¦   RE   i   R6   R7   R8   t   topR¥   i    s   #c0f0f0t   outlineRx   t   dasht   .s   #408080i   t   Stackt   colors   #004040R%   s   Remaining Text(   t   CanvasFramet   _cframeRO   t   canvasR   t   _stackwidgetst   _rtextwidgetst   create_rectanglet	   _titlebart   create_linet	   _exprlinet	   _stacktopR0   R2   t
   TextWidgetR3   t   _stacklabelt   _rtextlabelt
   add_widget(   R    Rb   R¹   R&   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   M  s$    %		!!c         C   s«  |  i  d i ƒ  } g  } | D] } | t | ƒ q ~ \ } } } } x! |  i D] } |  i i | ƒ qP Wg  |  _ x! |  i D] }	 |  i i |	 ƒ q} Wg  |  _ |  i i ƒ  \ }
 } } } | | d } |  i  i	 |  i
 d d d | d ƒ |  i  i	 |  i d | d d d | d d ƒ |  i i ƒ  \ }
 } } } |  i i d |
 d	 | ƒ |  i i ƒ  \ }
 } } } |  i i | | d d	 | ƒ d } x |  i i ƒ  D]ï } t | t i ƒ ok h  d
 d <d d <|  i d <d d <d d <|  i d <} t |  i  | |  } d | i ƒ  d <n" t |  i  | d d d |  i ƒ} | i |  i ƒ |  i i | ƒ |  i i | | | ƒ | i ƒ  d d } q¡Wd } xr |  i i ƒ  D]a } t |  i  | d d d |  i ƒ} |  i i | ƒ |  i i | | | ƒ | i ƒ  d d } qªWt |  i ƒ d j o | |  i d i ƒ  7} n t | |  i i ƒ  d ƒ } |  i i ƒ  d } | | t | | ƒ j o | t | | ƒ } n x) |  i D] }	 |	 i d | | d ƒ qªW|  i i | |  i i ƒ  d d d ƒ | | t | | ƒ d } |  i  i	 |  i  | d | d ƒ |  i i ƒ  \ }
 } } } t |  i ƒ d j o> | |  d „ } |  i d i! | ƒ |  i d i |  i" ƒ n |  i# ƒ  d  S(   Nt   scrollregioni
   ixìÿÿi    iˆ  i   i   i   i   s   #4080a0t
   tree_colort
   tree_widtht	   node_fonts   #006060t
   node_colort
   leaf_colort	   leaf_fonts   #000000R¶   R%   i   c         S   s3   |  i  ƒ  d | j  o | i ƒ  n | i ƒ  d  S(   Ni    (   t   bboxRn   t   _redraw(   t   widgett   midxR    (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyt
   drag_shift¯  s    %($   R   t   splitt   intRº   R¸   t   destroy_widgetR»   RÂ   RÌ   t   coordsR½   R¿   t   moveRÃ   R   t   stackt
   isinstanceR    t   TreeR3   R4   t   tree_to_treesegmentt   nodeRÁ   t
   bind_clickt   _popup_reducet   appendRÄ   t   remaining_textRZ   Rª   t   maxRÀ   t	   bind_dragRn   t   _highlight_productions(   R    RÅ   t   _[1]t   ct   cx1t   cy1t   cx2t   cy2t   stackwidgett   rtextwidgett   x1t   y1t   x2t   y2RL   t   stackxt   tokt   attribsRÎ   t
   rtextwidtht   rlabelwidthRÏ   RÐ   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRÍ   f  sz    3
 	
 	#/ 		 
 (c         C   s7   | i  ƒ  d d } |  i i |  i | d | d ƒ d  S(   Ni   i2   i    iˆ  (   RÌ   R   RÔ   RÀ   (   R    RÎ   RÏ   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyt   _draw_stack_top¸  s    c         C   sS   |  i  i d d ƒ x9 |  i i ƒ  D]( } |  i i | ƒ } |  i  i | ƒ q# Wd  S(   Ni    RF   (   RS   t   selection_clearR   t   reducible_productionsRV   t   indext   selection_set(   R    t   prodRö   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRá   ½  s
     c         G   s2   |  i  d  j o d  Sn |  i  i ƒ  d  |  _  d  S(   N(   R   t   NoneRl   (   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRl   È  s    c         G   s;   |  i  i |  i ƒ d |  i d <d |  i d <|  i ƒ  d  S(   Ns	   Reset AppR   R   (   R   t
   initializeR	   R   R­   RÍ   (   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   Í  s    c         G   s‚   |  i  ƒ  o d Snj |  i ƒ  o d SnU t |  i i ƒ  ƒ d j o d |  i d <d |  i d <n d |  i d <d |  i d <d  S(   Ni   i    s	   Finished:R   t   Successt   Failure(   Ro   Rn   RZ   R   t   parsesR   R­   (   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRm   Ó  s    c         G   s‡   |  i  o d  Sn |  i i ƒ  oa |  i i ƒ  d } d |  i d <d | |  i d <|  i i ƒ  o |  i ƒ  n |  i	 ƒ  d Sn d S(   Niÿÿÿÿs   Shift:R   s   %ri   i    (
   R   R   Rn   RÖ   R   R­   R   R2   t   _animate_shiftRÍ   (   R    Rg   Rï   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRn   Þ  s    
c         G   sv   |  i  o d  Sn |  i i ƒ  } | oJ d |  i d <d | |  i d <|  i i ƒ  o |  i ƒ  qr |  i ƒ  n | S(   Ns   Reduce:R   s   %s(	   R   R   Ro   R   R­   R   R2   t   _animate_reduceRÍ   (   R    Rg   Rd   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRo   ë  s    c         G   s4   |  i  o d  Sn |  i i ƒ  o |  i ƒ  n d  S(   N(   R   R   Rp   RÍ   (   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRp   ÷  s    c         G   s   |  i  i ƒ  d  S(   N(   R¸   t   print_to_file(   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRq   ü  s    c         O   s)   t  ƒ  o d Sn |  i i | | Ž  d S(   sñ   
        Enter the Tkinter mainloop.  This function must be called if
        this demo is created from a non-interactive program (e.g.
        from a secript); otherwise, the demo will close as soon as
        the script completes.
        N(   R   R   t   mainloop(   R    t   argst   kwargs(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR  ÿ  s    c         C   sŒ   | d  j	 o |  i i | ƒ n |  i i ƒ  } |  i i d t | ƒ ƒ |  i i d t | ƒ ƒ |  i i d t | ƒ ƒ |  i	 ƒ  d  S(   NR&   (
   Rù   R0   R   R2   R4   t	   configuret   absR3   R.   RÍ   (   R    R&   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR›     s    !	c         G   sV   y) t  |  i d t i ƒ  d d d d ƒWn& t  |  i d t i ƒ  d d ƒn Xd  S(   Ns%   Help: Shift-Reduce Parser ApplicationRª   iK   R%   t   fixed(   t   ShowTextR   t   __doc__t   strip(   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRr     s    c      	   G   s^   d d } d } y- d d k  l } | d | d | ƒ i ƒ  Wn t |  i | | ƒ n Xd  S(   Ns%   NLTK Shift-Reduce Parser Application
s   Written by Edward Lopers&   About: Shift-Reduce Parser Applicationiÿÿÿÿ(   t   Messaget   messageR   (   t   tkMessageBoxR
  t   showR  R   (   R    Rg   t   ABOUTt   TITLER
  (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRœ   &  s    c         G   s#   t  |  i |  i i ƒ  |  i ƒ d  S(   N(   R   R   R   R!   t   set_grammar(   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRs   0  s    c         C   sg   |  i  i | ƒ t | i ƒ  ƒ |  _ |  i i d d ƒ x( |  i D] } |  i i d d | ƒ qB Wd  S(   Ni    RF   s    %s(   R   R  RT   RU   RV   RS   t   deleteRW   (   R    R!   Rd   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR  3  s    
 c         G   s>   t  i |  i ƒ } d } d } t |  i | | |  i | ƒ d  S(   Ns	   Edit Texts   Enter a new sentence to parse.(   t   stringt   joinR	   t   EntryDialogR   t   set_sentence(   R    Rg   t   sentenceR   t   instr(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRt   :  s    c         C   s   t  i ƒ  |  _ |  i ƒ  d  S(   N(   R"   RÑ   R	   R   (   R    R  (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR  @  s    c      	   G   st   |  i  i ƒ  o9 |  i i d d d d d d d |  i ƒ d |  i d	 <n |  i i ƒ  d
 |  i d	 <d |  i d	 <d  S(   NR6   R7   R8   R9   R:   i   t   afters   Show GrammarR   s   Hide GrammarR   (   R   R2   RN   RO   R«   R   t   pack_forgetR­   (   R    Rg   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR™   H  s    
c         C   s÷   |  i  i ƒ  } t | ƒ d j o d  Sn t | d ƒ } |  i i |  i | ƒ } | oJ d |  i d <d | |  i d <|  i	 i
 ƒ  o |  i ƒ  qó |  i ƒ  nP |  i  i d d ƒ x9 |  i i ƒ  D]( } |  i i | ƒ } |  i  i | ƒ qÇ Wd  S(   Ni   i    s   Reduce:R   s   %sRF   (   RS   t   curselectionRZ   RÒ   R   Ro   RV   R   R­   R   R2   Rÿ   RÍ   Rô   Rõ   Rö   R÷   (   R    t   eventt	   selectionRö   Rd   Rø   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR^   R  s     c         C   s™   |  i  i ƒ  } t | ƒ d j o d  Sn |  i i d d ƒ x0 | D]( } |  i i d t | ƒ d |  i ƒ qD W|  i i |  i	 i
 ƒ  |  i	 i ƒ  ƒ d  S(   Ni    RF   R   RK   (   R   Rõ   RZ   R   R  R•   t   strRo   t   postR   t   winfo_pointerxt   winfo_pointery(   R    RÎ   RU   Rd   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRÜ   e  s     c         C   s   |  i  d } | i ƒ  d } t |  i ƒ d j o
 d } n |  i d i ƒ  d d } |  i i ƒ  } | | d | } |  i | | | ƒ d  S(   Ni    i   iÿÿÿÿi   i
   g      ð?(   R»   RÌ   RZ   Rº   R   R2   t   _animate_shift_frame(   R    RÎ   RD   R9   t   dtt   dx(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRþ   u  s     c         C   s‹   | d j o@ d |  _  | i | d ƒ |  i i d |  i | d | | ƒ n; |  i d =|  i i | ƒ d |  _  |  i | ƒ |  i	 ƒ  d  S(   Ni    i   i
   (
   R   RÕ   R   R  R!  R»   Rº   RÝ   Ró   Rá   (   R    t   frameRÎ   R#  (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR!  ƒ  s    	
	c         C   s¥   t  |  i i ƒ  d ƒ } |  i | } t | d t ƒ o d | d i ƒ  i ƒ  } n d | d i ƒ  } |  i i	 ƒ  } | d | } |  i
 | d | | ƒ d  S(   Niÿÿÿÿi    i   g       @i   (   RZ   R   RÖ   Rº   R×   t   TreeSegmentWidgetRÚ   RG   R   R2   t   _animate_reduce_frame(   R    t
   numwidgetst   widgetst   ydistR"  t   dy(    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRÿ   •  s    c      	   C   sª  | d j oQ d |  _  x | D] } | i d | ƒ q W|  i i d |  i | d | | ƒ nI|  i t | ƒ 3x | D] } |  i i | ƒ qv W|  i	 i
 ƒ  d } t | t i ƒ p t ƒ  ‚ n t |  i t | i ƒ d d d |  i ƒ} t |  i | | d d	 ƒ} |  i i ƒ  \ } } }	 }
 |
 | d } |  i p
 d
 } n |  i d i ƒ  d	 d } |  i i | | | ƒ |  i i | ƒ |  i | ƒ |  i ƒ  d |  _  d  S(   Ni    i   i
   iÿÿÿÿR¶   s   #006060R%   Rª   i   i   (   R   RÕ   R   R  R&  Rº   RZ   R¸   t   remove_widgetR   RÖ   R×   R    RØ   t
   ValueErrorRÁ   R   R  RÚ   R3   R%  RÂ   RÌ   RÄ   RÝ   Ró   Rá   (   R    R$  R(  R*  RÎ   Rï   R   Rê   Rë   Rì   Rí   RL   R¤   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR&  ¥  s2    	   	
c         C   så   |  i  i | i ƒ } |  i | j o d  Sn |  i ƒ  g  } |  i  i ƒ  D] } | t | ƒ qK ~ } | | j od t |  i | i	 ƒ  ƒ } xH |  i
 | D]4 } t | t ƒ o d | i ƒ  d <qœ d | d <qœ Wn | |  _ d  S(   Ns   #00a000R¶   (   RS   t   nearestRL   R_   Ra   R  RÒ   RZ   RV   t   rhsRº   R×   R%  RÚ   (   R    R  Rö   Râ   t   sR  t   rhslenRè   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR`   à  s    
0 c         G   sg   |  i  d j o d  Sn d |  _  x? |  i D]4 } t | t ƒ o d | i ƒ  d <q+ d | d <q+ Wd  S(   NiÿÿÿÿRx   R¶   (   R_   Rº   R×   R%  RÚ   (   R    R  Rè   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyRa   ö  s    	
 ('   t   __name__t
   __module__R  R$   R   R   R   R   R   R   R   RÍ   Ró   Rá   Rl   R   Rm   Rn   Ro   Rp   Rq   R  Rù   R›   Rr   Rœ   Rs   R  Rt   R  R™   R^   RÜ   Rþ   R!  Rÿ   R&  R`   Ra   (    (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyR   W   sH   	*		&	"		K			R													
					
						;	c          C   sÈ  d d k  l }  l } l } d } g  } | i ƒ  D] } | |  | ƒ q3 ~ \	 } } } }	 }
 } } } } | | | | g ƒ | | | | g ƒ | | | |	 g ƒ | | | |	 g ƒ | | | | |	 g ƒ | | | | g ƒ | |	 |
 | g ƒ | | d g ƒ | | d g ƒ | | d g ƒ | | d g ƒ | | d g ƒ | |
 d	 g ƒ | |
 d
 g ƒ | | d g ƒ | | d g ƒ | | d g ƒ | | d g ƒ f } | | | ƒ } d i ƒ  } t | | ƒ i ƒ  d S(   sQ   
    Create a shift reduce parser app, using a simple grammar and
    text. 
    iÿÿÿÿ(   t   Nonterminalt
   Productiont   ContextFreeGrammars   S VP NP PP P N Name V Dett   It   theRh   t   mant   sawt   int   witht   parkt   dogt   statuet   mys*   my dog saw a man in the park with a statueN(   t   nltkR3  R4  R5  RÑ   R   R  (   R3  R4  R5  t   nonterminalsRâ   R/  t   St   VPt   NPt   PPt   Pt   Nt   Namet   Vt   DetRU   R!   R"   (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pyt   app  s(    At   __main__RK  (   R  R  R@  R    R   R   t   nltk.draw.utilt   nltk.draw.treet   nltk.draw.cfgR   t   objectR   RK  R1  t   __all__(    (    (    s+   /p/zhu/06/nlp/nltk/nltk/app/srparser_app.pys   <module>@   s   

ÿ ÿ ¬	%