
4Ic           @   s   d  Z  d d k Z d d k l Z l Z l Z d d k l Z d d k Td d k	 Td e
 f d     YZ d Z d	 e f d
     YZ d e f d     YZ d   Z d   Z d   Z e d j o e   n d S(   s   
Visualization tools for CFGs.
iN(   t   ContextFreeGrammart   Nonterminalt   parse_cfg_production(   t   Tree(   t   *t   ProductionListc           B   s'   e  Z e i d  Z d   Z d   Z RS(   t
   rightarrowc         C   sI   | i  d d d | i  d d d d d | i  d	 d d
 d d d  S(   Nt   terminalt
   foregrounds   #006000t   arrowt   fontt   symbolt	   underlinet   0t   nonterminalt   bluet	   helveticait   bold(   s	   helveticais   bold(   t
   tag_config(   t   selft
   textwidgett   options(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   _init_colortagsF   s    c         C   s   g  } | i  d | i   d f  | i  |  i d f  x\ | i   D]N } t | t  o! | i  d | i   d f  qF | i  d | d f  qF W| S(   Ns   %s	R   R	   s    %ss    %rR   (   t   appendt   lhst   ARROWt   rhst
   isinstanceR   R   (   R   t   itemt   contentst   elt(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt
   _item_reprL   s     !(   t   __name__t
   __module__t   SymbolWidgett   SYMBOLSR   R   R   (    (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   C   s   	sM  

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 occurances of that nonterminal
will be highlighted.

Termianals 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 signifigant 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.

t	   CFGEditorc           B   s>  e  Z d  Z e i d Z e i d e d  Z e i d e d  Z	 e i d# e d d  Z
 e i d	 e d
  Z d$ Z e e 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! RS(%   sY  
    A dialog window for creating and editing context free grammars.
    C{CFGEditor} places the following restrictions on what C{CFG}s can
    be edited:
        - All nonterminals must be strings consisting of word
          characters.
        - All terminals must be strings consisting of word characters
          and space characters.
    R   s   (^\s*\w+\s*)(->|(s   ))s   \s*(->|(s   ))\s*s   (^\s*\w+\s*)s   (->|(s#   ((\w+|'[\w ]*'|\"[\w ]*\"|\|)\s*)*$s   \w+|->|'[\w ]+'|"[\w ]+"|(t   )R   iR   c         C   s   | |  _  | d  j	 o | |  _ n t t d  g   |  _ | |  _ d |  _ t |  |  _ |  i	   |  i
   |  i i d d d d d d  |  i   |  i i d d d d	 d d  |  i   |  i i d d
 d d d d  |  i i   d  S(   Nt   Si   t   sidet   topt   fillt   xt   expandi    t   botht   bottom(   t   _parentt   Nonet   _cfgR    R   t   _set_cfg_callbackt    _highlight_matching_nonterminalst   Toplevelt   _topt   _init_bindingst   _init_startframet   _startframet   packt   _init_prodframet
   _prodframet   _init_buttonst   _buttonframet   _textwidgett   focus(   R   t   parentt   cfgt   set_cfg_callback(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   __init__   s    			



c         C   s   t  |  i  } |  _ t |  |  _ |  i i d d  t | d d i d d  t | d d i d d  |  i i d |  i i	   i
    d  S(   NR'   t   rightt   texts   Start Symbol:s   Productions:t   lefti    (   t   FrameR4   R7   t   Entryt   _startR8   t   Labelt   insertR0   t   startR   (   R   t   frame(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR6      s    c      
   C   s  t  |  i  } |  _ t | d d d |  i d d d d i d d  t | d d	 d |  i d d d d i d d  t | d d
 d |  i d d d d i d d  t | d d d |  i d d d d i d d  t | d d d |  i	 d d d d i d d  d  S(   NRD   t   Okt   commandR   i    t	   takefocusR'   RE   t   Applyt   Resett   Cancelt   HelpRC   (
   RF   R4   R<   t   Buttont   _okR8   t   _applyt   _resett   _cancelt   _help(   R   RL   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR;      s    c         C   s^  |  i  i d  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d	 |  i  |  i  i d
 |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  |  i  i d |  i  d  S(   Ns
   CFG Editors   <Control-q>s   <Alt-q>s   <Control-d>s   <Alt-x>s   <Escape>s   <Alt-c>s   <Control-o>s   <Alt-o>s   <Control-a>s   <Alt-a>s   <Control-r>s   <Alt-r>s   <Control-h>s   <Alt-h>s   <F1>(   R4   t   titlet   bindRX   RU   RV   RW   RY   (   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR5      s     c         C   s?  t  |  i  |  _ t |  i d d d d |  _ t |  i d d d d |  _ |  i i d	 |  i i  |  i i d
 |  i i	  |  i i
 d d d d  |  i i
 d d d d d d  |  i i d d d |  i i d d d |  i i d d d d |  _ |  i i d |  i  |  i i d |  i  |  i i d |  i  |  i i d |  i  |  i d  } |  i i d |  g  } |  i i   D]" } | | i   | i   g f q~ } x t t |  d d d   D] } | | d | | d d j o d( | | d j o qn d) | | d d j o qn | | d d GH| | d GH| | d d i | | d  | | =qqWx | D] \ } } | G| GHd! | } xY | D]Q }	 x> |	 D]6 }
 t |
 t  o | d" |
 7} q| d# |
 7} qW| d$ 7} qW| d%  d& } |  i i d' |  qW|  i   d  S(*   Nt
   backgrounds   #e0e0e0t   exportselectioni   RO   i    t   orientt   verticalt   yscrollcommandRN   R'   RC   R)   t   yR+   R,   RE   R   R   s   #006000R	   R
   R   t   errort   redt   >s	   <<Paste>>s
   <KeyPress>s   <ButtonPress>c         S   s   | i    i   d  S(   N(   t   tk_focusNextR>   (   t   eR   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   cycle   s    s   <Tab>is   %s ->s    %ss    %rs    |is   
t   end(    (    (   RF   R4   R:   t   TextR=   t	   Scrollbart   _textscrollt   configt   sett   yviewR8   R   t   _linenumR[   t   _replace_arrowst   _analyzet   _check_analyzeR0   t   productionsR   R   t   ranget   lent   extendR   R   RJ   (   R   Rg   t   _[1]t   pt   prod_tuplest   iR   t   rhsst   sR   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR9      sV    	? ! ! 	
  "c         C   sY   d | } d | } x> |  i  i   D]- } | d j o |  i  i | | |  q$ q$ Wd S(   s   
        Remove all tags (except C{arrow} and C{sel}) from the given
        line of the text widget used for editing the productions.
        s   %d.0s   %d.endR	   t   selN(   s   arrows   sel(   R=   t	   tag_namest
   tag_remove(   R   t   linenumRK   Rh   t   tag(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   _clear_tags.  s    

 c         G   sc   t  |  i i d  i d  d  } | |  i j o* |  i |  |  i |  i  | |  _ n d S(   s   
        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.
        RJ   t   .i    N(   t   intR=   t   indext   splitRo   R   t   _analyze_line(   R   Rf   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRr   9  s
    %c         G   s   d } xp |  i  i d | d  } | d j o Pn |  i  i | | d  |  i  i | |  i d  |  i  i | d  q	 d } xN |  i  i |  i | d d  } | d j o Pn |  i  i d | | d  q d	 S(
   s   
        Replace any C{'->'} text strings with arrows (char \256, in
        symbol font).  This searches the whole buffer, but is fast
        enough to be done anytime they press '>'.
        s   1.0s   ->s	   end+1chart    s   +2charR	   s   	s   +1charN(   R=   t   searcht   deleteRJ   R   t   tag_add(   R   Rf   R	   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRp   E  s    	c         C   s   | i    d d j o
 d } n^ | i    d |  i f j o
 d } n8 d | i    } | |  i i   j o |  i |  n d | | i   f } d | | i   f } |  i i | | |  d S(	   s   
        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).
        i    s   '"R   s   ->R	   t   nonterminal_s   %d.%dN(   t   groupR   R=   R~   t   _init_nonterminal_tagRK   Rh   R   (   R   t   matchR   R   RK   Rh   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   _analyze_tokenZ  s    !&R   c         C   s   |  i  i | d | d t i |  i p d  Sn |  i  | d  } |  i  | d  } |  i  i | d |  |  i  i | d |  d  S(   NR   R
   c         S   s   | i  | d d d  S(   NR\   s   #80ff80(   R   (   Rf   R   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   enteru  s    c         S   s   | i  | d d d  S(   NR\   R   (   R   (   Rf   R   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   leavew  s    s   <Enter>s   <Leave>(   R=   R   R$   t   _BOLDR2   t   tag_bind(   R   R   R   R   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   p  s    

c         C   s   |  i  |  |  i i | d | d  } t i i |  o& |  | d  } t i i | |  n( | i   d j o |  i	 | |  n d S(   s(   
        Colorize a given line.
        s   .0s   .endc         S   s   | i  |  |  d S(   NR   (   R   (   R   R   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   analyze_token  s    R   N(
   R   R=   t   getR$   t   _PRODUCTION_RER   t	   _TOKEN_REt   subt   stript   _mark_error(   R   R   t   lineR   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   |  s    c         C   s   t  i i |  } | p d | } d | } nX t  i i |  p$ d | } d | | i   f } n! d | | i   f } d | } |  i i | d |  o d | } d | } n |  i i	 d | |  d S(   s:   
        Mark the location of an error in a line.
        s   %d.0s   %d.ends   %d.%ds   ==Rb   N(
   R$   t	   _ARROW_RER   t   _LHS_RER   RK   Rh   R=   t   compareR   (   R   R   R   t
   arrowmatchRK   Rh   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR     s    



c         G   s^   |  i    t |  i i d  i d  d  } x( t d | d  D] } |  i |  qC Wd S(   sL   
        Replace C{->} with arrows, and colorize the entire buffer.
        Rh   R   i    i   N(   Rp   R   R=   R   R   Rt   R   (   R   Rf   t   numlinesR   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRq     s
    
% c         C   s   g  } |  i  i d d  } t i |  i d |  } t i d d |  } | i d  } x> | D]6 } | i   } | d j o q^ n | t |  7} q^ W| S(   so   
        Parse the current contents of the textwidget buffer, to create
        a list of productions.
        s   1.0Rh   s   ->s   	t    s   
R   (   R=   R   t   reR   R   R   R   R   (   R   Rs   RD   t   linesR   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   _parse_productions  s     c         G   s2   |  i  d  j o d  Sn |  i  i   d  |  _  d  S(   N(   R4   R/   t   destroy(   R   Rf   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   _destroy  s    c         G   s   |  i    |  i   d  S(   N(   RV   R   (   R   Rf   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRU     s    
c         G   sU   |  i    } t |  i i    } t | |  } |  i d  j	 o |  i |  n d  S(   N(   R   R   RH   R   R    R1   R/   (   R   Rf   Rs   RK   R@   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRV     s
    c         G   sv   |  i  i d d  x. |  i i   D] } |  i  i d d |  q# W|  i   |  i d  j	 o |  i |  i  n d  S(   Ns   1.0Rh   s   %s
(   R=   R   R0   Rs   RJ   Rq   R1   R/   (   R   Rf   t
   production(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRW     s     
c         G   s&   y |  i    Wn n X|  i   d  S(   N(   RW   R   (   R   Rf   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRX     s    c         G   sV   y) t  |  i d t i   d d d d Wn& t  |  i d t i   d d n Xd  S(   Ns   Help: Chart Parser Demot   widthiK   R
   t   fixed(   t   ShowTextR.   t   _CFGEditor_HELPR   (   R   Rf   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRY     s    s   (^\s*\w+\s*)(->|((   s	   helveticais   bold("   R    R!   t   __doc__R"   R#   R   R   t   compileR   R   R   R   R   R/   RB   R6   R;   R5   R9   R   Rr   Rp   R   R   R   R   Rq   R   R   RU   RV   RW   RX   RY   (    (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR$      s:   	
				T									$					t   CFGDemoc           B   s   e  Z d    Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 e d	  Z d
   Z d   Z d   Z RS(   c         C   s   | |  _  | |  _ t   |  _ |  i i d  t |  i  |  _ |  i i d  |  i |  i  t	 |  i  } | i
 d d d d d d  |  i |  i  |  i |  i  |  i |  |  i |  |  i |  i  d  S(	   Ns   Context Free Grammar Demoi   R'   RE   R)   Ra   R+   i    (   t   _grammart   _textt   TkR4   RZ   t   IntVart   _sizeRm   R5   RF   R8   t   _init_menubarR;   t   _init_grammart   _init_treelett   _init_workspace(   R   t   grammarRD   t   frame1(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyRB     s    		c         C   s   | i  d |  i  d  S(   Ns   <Control-q>(   R[   R   (   R   R(   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR5     s    c         C   s   d  S(   N(    (   R   R?   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   !  s    c         C   s   d  S(   N(    (   R   R?   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR;   #  s    c         C   sw   t  | |  i d d |  _ |  i i d d d d d d  |  i i   |  i i d	 |  i  |  i i d
 |  i  d  S(   NR   i   R'   R(   R)   R,   R+   i   t   selectt   move(   R   R   t	   _prodlistR8   R>   t   add_callbackt   _selectprod_cb(   R   R?   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   %  s
    c         C   s;   t  | d d |  _ |  i i d d d d  d  |  _ d  S(   NR\   t   whiteR'   R-   R)   R*   (   t   Canvast   _treelet_canvasR8   R/   t   _treelet(   R   R?   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   ,  s    c         C   sK   t  | d d |  _ |  i i d d d d d d  d  |  _ |  i   d  S(	   NR\   R   R'   RC   R)   R,   R+   i   (   t   CanvasFramet
   _workspaceR8   R/   t   _treet   reset_workspace(   R   R?   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   1  s    	c   
   	   C   sO  |  i  i   } t |  i i    } d | d d f } d | d f } |  i d  j	 o |  i  i |  i  n |  i i	   i
   } t | | d | d d } g  } xS |  i D]H } t | t  o | i   } n | i t | | d | d d  q Wt | | | d d	 |  _ |  i  i |  i  x | D] }	 |	 i d
 d  q1Wd  S(   NR   i   R   i   R
   t	   draggablei   t   colorR   i    id   (   R   t   canvasR   R   R   R   R/   t   remove_widgetR   RK   R   t
   TextWidgetR   R   t   Tokent   typeR   t   TreeSegmentWidgett
   add_widgetR   (
   R   t   ct   fontsizet	   node_fontt	   leaf_fontRK   t   rootnodet   leavest   wordt   leaf(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   ;  s$    
  & c         C   s   d  S(   N(    (   R   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   workspace_markprod\  s    c         C   s1  | d  j o |  i } n xt t | i    t | i     D] } | d | f d j o |  i n x t | i    D] \ } } | i   | | } t | t	  o0 t | t
  o  | i | i   i   j o q~ t | t t f  o' t | t  o | | i   j o q~ Pq~ Wd G| GHqC Wd  S(   NR   R   s   MATCH AT(   R/   R   Rt   Ru   t   subtreesR   t   _markproductiont	   enumerateR   R   R   R   t   nodeRD   t   strt   unicodeR   (   R   t   prodt   treeRz   t   jR   t   widget(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   _  s$    )  c      	   C   s{  |  i  } |  i i |  |  i d  j	 o |  i i   n | i   } x: t |  D], \ } } t | t	  o t
 |  } qS qS Wt
 | i   i   |  } t |  i i    } d | d d f } d | d f }	 t | | d | d |	 |  _ d |  i d <|  i i   \ }
 } } } t | d	  t | d
  } } |  i i | |
 | d | | | d  |  i |  d  S(   NR   i   R   i   R   R   i   R   R   t   height(   R   R   t	   highlightR   R/   R   R   R   R   R   R   R   R   R   R   R   t   tree_to_treesegmentt   bboxR   R   (   R   R   R   R   Rz   R   R   R   R   R   t   x1t   y1t   x2t   y2t   wt   h(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR   x  s&    	! $!+c         G   s   |  i  i   d  S(   N(   R4   R   (   R   t   args(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR     s    c         O   s   |  i  i | |   d  S(   N(   R4   t   mainloop(   R   R   t   kwargs(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR     s    (   R    R!   RB   R5   R   R;   R   R   R   R   R   R/   R   R   R   R   (    (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR     s   							
	!			c          C   s  d d k  l }  l } l } d } g  } | i   D] } | |  |  q3 ~ \	 } } } }	 }
 } } } } | | | | 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 i   } t | |  } | i   d  S(   Ni(   R   t
   ProductionR    s   S VP NP PP P N Name V Dett   upt   overt   It   thet   at   mant   sawt   int   witht   parkt   dogt   statuet   mys   I saw a man in the park(   t   nltkR   R   R    R   R   R   (   R   R   R    t   nonterminalsRw   R|   R&   t   VPt   NPt   PPt   Pt   Nt   Namet   Vt   DetRs   R   RD   t   d(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   demo2  s.    Ac          C   s   d d k  l }  l } d } g  } | i   D] } | |  |  q- ~ \	 } } } } }	 }
 } } } | d  } d   } t   } t | | |  } t | d d i   t | d d d	 | i	 i   | i
   d  S(
   Ni(   R   t	   parse_cfgs   S VP NP PP P N Name V Dets+  
    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         S   s	   |  GHd  S(   N(    (   R   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   cb  s    RD   s   
Testing CFG Editor
t   QuitRN   (   R   R   R  R   R   R$   RI   R8   RT   R   R   (   R   R  R   Rw   R|   R&   R  R  R  R  R  R  R  R  R   R  R(   t   editor(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   demo  s    A			c          C   s$  d d k  l }  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   } | d  } | i d |  t | |
  } | i d d d d  | i d | i  | i d | i  | i	   | i
 |
 d  | i
 |
 d  d  S(   Ni(   R   s!   S, VP, NP, PP, P, N, Name, V, DetR   R   R   R   R   R   R   R   R   R   R   R   R   c         S   s   | i    d  S(   N(   R   (   Rf   t   t(    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyR     s    t   qR+   i   R)   R,   R   R   i   i   (   R   R   R   R   R[   R   R8   R   t   markonlyR>   t   mark(   R   R&   R  R  R  R  R  R  R  R  Rs   R  R   Rx   (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pyt   demo3  s6    '	
t   __main__(   R   R   t   nltk.grammarR    R   R   R   R   t   utilR   t   ColorizedListR   R   t   objectR$   R   R
  R  R  R    (    (    (    s#   /p/zhu/06/nlp/nltk/nltk/draw/cfg.pys   <module>   s   *

A |	$	#	&