
    gt                         d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZ ddlmZmZmZmZmZ ddlmZmZmZmZ ddlmZ  G d d	e      Zd
Z G d d      Z G d d      Z d Z!d Z"d Z#e$dk(  r e"        yy)z
Visualization tools for CFGs.
    N)
ButtonCanvasEntryFrameIntVarLabel	ScrollbarTextTkToplevel)TreeSegmentWidgettree_to_treesegment)CanvasFrameColorizedListShowTextSymbolWidget
TextWidget)CFGNonterminal_read_cfg_productionnonterminals)Treec                   6    e Zd Zej                  d   Zd Zd Zy)ProductionList
rightarrowc                 z    |j                  dd       |j                  ddd       |j                  dd	d
       y )Nterminal#006000
foregroundarrowsymbol0)font	underlinenonterminalblue	helveticaiboldr    r$   
tag_config)self
textwidgetoptionss      B/var/www/openai/venv/lib/python3.12/site-packages/nltk/draw/cfg.py_init_colortagszProductionList._init_colortagsR   sE    jY?gHDf3M 	 	
    c                 L   g }|j                  d|j                         z  df       |j                  | j                  df       |j                         D ]M  }t	        |t
              r%|j                  d|j                         z  df       8|j                  d|z  df       O |S )Nz%s	r&   r!    %s %rr   )appendlhsARROWrhs
isinstancer   r"   )r.   itemcontentselts       r1   
_item_reprzProductionList._item_reprY   s    $((*,m<=W-.88:C#{+!5} EFj 9:	 
 r3   N)__name__
__module____qualname__r   SYMBOLSr9   r2   r?    r3   r1   r   r   O   s      .E
	r3   r   aM  

The CFG Editor can be used to create or modify context free grammars.
A context free grammar consists of a start symbol and a list of
productions.  The start symbol is specified by the text entry field in
the upper right hand corner of the editor; and the list of productions
are specified in the main text editing box.

Every non-blank line specifies a single production.  Each production
has the form "LHS -> RHS," where LHS is a single nonterminal, and RHS
is a list of nonterminals and terminals.

Nonterminals must be a single word, such as S or NP or NP_subj.
Currently, nonterminals must consists of alphanumeric characters and
underscores (_).  Nonterminals are colored blue.  If you place the
mouse over any nonterminal, then all occurrences of that nonterminal
will be highlighted.

Terminals must be surrounded by single quotes (') or double
quotes(").  For example, "dog" and "New York" are terminals.
Currently, the string within the quotes must consist of alphanumeric
characters, underscores, and spaces.

To enter a new production, go to a blank line, and type a nonterminal,
followed by an arrow (->), followed by a sequence of terminals and
nonterminals.  Note that "->" (dash + greater-than) is automatically
converted to an arrow symbol.  When you move your cursor to a
different line, your production will automatically be colorized.  If
there are any errors, they will be highlighted in red.

Note that the order of the productions is significant for some
algorithms.  To re-order the productions, use cut and paste to move
them.

Use the buttons at the bottom of the window when you are done editing
the CFG:
  - Ok: apply the new CFG, and exit the editor.
  - Apply: apply the new CFG, and do not exit the editor.
  - Reset: revert to the original CFG, and do not exit the editor.
  - Cancel: revert to the original CFG, and exit the editor.

c                   t   e Zd ZdZej
                  d   Z ej                  dez   dz         Z	 ej                  dez   dz         Z
 ej                  dez   dz   dz         Z ej                  dez   d	z         Zd
Zd dZd Zd Zd Zd Zd Zd Zd 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!y)"	CFGEditora*  
    A dialog window for creating and editing context free grammars.
    ``CFGEditor`` imposes the following restrictions:

    - All nonterminals must be strings consisting of word
      characters.
    - All terminals must be strings consisting of word characters
      and space characters.
    r   z(^\s*\w+\s*)(->|(z))z\s*(->|(z))\s*z#((\w+|'[\w ]*'|\"[\w ]*\"|\|)\s*)*$z\w+|->|'[\w ]+'|"[\w ]+"|()r(   Nc                    || _         ||| _        nt        t        d      g       | _        || _        d| _        t        |      | _        | j                          | j                          | j                  j                  ddd       | j                          | j                  j                  ddd       | j                          | j                  j                  ddd       | j                   j#                          y )	NS   topxr   sidefillexpandbothbottom)_parent_cfgr   r   _set_cfg_callback _highlight_matching_nonterminalsr   _top_init_bindings_init_startframe_startframepack_init_prodframe
_prodframe_init_buttons_buttonframe_textwidgetfocus)r.   parentcfgset_cfg_callbacks       r1   __init__zCFGEditor.__init__   s    ?DIK,b1DI!101- V$	5s1=%fQ?H3qA r3   c                    t        | j                        x}| _        t        |      | _        | j                  j                  d       t        |d      j                  d       t        |d      j                  d       | j                  j                  d| j                  j                         j                                y )NrightrN   zStart Symbol:textzProductions:leftr   )r   rW   rZ   r   _startr[   r   insertrT   startr"   r.   frames     r1   rY   zCFGEditor._init_startframe   s    #(#33 Elg&e/*//W/=e.)..F.;1diioo/6689r3   c                    t        | j                        x}| _        t        |d| j                  dd      j                  d       t        |d| j                  dd      j                  d       t        |d| j                  dd      j                  d       t        |d| j                  dd      j                  d       t        |d	| j                  dd      j                  d
       y )NOkr   )rj   commandr%   	takefocusrk   rh   ApplyResetCancelHelprg   )
r   rW   r_   r   _okr[   _apply_reset_cancel_helpro   s     r1   r^   zCFGEditor._init_buttons   s    $)$))$44!u4Q!LQQ 	R 	
 	u7DKK1PQRWW 	X 	
 	u7DKK1PQRWW 	X 	
 	$,,!q	

$F$
u64::aPUU 	V 	
r3   c                    | j                   j                  d       | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d	| j                         | j                   j                  d
| j
                         | j                   j                  d| j
                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         | j                   j                  d| j                         y )Nz
CFG Editor<Control-q>z<Alt-q>z<Control-d>z<Alt-x>z<Escape>z<Alt-c>z<Control-o>z<Alt-o>z<Control-a>z<Alt-a>z<Control-r>z<Alt-r>z<Control-h>z<Alt-h>z<F1>)rW   titlebindr|   ry   rz   r{   r}   )r.   s    r1   rX   zCFGEditor._init_bindings   s\   		%		}dll3		y$,,/		}dll3		y$,,/		z4<<0		y$,,/		}dhh/		y$((+		}dkk2		y$++.		}dkk2		y$++.		}djj1		y$**-		vtzz*r3   c                    t        | j                        | _        t        | j                  dd      | _        t        | j                  dd      | _        | j                  j                  | j                  j                         | j                  j                  | j                  j                         | j                  j                  d	d
       | j                  j                  ddd       | j                  j                  dd       | j                  j                  dd       | j                  j                  dd       d| _        | j                  j                  d| j                         | j                  j                  d| j                         | j                  j                  d| j                          | j                  j                  d| j                          | j                  fd}| j                  j                  d|       | j"                  j%                         D cg c]#  }|j'                         |j)                         gf% }}t+        t-        |      dz
  dd      D ]x  }||   d   ||dz
     d   k(  sd||   d   v r#d||dz
     d   v r1t/        ||dz
     d          t/        ||   d          ||dz
     d   j1                  ||   d          ||= z |D ]n  \  }}t/        ||       d |z  }|D ]/  }|D ]#  }	t3        |	t4              r	|d!|	z  z  }|d"|	z  z  }% |d#z  }1 |d d$ d%z   }| j                  j7                  d&|       p | j                          y c c}w )'Nz#e0e0e0rJ   )
backgroundexportselectionr   vertical)rt   orient)yscrollcommand)rs   rg   yrN   rO   rQ   rk   )rP   rO   rN   r   r   r   r!   r"   )r$   errorredr   >z	<<Paste>>z
<KeyPress>z<ButtonPress>c                 @    |j                         j                          y N)tk_focusNextra   )er/   s     r1   cyclez(CFGEditor._init_prodframe.<locals>.cycle  s    ##%++-r3   z<Tab>rD   z%s ->r5   r6   z |
end)r   rW   r]   r
   r`   r	   _textscrollconfigsetyviewr[   r-   _linenumr   _replace_arrows_analyze_check_analyzerT   productionsr8   r:   rangelenprintextendr;   r   rm   )
r.   r   pprod_tuplesir8   rhsssr:   r>   s
             r1   r\   zCFGEditor._init_prodframe   s/   		*  OO	1
 %T__*Ut/?/?/C/CD(8(8(>(>?75QV&A 	##J9#E##G(#;##G#>  			sD001 			{DMM2		|T%8%89		(;(;< !% 0 0 	. 	gu-59YY5J5J5LM5L!%%'+5LMs;'!+Q3A1~a KA$6q$99Q**QU+A..k!a%(+,k!nQ'(AE"1%,,[^A->?N 4 %IC#t#AC!#{3US[(US[(	 
 T	  #2A##E1- % 	3 Ns   -(M/c                     d|z  }d|z  }| j                   j                         D ]$  }|dvs| j                   j                  |||       & y)z
        Remove all tags (except ``arrow`` and ``sel``) from the given
        line of the text widget used for editing the productions.
        %d.0%d.end)r!   selN)r`   	tag_names
tag_remove)r.   linenumrn   r   tags        r1   _clear_tagszCFGEditor._clear_tagsN  sR    
   ##--/C**  ++C< 0r3   c                     t        | j                  j                  d      j                  d      d         }|| j                  k7  r4| j                  |       | j                  | j                         || _        yy)z
        Check if we've moved to a new line.  If we have, then remove
        all colorization from the line we moved to, and re-colorize
        the line that we moved from.
        rm   .r   N)intr`   indexsplitr   r   _analyze_line)r.   r   r   s      r1   r   zCFGEditor._check_analyzeY  sg     d&&,,X6<<SA!DEdmm#W%t}}-#DM $r3   c                    d}	 | j                   j                  d|d      }|dk(  rnc| j                   j                  ||dz          | j                   j                  || j                  d       | j                   j                  |d       d}	 | j                   j                  | j                  |dz   d      }|dk(  ry	| j                   j                  d||dz          Q)
z
        Replace any ``'->'`` text strings with arrows (char \256, in
        symbol font).  This searches the whole buffer, but is fast
        enough to be done anytime they press '>'.
        1.0->z	end+1char z+2charr!   	z+1charN)r`   searchdeleterm   r9   tag_add)r.   r   r!   s      r1   r   zCFGEditor._replace_arrowse  s     $$++D%EE{##E58+;<##E4::w?##E40  $$++DJJ8H+VE{$$WeUX5EF	 r3   c                    |j                         d   dv rd}na|j                         d| j                  fv rd}n@d|j                         z   }|| j                  j                         vr| j	                  |       d||j                         fz  }d||j                         fz  }| j                  j                  |||       y)	z
        Given a line number and a regexp match for a token on that
        line, colorize the token.  Note that the regexp match gives us
        the token's text, start index (on the line), and end index (on
        the line).
        r   z'"r   r   r!   nonterminal_%d.%dN)groupr9   r`   r   _init_nonterminal_tagrn   r   r   )r.   matchr   r   rn   r   s         r1   _analyze_tokenzCFGEditor._analyze_token{  s     ;;=u$C[[]tTZZ00C
 !5;;=0C$**4466**3/7EKKM22%))+..  eS1r3   c                 *   | j                   j                  ||t        j                         | j                  sy | j                   |fd}| j                   |fd}| j                   j                  |d|       | j                   j                  |d|       y )Nr+   c                 *    |j                  |d       y )Nz#80ff80r   r,   r   r/   r   s      r1   enterz.CFGEditor._init_nonterminal_tag.<locals>.enter  s    !!#)!<r3   c                 *    |j                  |d       y )Nr   r   r,   r   s      r1   leavez.CFGEditor._init_nonterminal_tag.<locals>.leave  s    !!#"!5r3   z<Enter>z<Leave>)r`   r-   rF   _BOLDrV   tag_bind)r.   r   r    r   r   s        r1   r   zCFGEditor._init_nonterminal_tag  s    ##CJY__#U44 $ 0 0c 	= !% 0 0c 	6 	!!#y%8!!#y%8r3   c                 f   | j                  |       | j                  j                  t        |      dz   t        |      dz         }t        j
                  j                  |      r'| |fd}t        j                  j                  ||       y|j                         dk7  r| j                  ||       yy)z(
        Colorize a given line.
        z.0z.endc                 (    |j                  | |       y)Nr   )r   )r   r.   r   s      r1   analyze_tokenz.CFGEditor._analyze_line.<locals>.analyze_token  s    ##E73r3   r   N)r   r`   getreprrF   _PRODUCTION_REr   	_TOKEN_REsubstrip_mark_error)r.   r   liner   s       r1   r   zCFGEditor._analyze_line  s    
 	! ##DMD$8$w-&:PQ ##))$/ +/  ##M48ZZ\RWd+  r3   c                    t         j                  j                  |      }|sd|z  }d|z  }nTt         j                  j	                  |      sd|z  }d||j                         fz  }nd||j                         fz  }d|z  }| j                  j                  |d|      r
d|z  }d|z  }| j                  j                  d||       y)z:
        Mark the location of an error in a line.
        r   r   r   z==r   N)
rF   	_ARROW_REr   _LHS_REr   rn   r   r`   comparer   )r.   r   r   
arrowmatchrn   r   s         r1   r   zCFGEditor._mark_error  s     ((//5
W$EW$C""((.W$EWj&6&6&899C w
(899EW$C ##E45W$EW$C  %5r3   c                     | j                          t        | j                  j                  d      j	                  d      d         }t        d|dz         D ]  }| j                  |        y)zM
        Replace ``->`` with arrows, and colorize the entire buffer.
        r   r   r   rJ   N)r   r   r`   r   r   r   r   )r.   r   numlinesr   s       r1   r   zCFGEditor._analyze  s^     	t''--e4::3?BCQ1-Gw' .r3   c                 *   g }| j                   j                  dd      }t        j                  | j                  d|      }t        j                  dd|      }|j                  d      }|D ]&  }|j                         }|dk(  r|t        |      z  }( |S )zo
        Parse the current contents of the textwidget buffer, to create
        a list of productions.
        r   r   r   r    r   r   )r`   r   rer   r9   r   r   r   )r.   r   rj   linesr   s        r1   _parse_productionszCFGEditor._parse_productions  s    
  ##E51vvdjj$-vvdC&

4  D::<Drz/55K	 * r3   c                 `    | j                   y | j                   j                          d | _         y r   rW   destroyr.   r   s     r1   _destroyzCFGEditor._destroy  s&    99			r3   c                 D    | j                          | j                          y r   )rz   r   r   s     r1   ry   zCFGEditor._ok  s    r3   c                     | j                         }t        | j                  j                               }t	        ||      }| j
                  | j                  |       y y r   )r   r   rl   r   r   rU   )r.   r   r   rn   rc   s        r1   rz   zCFGEditor._apply  sP    --/DKKOO-.%%!!-""3' .r3   c                 (   | j                   j                  dd       | j                  j                         D ]!  }| j                   j	                  dd|z         # | j                          | j                  | j                  | j                         y y )Nr   r   z%s
)r`   r   rT   r   rm   r   rU   )r.   r   
productions      r1   r{   zCFGEditor._reset  sv    u-))//1J##E6J+>? 2!!-""499- .r3   c                 T    	 | j                          | j                          y #  Y xY wr   )r{   r   r   s     r1   r|   zCFGEditor._cancel  s%    	KKM 		s   # 'c                     	 t        | j                  dt        j                         dd       y #  t        | j                  dt        j                         d       Y y xY w)NzHelp: Chart Parser DemoK   fixed)widthr$   r   )r   rS   _CFGEditor_HELPr   r   s     r1   r}   zCFGEditor._help  sS    	) '')	) '')	s	   ,/ -A)NN)r'   )"r@   rA   rB   __doc__r   rC   r9   r   compiler   r   r   r   r   re   rY   r^   rX   r\   r   r   r   r   r   r   r   r   r   r   ry   rz   r{   r|   r}   rD   r3   r1   rF   rF      s      .Ebjj-5<=G

;.9:IRZZ	
	 	 1		1N 

<uDsJKI&E!.:
$+*>r	=
$G,209,.60(#J(.r3   rF   c                   \    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 ZddZd Zd Zd Zy
)CFGDemoc                 L   || _         || _        t               | _        | j                  j	                  d       t        | j                        | _        | j                  j                  d       | j                  | j                         t        | j                        }|j                  ddd       | j                  | j                         | j                  | j                         | j                  |       | j                  |       | j                  | j                         y )NzContext Free Grammar Demo   rk   r   r   rM   )_grammar_textr   rW   r   r   _sizer   rX   r   r[   _init_menubarr^   _init_grammar_init_treelet_init_workspace)r.   grammarrj   frame1s       r1   re   zCFGDemo.__init__7  s    
 D			34 DII&


r 	DII& tyy!c!4499%499%6"6"TYY'r3   c                 <    |j                  d| j                         y )Nr   )r   r   )r.   rK   s     r1   rX   zCFGDemo._init_bindingsS  s    -r3   c                      y r   rD   r.   rb   s     r1   r   zCFGDemo._init_menubarV      r3   c                      y r   rD   r  s     r1   r^   zCFGDemo._init_buttonsY  r  r3   c                 F   t        || j                  d      | _        | j                  j                  ddd       | j                  j	                          | j                  j                  d| j                         | j                  j                  d| j                         y )	N   r   rK   rQ   rJ   rM   selectmove)r   r   	_prodlistr[   ra   add_callback_selectprod_cbr  s     r1   r   zCFGDemo._init_grammar\  ss    'RHVA>##Hd.A.AB##FD,?,?@r3   c                 p    t        |d      | _        | j                  j                  dd       d | _        y )Nwhiter   rR   rL   r   )r   _treelet_canvasr[   _treeletr  s     r1   r  zCFGDemo._init_treeletc  s1    %fA!!xc!:r3   c                     t        |d      | _        | j                  j                  ddd       d | _        | j	                          y )Nr  r   rg   rQ   rJ   rM   )r   
_workspacer[   _treereset_workspacer  s     r1   r  zCFGDemo._init_workspaceh  s<    %fA'qA
r3   c           	      v   | j                   j                         }t        | j                  j	                               }d|dz    df}d|dz    f}| j
                  %| j                   j                  | j
                         | j                  j                         j                         }t        |||d      }g }| j                  D ]   }|j                  t        |||d             " t        |||d      | _        | j                   j                  | j
                         |D ]  }	|	j                  d	d
        y )Nr)      r*      rJ   )r$   	draggabler  )colorr   d   )r  canvasr   r   r   r  remove_widgetr   rn   r"   r   r   r7   r   
add_widgetr  )
r.   cfontsize	node_font	leaf_fontrn   rootnodeleaveswordleafs
             r1   r  zCFGDemo.reset_workspacer  s   OO""$tzz~~'( HqL/6:	 HqL/2	 ::!OO))$**5 ##%,,.aY!D JJDMM*Q9JK  'q(F'J
 	""4::. DIIa r3   c                      y r   rD   )r.   r   s     r1   workspace_markprodzCFGDemo.workspace_markprod  r  r3   Nc                 V   || j                   }t        t        |j                               t        |j	                               z
        D ]  }|d|f   dk(  r| j
                   t        |j	                               D ]  \  }}|j                         ||z      }t        |t              r<t        |t              r,|j                  |j                         j                         k(  rht        |t              r$t        |t              r||j                         k(  r  t        d|        y )Nr  r  zMATCH AT)r  r   r   subtreesr:   _markproduction	enumerater;   r   r   r"   labelrj   strr   r   )r.   prodtreer   jnodewidgets          r1   r.  zCFGDemo._markproduction  s    <::Ds4==?+c$((*o=>AGQJ7*$$$TXXZ04Q/t[1"6+<=v||~':':'<<tS)"6:6- 1$ j!$- ?r3   c                    | j                   }| j                  j                  |       | j                  | j                  j	                          |j                         }t        |      D ]!  \  }}t        |t              st        |      }# t        |j                         j                         g| }t        | j                  j                               }d|dz    df}d|dz    f}	t        ||||	      | _        d| j                  d<   | j                  j!                         \  }
}}}t        |d         t        |d	         }}| j                  j#                  ||
z
  |z
  dz  ||z
  |z
  dz         | j%                  |       y )
Nr)   r  r*   r  )r$  r%  rJ   r  r   height)r  r  	highlightr  r   r:   r/  r;   r   r   r8   r"   r   r   r   r   bboxr  r.  )r.   r   r  r:   r   r>   r3  r#  r$  r%  x1y1x2y2whs                   r1   r  zCFGDemo._selectprod_cb  sb   %%  ,==$MM!!# nnnFAs#{+3i % JNN$++-44 tzz~~'( HqL/6:	 HqL/2	+DI
 &'k"  ==--/RR6'?#S)9%:1AFRK1,q2v{a.?@ 	Z(r3   c                 8    | j                   j                          y r   r   )r.   argss     r1   r   zCFGDemo.destroy  s    		r3   c                 <     | j                   j                  |i | y r   )rW   mainloop)r.   rB  kwargss      r1   rD  zCFGDemo.mainloop  s    		D+F+r3   r   )r@   rA   rB   re   rX   r   r^   r   r  r  r  r+  r.  r  r   rD  rD   r3   r1   r   r   6  sE    (8.A
@%>)>,r3   r   c                  N   ddl m} mm} d}fd |j                         D        \	  }}}}}}}	}
} ||||g       ||||g       ||||g       ||||g       |||
||g       |||
|g       ||||g       ||g        ||dd|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j	                         }t        ||      }|j                          y )Nr   )r   r   
ProductionS VP NP PP P N Name V Detc              3   .   K   | ]  } |        y wr   rD   .0r   r   s     r1   	<genexpr>zdemo2.<locals>.<genexpr>       *XCWa;q>CW   upoverItheamansawinwithparkdogstatuemyzI saw a man in the park)nltkr   r   rG  r   r   rD  )r   rG  r   rI   VPNPPPPNNameVDetr   r  rj   dr   s                   @r1   demo2rf    st   11.L*XCU<CUCUCW*X'QBAq$3 	1r2h2Qx 2Bx 2Bx 22r{#22w22w2r2fb)*2u3 31ug1ug1tf1vh1vh1ug1xj!3-K0 ![!G$**,DAJJLr3   c            	      \   ddl m} m d}fd |j                         D        \	  }}}}}}}}	}
 | j                  d      }d }t               }t        |||      }t        |d      j                          t        |d	|j                  
      j                          |j                          y )Nr   )r   r   rH  c              3   .   K   | ]  } |        y wr   rD   rJ  s     r1   rL  zdemo.<locals>.<genexpr>  rM  rN  a+  
    S -> NP VP
    PP -> P NP
    NP -> Det N
    NP -> NP PP
    VP -> V NP
    VP -> VP PP
    Det -> 'a'
    Det -> 'the'
    Det -> 'my'
    NP -> 'I'
    N -> 'dog'
    N -> 'man'
    N -> 'park'
    N -> 'statue'
    V -> 'saw'
    P -> 'in'
    P -> 'up'
    P -> 'over'
    P -> 'with'
    c                     t        |        y r   )r   )r  s    r1   cbzdemo.<locals>.cb!  s	    gr3   z
Testing CFG Editor
ri   Quit)rj   rs   )r\  r   r   r   
fromstringr   rF   r   r[   r   r   rD  )r   r   rI   r]  r^  r_  r`  ra  rb  rc  rd  r  rj  rK   editorr   s                  @r1   demorn    s    %.L*XCU<CUCUCW*X'QBAq$3cnn	G0 $CsGR(F	#,-224
3VS[[1668LLNr3   c                     ddl m}  t        d      \	  }}}}}}}}}	 | |||g       | ||	|g       | |||g       | |||g       | ||||g       | |||g       | |||g       | |g        | |dd|g       | |dg       | |	dg       | |	dg       | |d	g       | |d
g       | |dg       | |dg       | |dg       | |dg       | |dg       | |	dg      f}
t               }|fd}|j	                  d|       t        ||
      }|j                  dd       |j                  d|j                         |j                  d|j                         |j                          |j                  |
d          |j                  |
d          y )Nr   )rG  z!S, VP, NP, PP, P, N, Name, V, DetrO  rP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  c                 $    |j                          y r   )r   )r   ts     r1   r   zdemo3.<locals>.destroyM  s    			r3   qrJ   rQ   )rP   rO   r  r  r     )r\  rG  r   r   r   r   r[   r  markonlyra   mark)rG  rI   r]  r^  r_  r`  ra  rb  rc  rd  r   rq  r   r   s                 r1   demo3rv  +  s   *6++'QBAq$3 	1r2h2Qx 2Bx 2Bx 22r{#22w22w2r2fb)*2u3 31ug1ug1tf1vh1vh1ug1xj!3-K2 	A  FF3q+&AFF!&F!NN8QZZ(NN61::&GGIFF;q>FF;q>r3   __main__)%r   r   tkinterr   r   r   r   r   r   r	   r
   r   r   nltk.draw.treer   r   nltk.draw.utilr   r   r   r   r   nltk.grammarr   r   r   r   	nltk.treer   r   r   rF   r   rf  rn  rv  r@   rD   r3   r1   <module>r}     s   R 
   B  N M ] 4)XY YBa, a,H!R%P,^ zF r3   