³ò
3ÒÇIc           @   sC   d  e  f d „  ƒ  YZ d e  f d „  ƒ  YZ d d d „  ƒ  YZ d S(   t
   SortedDictc           B   sV   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   s·  
    A very rudamentary sorted dictionary, whose main purpose is to
    allow dictionaries to be displayed in a consistent order in
    regression tests.  keys(), items(), values(), iter*(), and
    __repr__ all sort their return values before returning them.
    (note that the sort order for values() does *not* correspond to
    the sort order for keys().  I.e., zip(d.keys(), d.values()) is not
    necessarily equal to d.items().
    c         C   s   t  t i |  ƒ ƒ S(   N(   t   sortedt   dictt   keys(   t   self(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR      s    c         C   s   t  t i |  ƒ ƒ S(   N(   R   R   t   items(   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR      s    c         C   s   t  t i |  ƒ ƒ S(   N(   R   R   t   values(   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR      s    c         C   s   t  t t i |  ƒ ƒ ƒ S(   N(   t   iterR   R   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   iterkeys   s    c         C   s   t  t t i |  ƒ ƒ ƒ S(   N(   R   R   R   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt	   iteritems   s    c         C   s   t  t t i |  ƒ ƒ ƒ S(   N(   R   R   R   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt
   itervalues   s    c         C   s   t  t t i |  ƒ ƒ ƒ S(   N(   R   R   R   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __iter__   s    c         C   sB   g  } t  |  i ƒ  ƒ D] } | d | q ~ } d d i | ƒ S(   Ns   %s=%ss   {%s}s   , (   R   R   t   join(   R   t   _[1]t   tR   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   repr   s    1(   t   __name__t
   __module__t   __doc__R   R   R   R   R	   R
   R   R   (    (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR       s   								t   OrderedDictc           B   s€   e  Z d  Z h  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 e
 d „ Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   sg   
    This implementation of a dictionary keeps track of the order
    in which keys were inserted.
    c         C   s#   | i  ƒ  |  _ t i |  | ƒ d  S(   N(   R   t   _keysR   t   __init__(   R   t   d(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   &   s    c         C   s$   t  i |  | ƒ |  i i | ƒ d  S(   N(   R   t   __delitem__R   t   remove(   R   t   key(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   *   s    c         C   s[   t  i |  | | ƒ t |  d ƒ p | g |  _ n | |  i j o |  i i | ƒ n d  S(   NR   (   R   t   __setitem__t   hasattrR   t   append(   R   R   t   item(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   .   s
    c         C   s   t  i |  ƒ g  |  _ d  S(   N(   R   t   clearR   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   7   s    c         c   s'   x  |  i  D] } | |  | f Vq
 Wd  S(   N(   R   (   R   t   i(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   ;   s    
 c         C   s   |  i  S(   N(   R   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   ?   s    c         C   sR   t  |  i ƒ d j o t d ƒ ‚ n) |  i d } |  | } |  | =| | f Sd  S(   Ni    s   dictionary is emptyiÿÿÿÿ(   t   lenR   t   KeyError(   R   R   t   val(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   popitemB   s    
c         C   s;   t  i |  | | ƒ | |  i j o |  i i | ƒ n d  S(   N(   R   t
   setdefaultR   R   (   R   R   t   failobj(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR$   K   s    c         C   sL   x5 | i  ƒ  D]' } | |  j o |  i i | ƒ q q Wt i |  | ƒ d  S(   N(   R   R   R   R   t   update(   R   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR&   P   s
     c         c   s!   x |  i  D] } |  | Vq
 Wd  S(   N(   R   (   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   V   s    
 c         C   st   y |  i  i | ƒ } Wn t j
 o t | ƒ ‚ n X|  i  i | | ƒ | | j o | d } n |  i  | =d S(   s<    Move the specified to key to *before* the specified index. i   N(   R   t   indext
   ValueErrorR!   t   insert(   R   R   R'   t   cur(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   moveZ   s    c         C   s-   | |  j o t  | ƒ ‚ n |  i i | ƒ S(   N(   R!   R   R'   (   R   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR'   g   s    (   R   R   R   R   R   R   R   R   R   R#   t   NoneR$   R&   R   R+   R'   (    (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR       s   											t   Triec           B   s†   e  Z d  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z RS(   sÌ   A Trie is like a dictionary in that it maps keys to
    values. However, because of the way keys are stored, it allows
    look up based on the longest prefix that matches.  Keys must be
    strings.
    c         C   s0   | d  j o d  h  d g |  _ n
 | |  _ d  S(   Ni    (   R,   t   _root(   R   t   trie(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   {   s    c         C   s   d  h  d g |  _ d  S(   Ni    (   R,   R.   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR      s    c         C   sQ   |  i  } x7 | D]/ } | d } | | j o | | } q t Sq W| d t j	 S(   sW   Return True if the key is present and it's a leaf of the
        Trie, False otherwise.i   i    (   R.   t   FalseR,   (   R   R   t	   curr_nodet   chart   curr_node_1(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   isleaf„   s    	 
c         C   si   |  i  } | } xI | D]A } | | d j o | d | } n | d | f S| d } q W| d | f S(   s­   Find as much of the key as one can, by using the longest
        prefix that has a value.  Return (value, remainder) where
        remainder is the rest of the given string.i   i    (   R.   (   R   R   R1   t	   remainderR2   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   find_prefix‘   s    	 c         C   s5   |  i  } x | D] } | d | } q Wt d | ƒ S(   Ni   R/   (   R.   R-   (   R   R   R1   R2   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   subtrie    s
    	 c         C   s   |  i  d S(   Ni   (   R.   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __len__¦   s    c         C   s   |  i  | i  j S(   N(   R.   (   R   t   other(    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __eq__©   s    c         C   s   |  | j S(   N(    (   R   R9   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __ne__¬   s    c         C   sg   |  i  } x= | D]5 } | d c d 7<| d i | d  h  d g ƒ } q W| | d <| d c d 7<d  S(   Ni   i   i    (   R.   R$   R,   (   R   R   t   valueR1   R2   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR   ¯   s    	 #
c         C   s0   |  i  } x | D] } | d | } q W| d S(   s¦   Return the value for the given key if it is present, raises
        a KeyError if key not found, and return None if it is present
        a key2 that starts with key.i   i    (   R.   (   R   R   R1   R2   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __getitem__·   s
    	 c         C   sG   |  i  } x7 | D]/ } | d } | | j o | | } q t Sq Wt S(   sa   Return True if the key is present or if it is present a
        key2 string that starts with key.i   (   R.   R0   t   True(   R   R   R1   R2   R3   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __contains__Á   s    	 
c         C   s   t  |  i ƒ S(   N(   t   strR.   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __str__Î   s    c         C   s   d |  i  S(   Ns   Trie(%r)(   R.   (   R   (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyt   __repr__Ñ   s    (   R   R   R   R,   R   R   R4   R6   R7   R8   R:   R;   R   R=   R?   RA   RB   (    (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pyR-   t   s   									
		N(    (   R   R    R   R-   (    (    (    s%   /p/zhu/06/nlp/nltk/nltk/containers.pys   <module>   s   T