
    /ht                         S r SSKrSSKJrJrJrJrJrJrJ	r	J
r
JrJr  SSKJrJr  SSKJrJrJrJrJr  SSKJrJrJrJr  SSKJr   " S S	\5      rS
r " S S5      r " S S5      r S r!S r"S r#\$S:X  a  \"" 5         gg)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                   >    \ rS rSr\R
                  S   rS rS rSr	g)ProductionListO   
rightarrowc                 h    UR                  SSS9  UR                  SSSS9  UR                  SS	S
S9  g )Nterminal#006000
foregroundarrowsymbol0)font	underlinenonterminalblue	helveticaiboldr!   r%   
tag_config)self
textwidgetoptionss      E/var/www/auris/envauris/lib/python3.13/site-packages/nltk/draw/cfg.py_init_colortagsProductionList._init_colortagsR   sE    jY?gHDf3M 	 	
    c                 \   / nUR                  SUR                  5       -  S45        UR                  U R                  S45        UR                  5        HT  n[	        U[
        5      (       a&  UR                  SUR                  5       -  S45        M>  UR                  SU-  S45        MV     U$ )Nz%s	r'   r"    %s %rr   )appendlhsARROWrhs
isinstancer   r#   )r/   itemcontentselts       r2   
_item_reprProductionList._item_reprY   s    $((*,m<=W-.88:C#{++!5} EFj 9:	 
 r5    N)
__name__
__module____qualname____firstlineno__r   SYMBOLSr;   r3   rA   __static_attributes__rC   r5   r2   r   r   O   s      .E
	r5   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                      \ rS rSrSr\R                  S   r\R                  " S\-   S-   5      r
\R                  " S\-   S-   5      r\R                  " S\-   S-   S-   5      r\R                  " S	\-   S
-   5      rSrS"S jrS rS rS rS rS rS rS rS rS#S jrS rS rS rS rS rS rS rS r S r!S  r"S!r#g)$	CFGEditor   a  
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                    Xl         Ub  X l        O[        [        S5      / 5      U l        X0l        SU l        [        U5      U l        U R                  5         U R                  5         U R                  R                  SSSS9  U R                  5         U R                  R                  SSSS9  U R                  5         U R                  R                  SSSS9  U R                   R#                  5         g )	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       r2   __init__CFGEditor.__init__   s    ?IK,b1DI!101- V$	5s1=%fQ?H3qA r5   c                 l   [        U R                  5      =ol        [        U5      U l        U R                  R                  SS9  [        USS9R                  SS9  [        USS9R                  SS9  U R                  R                  SU R                  R                  5       R                  5       5        g )NrightrT   zStart Symbol:textzProductions:leftr   )r   r]   r`   r   _startra   r   insertrZ   startr#   r/   frames     r2   r_   CFGEditor._init_startframe   s    #(#33 Elg&e/*//W/=e.)..F.;1diioo/6689r5   c                    [        U R                  5      =ol        [        USU R                  SSS9R                  SS9  [        USU R                  SSS9R                  SS9  [        USU R                  SSS9R                  SS9  [        USU R                  SSS9R                  SS9  [        US	U R                  SSS9R                  S
S9  g )NOkr   )rq   commandr&   	takefocusrr   ro   ApplyResetCancelHelprn   )
r   r]   re   r   _okra   _apply_reset_cancel_helprv   s     r2   rd   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 	
r5   c                    U R                   R                  S5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  S	U R                  5        U R                   R                  S
U R
                  5        U R                   R                  SU R
                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        U R                   R                  SU R                  5        g )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>)r]   titlebindr   r   r   r   r   )r/   s    r2   r^   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*r5   c                    [        U R                  5      U l        [        U R                  SSS9U l        [        U R                  SSS9U l        U R                  R                  U R                  R                  S9  U R                  R                  U R                  R                  S9  U R                  R                  S	S
S9  U R                  R                  SSSS9  U R                  R                  SSS9  U R                  R                  SSS9  U R                  R                  SSS9  SU l        U R                  R                  SU R                  5        U R                  R                  SU R                  5        U R                  R                  SU R                   5        U R                  R                  SU R                   5        U R                  4S jnU R                  R                  SU5        U R"                  R%                  5        Vs/ s H#  o"R'                  5       UR)                  5       /4PM%     nn[+        [-        U5      S-
  SS5       Hx  nX4   S   X4S-
     S   :X  d  M  SX4   S   ;   a  M%  SX4S-
     S   ;   a  M5  [/        X4S-
     S   5        [/        X4   S   5        X4S-
     S   R1                  X4   S   5        X4	 Mz     U Hw  u  pV[/        XV5        S U-  nU H8  nU H*  n	[3        U	[4        5      (       a
  US!U	-  -  nM"  US"U	-  -  nM,     US#-  nM:     US S$ S%-   nU R                  R7                  S&U5        My     U R                  5         g s  snf )'Nz#e0e0e0rP   )
backgroundexportselectionr   vertical)r|   orient)yscrollcommand)r{   rn   yrT   rU   rW   rr   )rV   rU   rT   r   r   r    r"   r#   )r%   errorredr   >z	<<Paste>>z
<KeyPress>z<ButtonPress>c                 @    UR                  5       R                  5         g N)tk_focusNextrg   )er0   s     r2   cycle(CFGEditor._init_prodframe.<locals>.cycle  s    ##%++-r5   z<Tab>rC   z%s ->r7   r8   z |
end)r   r]   rc   r
   rf   r	   _textscrollconfigsetyviewra   r.   _linenumr   _replace_arrows_analyze_check_analyzerZ   productionsr:   r<   rangelenprintextendr=   r   rt   )
r/   r   pprod_tuplesir:   rhsssr<   r@   s
             r2   rb   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~a KA$6q$99**U+A..ka%(+,knQ'(E"1%,,[^A->?N 4 %IC##AC!#{33US[(US[(	 
 T	  #2A##E1- % 	3 Ns   *M"c                     SU-  nSU-  nU R                   R                  5        H'  nUS;  d  M  U R                   R                  XBU5        M)     g)zy
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)rf   	tag_names
tag_remove)r/   linenumru   r   tags        r2   _clear_tagsCFGEditor._clear_tagsN  sP    
   ##--/C**  ++C< 0r5   c                     [        U R                  R                  S5      R                  S5      S   5      nX R                  :w  a3  U R                  U5        U R                  U R                  5        X l        gg)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.
rt   .r   N)intrf   indexsplitr   r   _analyze_line)r/   r   r   s      r2   r   CFGEditor._check_analyzeY  sc     d&&,,X6<<SA!DEmm#W%t}}-#M $r5   c                    Sn U R                   R                  SUS5      nUS:X  a  ObU R                   R                  X"S-   5        U R                   R                  X R                  S5        U R                   R                  US5        M  Sn U R                   R                  U R                  US-   S5      nUS:X  a  g	U R                   R                  SX"S-   5        MR  )
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)rf   searchdeletert   r;   tag_add)r/   r   r"   s      r2   r   CFGEditor._replace_arrowse  s     $$++D%EE{##E8+;<##E::w?##E40  $$++DJJ8H+VE{$$WeX5EF	 r5   c                    UR                  5       S   S;   a  SnOdUR                  5       SU R                  4;   a  SnOASUR                  5       -   nX0R                  R                  5       ;  a  U R	                  U5        SX!R                  5       4-  nSX!R                  5       4-  nU R                  R                  X4U5        g)	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)groupr;   rf   r   _init_nonterminal_tagru   r   r   )r/   matchr   r   ru   r   s         r2   _analyze_tokenCFGEditor._analyze_token{  s     ;;=u$C[[]tTZZ00C
 !5;;=0C**4466**3/7KKM22))+..  S1r5   c                 0   U R                   R                  X[        R                  S9  U R                  (       d  g U R                   U4S jnU R                   U4S jnU R                   R                  USU5        U R                   R                  USU5        g )Nr,   c                 $    UR                  USS9  g )Nz#80ff80r   r-   r   r0   r   s      r2   enter.CFGEditor._init_nonterminal_tag.<locals>.enter  s    !!#)!<r5   c                 $    UR                  USS9  g )Nr   r   r-   r   s      r2   leave.CFGEditor._init_nonterminal_tag.<locals>.leave  s    !!#"!5r5   z<Enter>z<Leave>)rf   r.   rK   _BOLDr\   tag_bind)r/   r   r!   r   r   s        r2   r   CFGEditor._init_nonterminal_tag  s    ##CY__#U44 $ 0 0c 	= !% 0 0c 	6 	!!#y%8!!#y%8r5   c                 n   U R                  U5        U R                  R                  [        U5      S-   [        U5      S-   5      n[        R
                  R                  U5      (       a&  X4S jn[        R                  R                  X25        gUR                  5       S:w  a  U R                  X5        gg)z
Colorize a given line.
z.0z.endc                 &    UR                  X5        g)Nr   )r   )r   r/   r   s      r2   analyze_token.CFGEditor._analyze_line.<locals>.analyze_token  s    ##E3r5   r   N)r   rf   getreprrK   _PRODUCTION_REr   	_TOKEN_REsubstrip_mark_error)r/   r   liner   s       r2   r   CFGEditor._analyze_line  s    
 	! ##DMD$8$w-&:PQ ##))$// +/  ##M8ZZ\RW+  r5   c                    [         R                  R                  U5      nU(       d  SU-  nSU-  nOW[         R                  R	                  U5      (       d  SU-  nSXR                  5       4-  nOSXR                  5       4-  nSU-  nU R                  R                  USU5      (       a
  SU-  nSU-  nU R                  R                  SXE5        g)z*
Mark the location of an error in a line.
r   r   r   z==r   N)
rK   	_ARROW_REr   _LHS_REr   ru   r   rf   comparer   )r/   r   r   
arrowmatchru   r   s         r2   r   CFGEditor._mark_error  s     ((//5
W$EW$C""((..W$EW&6&6&899C w(899EW$C ##E455W$EW$C  %5r5   c                     U R                  5         [        U R                  R                  S5      R	                  S5      S   5      n[        SUS-   5       H  nU R                  U5        M     g)z=
Replace ``->`` with arrows, and colorize the entire buffer.
r   r   r   rP   N)r   r   rf   r   r   r   r   )r/   r   numlinesr   s       r2   r   CFGEditor._analyze  s^     	t''--e4::3?BCQ1-Gw' .r5   c                 6   / nU R                   R                  SS5      n[        R                  " U R                  SU5      n[        R                  " SSU5      nUR                  S5      nU H)  nUR                  5       nUS:X  a  M  U[        U5      -  nM+     U$ )zW
Parse the current contents of the textwidget buffer, to create
a list of productions.
r   r   r   r    r   r   )rf   r   rer   r;   r   r   r   )r/   r   rq   linesr   s        r2   _parse_productionsCFGEditor._parse_productions  s    
  ##E51vvdjj$-vvdC&

4  D::<Drz/55K	 * r5   c                 b    U R                   c  g U R                   R                  5         S U l         g r   r]   destroyr/   r   s     r2   _destroyCFGEditor._destroy  s&    99			r5   c                 D    U R                  5         U R                  5         g r   )r   r  r  s     r2   r   CFGEditor._ok  s    r5   c                     U R                  5       n[        U R                  R                  5       5      n[	        X25      nU R
                  b  U R                  U5        g g r   )r   r   rs   r   r   r[   )r/   r   r   ru   ri   s        r2   r   CFGEditor._apply  sN    --/DKKOO-.%%!!-""3' .r5   c                 .   U R                   R                  SS5        U R                  R                  5        H"  nU R                   R	                  SSU-  5        M$     U R                  5         U R                  b  U R                  U R                  5        g g )Nr   r   z%s
)rf   r   rZ   r   rt   r   r[   )r/   r   
productions      r2   r   CFGEditor._reset  sv    u-))//1J##E6J+>? 2!!-""499- .r5   c                 T     U R                  5         U R                  5         g !    N= fr   )r   r  r  s     r2   r   CFGEditor._cancel  s%    	KKM 		s   # 'c                      [        U R                  S[        R                  5       SSS9  g !   [        U R                  S[        R                  5       SS9   g = f)NzHelp: Chart Parser DemoK   fixed)widthr%   r  )r   rY   _CFGEditor_HELPr   r  s     r2   r   CFGEditor._help  sS    	) '')	) '')	s	   ), *A)re   rZ   r\   r   rY   rc   r[   rs   r`   r   rf   r]   )NN)r(   )$rD   rE   rF   rG   __doc__r   rH   r;   r   compiler   r   r   r   r   rk   r_   rd   r^   rb   r   r   r   r   r   r   r   r   r   r  r   r   r   r   r   rI   rC   r5   r2   rK   rK      s       .Ejj-5<=G

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

<uDsJKI&E!.:
$+*>r	=
$G,209,.60(#J(.r5   rK   c                   f    \ rS rSrS rS rS rS rS rS r	S r
S	 rS
 rSS jrS rS rS rSrg)CFGDemoi6  c                 B   Xl         X l        [        5       U l        U R                  R	                  S5        [        U R                  5      U l        U R                  R                  S5        U R                  U R                  5        [        U R                  5      nUR                  SSSS9  U R                  U R                  5        U R                  U R                  5        U R                  U5        U R                  U5        U R                  U R                  5        g )NzContext Free Grammar Demo   rr   r   r   rS   )_grammar_textr   r]   r   r   _sizer   r^   r   ra   _init_menubarrd   _init_grammar_init_treelet_init_workspace)r/   grammarrq   frame1s       r2   rk   CFGDemo.__init__7  s    
 D			34 DII&


r 	DII& tyy!c!4499%499%6"6"TYY'r5   c                 <    UR                  SU R                  5        g )Nr   )r   r   )r/   rQ   s     r2   r^   CFGDemo._init_bindingsS  s    -r5   c                     g r   rC   r/   rh   s     r2   r  CFGDemo._init_menubarV      r5   c                     g r   rC   r'  s     r2   rd   CFGDemo._init_buttonsY  r)  r5   c                 8   [        XR                  SS9U l        U R                  R                  SSSS9  U R                  R	                  5         U R                  R                  SU R                  5        U R                  R                  SU R                  5        g )	N   r  rQ   rW   rP   rS   selectmove)r   r  	_prodlistra   rg   add_callback_selectprod_cbr'  s     r2   r  CFGDemo._init_grammar\  sq    'RHVA>##Hd.A.AB##FD,?,?@r5   c                 d    [        USS9U l        U R                  R                  SSS9  S U l        g )Nwhiter   rX   rR   r   )r   _treelet_canvasra   _treeletr'  s     r2   r  CFGDemo._init_treeletc  s1    %fA!!xc!:r5   c                     [        USS9U l        U R                  R                  SSSS9  S U l        U R	                  5         g )Nr5  r   rn   rW   rP   rS   )r   
_workspacera   _treereset_workspacer'  s     r2   r   CFGDemo._init_workspaceh  s<    %fA'qA
r5   c           
      h   U R                   R                  5       n[        U R                  R	                  5       5      nSUS-   * S4nSUS-   * 4nU R
                  b%  U R                   R                  U R
                  5        U R                  R                  5       R                  5       n[        XUSS9n/ nU R                   H  nUR                  [        XUSS95        M     [        XUSS9U l        U R                   R                  U R
                  5        U H  n	U	R                  S	S
5        M     g )Nr*      r+      rP   )r%   	draggabler5  )colorr   d   )r:  canvasr   r  r   r;  remove_widgetr  ru   r#   r   r  r9   r   
add_widgetr/  )
r/   cfontsize	node_font	leaf_fontru   rootnodeleaveswordleafs
             r2   r<  CFGDemo.reset_workspacer  s   OO""$tzz~~'( HqL/6:	 HqL/2	 ::!OO))$**5 ##%,,.aY!D JJDMM*Q9JK  'qF'J
 	""4::. DIIa r5   c                     g r   rC   )r/   r	  s     r2   workspace_markprodCFGDemo.workspace_markprod  r)  r5   Nc                    Uc  U R                   n[        [        UR                  5       5      [        UR	                  5       5      -
  5       H  nUSU4   S:X  a  U R
                    [        UR	                  5       5       H  u  pEUR                  5       X4-      n[        U[        5      (       aC  [        U[        5      (       a.  UR                  UR                  5       R                  5       :X  a  Mr  [        U[        5      (       a*  [        U[        5      (       a  XVR                  5       :X  a  M    M     [        SU5        M     g )NrB  r5  zMATCH AT)r;  r   r   subtreesr<   _markproduction	enumerater=   r   r   r#   labelrq   strr   r   )r/   prodtreer   jnodewidgets          r2   rU  CFGDemo._markproduction  s    <::Ds4==?+c$((*o=>AGQJ7*$$$TXXZ0/t[11"6+<==v||~':':'<<tS))"6:66- 1$ j!$- ?r5   c                 
   U R                   nU R                  R                  U5        U R                  b  U R                  R	                  5         UR                  5       n[        U5       H'  u  pE[        U[        5      (       d  M  [        U5      nM)     [        UR                  5       R                  5       /UQ76 n[        U R                  R                  5       5      nSUS-   * S4nSUS-   * 4n	[        X&XS9U l        SU R                  S'   U R                  R!                  5       u  pp[        US   5      [        US	   5      pU R                  R#                  X-
  U-
  S-  X-
  U-
  S-  5        U R%                  U5        g )
Nr*   r?  r+   r@  )rI  rJ  rP   rA  r  height)r6  r0  	highlightr7  r   r<   rV  r=   r   r   r:   r#   r   r  r   r   bboxr/  rU  )r/   r	  rD  r<   r   r@   rZ  rH  rI  rJ  x1y1x2y2whs                   r2   r2  CFGDemo._selectprod_cb  sU   %%  ,==$MM!!# nnnFA#{++3i % JNN$++-44 tzz~~'( HqL/6:	 HqL/2	+I
 &'k"  ==--/6'?#S)9%:1AFRK1,qv{a.?@ 	Z(r5   c                 8    U R                   R                  5         g r   r   )r/   argss     r2   r   CFGDemo.destroy  s    		r5   c                 <    U R                   R                  " U0 UD6  g r   )r]   mainloop)r/   rk  kwargss      r2   rn  CFGDemo.mainloop  s    		D+F+r5   )	r  r0  r  r  r]   r;  r7  r6  r:  r   )rD   rE   rF   rG   rk   r^   r  rd   r  r  r   r<  rQ  rU  r2  r   rn  rI   rC   r5   r2   r  r  6  sE    (8.A
@%>)>,r5   r  c                  4  ^ SSK Jn JmJn  SnU4S jUR                  " 5        5       u	  p4pVpxpnU" X5U/5      U" X[U/5      U" XUU/5      U" XDU/5      U" XJXV/5      U" XJU/5      U" XgU/5      U" U/ 5      U" USSU/5      U" US/5      U" US/5      U" US	/5      U" US
/5      U" U
S/5      U" US/5      U" US/5      U" US/5      U" US/5      U" US/5      U" US/5      4nU " X<5      nSR	                  5       n[        X5      nUR                  5         g )Nr   )r   r   
ProductionS VP NP PP P N Name V Detc              3   4   >#    U  H  nT" U5      v   M     g 7fr   rC   .0r   r   s     r2   	<genexpr>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   rr  r   r  rn  )r   rr  r   rO   VPNPPPPNNameVDetr   r!  rq   dr   s                   @r2   demo2r    sU   11.L*X<CUCUCW*X'QBA$3 	12h2Qx 2Bx 2Bx 22{#22w22w2r2fb)*2u3 31ug1ug1tf1vh1vh1ug1xj!3-K0 !!G$**,DAJJLr5   c            	      H  ^ SSK Jn Jm  SnU4S jUR                  " 5        5       u	  p#pEpgpn
U R                  " S5      nS n[        5       n[        XU5      n[        USS9R                  5         [        US	UR                  S
9R                  5         UR                  5         g )Nr   )r   r   rs  c              3   4   >#    U  H  nT" U5      v   M     g 7fr   rC   ru  s     r2   rw  demo.<locals>.<genexpr>  ry  rz  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                     [        U 5        g r   )r   )r!  s    r2   cbdemo.<locals>.cb!  s	    gr5   z
Testing CFG Editor
rp   Quit)rq   r{   )r  r   r   r   
fromstringr   rK   r   ra   r   r   rn  )r   r   rO   r  r  r  r  r  r  r  r  r!  r  rQ   editorr   s                  @r2   demor    s    %.L*X<CUCUCW*X'QBA$3nn	G0 $CsR(F	#,-224
3VS[[1668LLNr5   c                     SSK Jn   [        S5      u	  pp4pVpxn	U " XU/5      U " X9U/5      U " X3U/5      U " X"U/5      U " X(X4/5      U " X(U/5      U " XEU/5      U " U/ 5      U " USSU/5      U " US/5      U " U	S/5      U " U	S/5      U " US	/5      U " US
/5      U " US/5      U " US/5      U " US/5      U " US/5      U " US/5      U " U	S/5      4n
[        5       nU4S jnUR	                  SU5        [        X5      nUR                  SSS9  UR                  SUR                  5        UR                  SUR                  5        UR                  5         UR                  U
S   5        UR                  U
S   5        g )Nr   )rr  z!S, VP, NP, PP, P, N, Name, V, Detr{  r|  r}  r~  r  r  r  r  r  r  r  r  r  c                 $    UR                  5         g r   )r   )r   ts     r2   r   demo3.<locals>.destroyM  s    			r5   qrP   rW   )rV   rU   r.  r/  r@     )r  rr  r   r   r   r   ra   r1  markonlyrg   mark)rr  rO   r  r  r  r  r  r  r  r  r   r  r   r   s                 r2   demo3r  +  s   *6++'QBA$3 	12h2Qx 2Bx 2Bx 22{#22w22w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>r5   __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  rK   r  r  r  r  rD   rC   r5   r2   <module>r     s   R 
   B  N M ] 4)XY YBa, a,H!R%P,^ zF r5   