
    Ngt                        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"             dS dS )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                   4    e Zd Zej        d         Zd Zd ZdS )ProductionList
rightarrowc                     |                     dd           |                     ddd           |                     dd	d
           d S )Nterminal#006000
foregroundarrowsymbol0)font	underlinenonterminalblue	helveticaiboldr    r$   
tag_config)self
textwidgetoptionss      I/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/draw/cfg.py_init_colortagszProductionList._init_colortagsR   se    jY???gHDDDf3M 	 	
 	
 	
 	
 	
    c                    g }|                     d|                                z  df           |                     | j        df           |                                D ]^}t	          |t
                    r-|                     d|                                z  df           D|                     d|z  df           _|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FF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                   b   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!dS )#	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                 0   || _         ||| _        n"t          t          d          g           | _        || _        d| _        t          |          | _        |                                  | 	                                 | j
                            ddd           |                                  | j                            ddd           |                                  | j                            ddd           | j                                         d S )	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   ?DIIK,,b11DI!101- V$$	5s1===%fQ???H3qAAA     r3   c                    t          | j                  x}| _        t          |          | _        | j                            d           t          |d                              d           t          |d                              d           | j                            d| j        	                                
                                           d S )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3 Ellg&&&e/***//W/===e.)))..F.;;;1dioo//668899999r3   c                    t          | j                  x}| _        t          |d| j        dd                              d           t          |d| j        dd                              d           t          |d| j        dd                              d           t          |d| j        dd                              d           t          |d	| j	        dd                              d
           d S )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   s4   $)$)$4$44!u4Q!LLLQQ 	R 	
 	
 	
 	u7DK1PQRRRWW 	X 	
 	
 	
 	u7DK1PQRRRWW 	X 	
 	
 	
 	$,!q	
 	
 	

$F$


u64:aPPPUU 	V 	
 	
 	
 	
 	
r3   c                    | j                             d           | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d	| j                   | j                             d
| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   | j                             d| j                   d S )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   	%%%	}dl333	y$,///	}dl333	y$,///	z4<000	y$,///	}dh///	y$(+++	}dk222	y$+...	}dk222	y$+...	}dj111	y$*---	vtz*****r3   c                    t          | j                  | _        t          | j        dd          | _        t          | j        dd          | _        | j                            | j        j                   | j                            | j        j	                   | j        
                    d	d
           | j        
                    ddd           | j                            dd           | j                            dd           | j                            dd           d| _        | j                            d| j                   | j                            d| j                   | j                            d| j                   | j                            d| j                   | j        fd}| j                            d|           d | j                                        D             }t'          t)          |          dz
  dd          D ]}||         d         ||dz
           d         k    rd ||         d         v r4d ||dz
           d         v rHt+          ||dz
           d                    t+          ||         d                    ||dz
           d                             ||         d                    ||= |D ]w\  }}t+          ||           d!|z  }|D ]2}|D ](}t/          |t0                    r	|d"|z  z  } |d#|z  z  })|d$z  }3|d d%         d&z   }| j                            d'|           x|                                  d S )(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                 R    |                                                                  d S N)tk_focusNextra   )er/   s     r1   cyclez(CFGEditor._init_prodframe.<locals>.cycle  s&    ##%%++-----r3   z<Tab>c                 `    g | ]+}|                                 |                                gf,S rD   )r8   r:   ).0ps     r1   
<listcomp>z-CFGEditor._init_prodframe.<locals>.<listcomp>  s/    MMM!%%''+MMMr3   rD   z%s ->r5   r6   z |
end)r   rW   r]   r
   r`   r	   _textscrollconfigsetyviewr[   r-   _linenumr   _replace_arrows_analyze_check_analyzerT   productionsrangelenprintextendr;   r   rm   )	r.   r   prod_tuplesir8   rhsssr:   r>   s	            r1   r\   zCFGEditor._init_prodframe   s   	**  O	1
 
 
 %T_*UUUt/?/CDDD(8(>???7555QV&AAA 	##J9#EEE##G(#;;;##G#>>>  		sD0111 		{DM222	|T%8999	(;<<< !% 0 	. 	. 	. 	. 	gu---MMTY5J5J5L5LMMMs;''!+Q33 		# 		#A1~a KA$6q$999Q***QU+A...k!a%(+,,,k!nQ'(((AE"1%,,[^A->???N$ 	. 	.IC#t#A   ) )C!#{33 )US[(US[(T	#2#A##E1----r3   c                     d|z  }d|z  }| j                                         D ]"}|dvr| j                             |||           #dS )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  sh    
   #--// 	= 	=C*** ++C<<<	= 	=r3   c                    t          | j                            d                              d          d                   }|| j        k    r8|                     |           |                     | j                   || _        dS dS )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  s     d&,,X66<<SAA!DEEdm##W%%%t}---#DMMM $#r3   c                    d}	 | j                             d|d          }|dk    rn[| j                             ||dz              | j                             || j        d           | j                             |d           ~d}	 | j                             | j        |d	z   d          }|dk    rd
S | j                             d||d	z              L)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.0T->z	end+1char z+2charr!   	z+1charN)r`   searchdeleterm   r9   tag_add)r.   r   r!   s      r1   r   zCFGEditor._replace_arrowse  s     	1$++D%EEE{{##E58+;<<<##E4:w???##E4000	1 	G$++DJ8H+VVE{{$$WeUX5EFFF		Gr3   c                    |                                 d         dv rd}ng|                                 d| j        fv rd}nGd|                                 z   }|| j                                        vr|                     |           d||                                fz  }d||                                fz  }| j                            |||           dS )	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$$CC[[]]tTZ000CC
 !5;;==0C$*446666**3///7EKKMM22%))++..  eS11111r3   r'   c                    | j                             ||t          j                   | j        sd S | j         |fd}| j         |fd}| j                             |d|           | j                             |d|           d S )Nr+   c                 4    |                     |d           d S )Nz#80ff80r   r,   r   r/   r   s      r1   enterz.CFGEditor._init_nonterminal_tag.<locals>.enter  s!    !!#)!<<<<<r3   c                 4    |                     |d           d S )Nr   r   r,   r   s      r1   leavez.CFGEditor._init_nonterminal_tag.<locals>.leave  s!    !!#"!5555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UU4 	F $ 0c 	= 	= 	= 	= !% 0c 	6 	6 	6 	6 	!!#y%888!!#y%88888r3   c                    |                      |           | j                            t          |          dz   t          |          dz             }t          j                            |          r(| |fd}t          j                            ||           dS |	                                dk    r| 
                    ||           dS dS )z(
        Colorize a given line.
        z.0z.endc                 2    |                     | |           dS )Nr   )r   )r   r.   r   s      r1   analyze_tokenz.CFGEditor._analyze_line.<locals>.analyze_token  s    ##E7333rr3   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MMD$8$w--&:PQQ #))$// 
	, +/     ##M488888ZZ\\RWd+++++  r3   c                    t           j                            |          }|sd|z  }d|z  }n\t           j                            |          sd|z  }d||                                fz  }nd||                                fz  }d|z  }| j                            |d|          r
d|z  }d|z  }| j        	                    d||           dS )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5
 	%W$EW$CC"((.. 	%W$EWj&6&6&8&899CC w
(8(899EW$C ##E455 	%W$EW$C  %55555r3   c                    |                                   t          | j                            d                              d          d                   }t          d|dz             D ]}|                     |           dS )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4::3??BCCQ1-- 	( 	(Gw''''	( 	(r3   c                 0   g }| j                             dd          }t          j        | j        d|          }t          j        dd|          }|                    d          }|D ]/}|                                }|dk    r|t          |          z  }0|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1vdj$--vdC&&

4    	6 	6D::<<Drzz/555KK" r3   c                 X    | j         d S | j                                          d | _         d S r   rW   destroyr.   r   s     r1   _destroyzCFGEditor._destroy  s.    9F				r3   c                 V    |                                   |                                  d S r   )rz   r   r   s     r1   ry   zCFGEditor._ok  s     r3   c                     |                                  }t          | j                                                  }t	          ||          }| j        |                     |           d S d S r   )r   r   rl   r   r   rU   )r.   r   r   rn   rc   s        r1   rz   zCFGEditor._apply  sf    --//DKOO--..%%%!-""3''''' .-r3   c                    | j                             dd           | j                                        D ] }| j                             dd|z             !|                                  | j        |                     | j                   d S d S )Nr   r   z%s
)r`   r   rT   r   rm   r   rU   )r.   r   
productions      r1   r{   zCFGEditor._reset  s    u---)//11 	@ 	@J##E6J+>????!-""49----- .-r3   c                 h    	 |                                   n#  Y nxY w|                                  d S r   )r{   r   r   s     r1   r|   zCFGEditor._cancel  s5    	KKMMMM	Ds    c                     	 t          | j        dt                                          dd           d S #  t          | j        dt                                          d           Y d S xY w)NzHelp: Chart Parser DemoK   fixed)widthr$   r   )r   rS   _CFGEditor_HELPr   r   s     r1   r}   zCFGEditor._help  s    	) ''))     	) ''))	      s	   04 1A()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bj-5<==G
;.9::IRZ	
	 	 1		1 N 
<uDsJKKI&E! ! ! !.: : :
 
 
$+ + +*> > >r	= 	= 	=
$ 
$ 
$G G G,2 2 209 9 9 9, , ,.6 6 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d
S )CFGDemoc                 ^   || _         || _        t                      | _        | j                            d           t          | j                  | _        | j                            d           |                     | j                   t          | j                  }|
                    ddd           |                     | j                   |                     | j                   |                     |           |                     |           |                     | j                   d S )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
   
 DD		3444 DI&&

r 	DI&&& ty!!c!44449%%%49%%%6"""6"""TY'''''r3   c                 <    |                     d| j                   d S )Nr   )r   r   )r.   rK   s     r1   rX   zCFGDemo._init_bindingsS  s    -----r3   c                     d S r   rD   r.   rb   s     r1   r  zCFGDemo._init_menubarV      r3   c                     d S r   rD   r
  s     r1   r^   zCFGDemo._init_buttonsY  r  r3   c                 *   t          || j        d          | _        | j                            ddd           | j                                         | j                            d| j                   | j                            d| j                   d S )	N   r   rK   rQ   rJ   rM   selectmove)r   r   	_prodlistr[   ra   add_callback_selectprod_cbr
  s     r1   r  zCFGDemo._init_grammar\  s    'RHHHVA>>>##Hd.ABBB##FD,?@@@@@r3   c                 x    t          |d          | _        | j                            dd           d | _        d S )Nwhiter   rR   rL   r   )r   _treelet_canvasr[   _treeletr
  s     r1   r  zCFGDemo._init_treeletc  s>    %fAAA!!xc!:::r3   c                     t          |d          | _        | j                            ddd           d | _        |                                  d S )Nr  r   rg   rQ   rJ   rM   )r   
_workspacer[   _treereset_workspacer
  s     r1   r  zCFGDemo._init_workspaceh  sR    %fAAA'qAAA
r3   c           	      v   | j                                         }t          | j                                                  }d|dz    df}d|dz    f}| j        | j                             | j                   | j                                        	                                }t          |||d          }g }| j        D ](}|                    t          |||d                     )t          |||d          | _        | j                             | j                   |D ]}	|	                    d	d
           d S )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  sO   O""$$tz~~''(( HqL/6:	 HqL/2	 :!O))$*555 ##%%,,..aY!DDD J 	L 	LDMM*Q9JJJKKKK 'q(F'JJJ
 	""4:...  	 	DIIa	 	r3   c                     d S r   rD   )r.   r   s     r1   workspace_markprodzCFGDemo.workspace_markprod  r  r3   Nc                    || j         }t          t          |                                          t          |                                          z
            D ]
}|d|f         dk    r| j         t          |                                          D ]\  }}|                                ||z            }t          |t                    rEt          |t                    r0|j
        |                                                                k    r|t          |t                    r.t          |t                    r||                                k    r nt          d|           d S )Nr   r  zMATCH AT)r  r   r   subtreesr:   _markproduction	enumerater;   r   r   r"   labelrj   strr   r   )r.   prodtreer   jnodewidgets          r1   r1  zCFGDemo._markproduction  sG   <:Ds4==??++c$((**oo=>> 	% 	%AGQJ7**$$$TXXZZ00 % %4Q/t[11"6+<== v||~~':':'<'<<<tS))"6:66 --E j!$$$-	% 	%r3   c                 J   | j         }| j                            |           | j        | j                                         |                                }t          |          D ])\  }}t          |t                    rt          |          }*t          |
                                                                g|R  }t          | j                                                  }d|dz    df}d|dz    f}	t          ||||	          | _        d| j        d<   | j                                        \  }
}}}t          |d                   t          |d	                   }}| j                            ||
z
  |z
  dz  ||z
  |z
  dz             |                     |           d S )
Nr)   r  r*   r  )r'  r(  rJ   r  r   height)r  r  	highlightr  r   r:   r2  r;   r   r   r8   r"   r   r  r   r   bboxr  r1  )r.   r   r"  r:   r   r>   r6  r&  r'  r(  x1y1x2y2whs                   r1   r  zCFGDemo._selectprod_cb  s   %  ,,,=$M!!### nnnn 	  	 FAs#{++  3iiJNN$$++--4444 tz~~''(( HqL/6:	 HqL/2	+DI
 
 
 &'k"  =--//RR6'?##S)9%:%:1AFRK1,q2v{a.?@@@ 	Z(((((r3   c                 8    | j                                          d S r   r   )r.   argss     r1   r   zCFGDemo.destroy  s    	r3   c                 *     | j         j        |i | d S r   )rW   mainloop)r.   rE  kwargss      r1   rG  zCFGDemo.mainloop  s"    	D+F+++++r3   r   )r@   rA   rB   re   rX   r  r^   r  r  r  r  r.  r1  r  r   rG  rD   r3   r1   r   r   6  s        ( ( (8. . .    A A A  
    @  % % % %>) ) )>  , , , , ,r3   r   c                     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                                }t          ||          }|                                 d S )Nr   )r   r   
ProductionS VP NP PP P N Name V Detc              3   .   K   | ]} |          V  d S r   rD   r   r   r   s     r1   	<genexpr>zdemo2.<locals>.<genexpr>  +      *X*Xa;;q>>*X*X*X*X*X*Xr3   upoverItheamansawinwithparkdogstatuemyzI saw a man in the park)nltkr   r   rJ  r   r   rG  )r   rJ  r   rI   VPNPPPPNNameVDetr   r  rj   dr   s                   @r1   demo2rg    s   1111111111.L*X*X*X*XCU<CUCWCW*X*X*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 c![!!G$**,,DAJJLLLLLr3   c            	         ddl m} m d}fd |j                    D             \	  }}}}}}}}	}
 | j        d          }d }t                      }t          |||          }t          |d                                           t          |d	|j
        
                                           |                                 d S )Nr   )r   r   rK  c              3   .   K   | ]} |          V  d S r   rD   rM  s     r1   rN  zdemo.<locals>.<genexpr>  rO  r3   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          |            d S 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   rG  )r   r   rI   r^  r_  r`  ra  rb  rc  rd  re  r  rk  rK   editorr   s                  @r1   demoro    s    %%%%%%%%.L*X*X*X*XCU<CUCWCW*X*X*X'QBAq$3cn	 G0   $$CsGR((F	#,---22444
3VS[11166888LLNNNNNr3   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}|                    d|           t          ||
          }|                    dd           |                    d|j                   |                    d|j                   |	                                 |
                    |
d                    |
                    |
d                    d S )Nr   )rJ  z!S, VP, NP, PP, P, N, Name, V, DetrP  rQ  rR  rS  rT  rU  rV  rW  rX  rY  rZ  r[  r\  c                 .    |                                  d S r   )r   )r   ts     r1   r   zdemo3.<locals>.destroyM  s    			r3   qrJ   rQ   )rP   rO   r  r  r     )r]  rJ  r   r   r   r   r[   r  markonlyra   mark)rJ  rI   r^  r_  r`  ra  rb  rc  rd  re  r   rr  r   r   s                 r1   demo3rw  +  sq   *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!!!NN8QZ(((NN61:&&&GGIII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   rg  ro  rw  r@   rD   r3   r1   <module>r~     s   R 
			                        B A A A A A A A              N M M M M M M M M M M M          ]   4)XY Y Y Y Y Y Y YBa, a, a, a, a, a, a, a,H! ! !R% % %P, , ,^ zDFFFFF r3   