³ò
4ÒÇIc           @   st   d  d k  Z  d  d k l Z l Z l Z d e f d „  ƒ  YZ d e e f d „  ƒ  YZ d e e f d „  ƒ  YZ d S(	   iÿÿÿÿN(   t
   deprecatedt
   Deprecatedt
   overriddent   ParserIc           B   sÎ   e  Z d  Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z	 e d „ Z
 d „  Z d	 „  Z e d
 ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z e d ƒ d „  ƒ Z RS(   s”  
    A processing class for deriving trees that represent possible
    structures for a sequence of tokens.  These tree structures are
    known as X{parses}.  Typically, parsers are used to derive syntax
    trees for sentences.  But parsers can also be used to derive other
    kinds of tree structure, such as morphological trees and discourse
    structures.
    
    Subclasses must define:
      - at least one of: L{parse()}, L{nbest_parse()}, L{iter_parse()},
        L{batch_parse()}, L{batch_nbest_parse()}, L{batch_iter_parse()}.

    Subclasses may define:
      - L{grammar()}
      - either L{prob_parse()} or L{batch_prob_parse()} (or both)
    c         C   s   t  ƒ  ‚ d S(   s;   
        @return: The grammar used by this parser.
        N(   t   NotImplementedError(   t   self(    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt   grammar   s    c         C   sU   t  |  i ƒ o |  i | g ƒ d Sn* |  i | d ƒ } | o | d Sn d Sd S(   sF  
        @return: A parse tree that represents the structure of the
        given sentence, or C{None} if no parse tree is found.  If
        multiple parses are found, then return the best parse.
        
        @param sent: The sentence to be parsed
        @type sent: L{list} of L{string}
        @rtype: L{Tree}
        i    i   N(   R   t   batch_parset   nbest_parset   None(   R   t   sentt   trees(    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt   parse%   s
    
c         C   s—   t  |  i ƒ o |  i | g | ƒ d Sni t  |  i ƒ p t  |  i ƒ o) |  i | ƒ } | o | g Sq“ g  Sn  t t i |  i | ƒ | ƒ ƒ Sd S(   sû  
        @return: A list of parse trees that represent possible
        structures for the given sentence.  When possible, this list is
        sorted from most likely to least likely.  If C{n} is
        specified, then the returned list will contain at most C{n}
        parse trees.
        
        @param sent: The sentence to be parsed
        @type sent: L{list} of L{string}
        @param n: The maximum number of trees to return.
        @type n: C{int}
        @rtype: C{list} of L{Tree}
        i    N(   R   t   batch_nbest_parseR   R   t   listt	   itertoolst   islicet
   iter_parse(   R   R
   t   nt   tree(    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR   6   s     c         C   sÁ   t  |  i ƒ o |  i | g ƒ d Sn– t  |  i ƒ p t  |  i ƒ o t |  i | ƒ ƒ Sn_ t  |  i ƒ p t  |  i ƒ o5 |  i | ƒ } | o t | g ƒ Sq½ t g  ƒ Sn
 t ƒ  ‚ d S(   sZ  
        @return: An iterator that generates parse trees that represent
        possible structures for the given sentence.  When possible,
        this list is sorted from most likely to least likely.
        
        @param sent: The sentence to be parsed
        @type sent: L{list} of L{string}
        @rtype: C{iterator} of L{Tree}
        i    N(   R   t   batch_iter_parseR   R   t   iterR   R   R   (   R   R
   R   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR   M   s    
  c         C   s2   t  |  i ƒ o |  i | g ƒ d Sn t ‚ d S(   sš  
        @return: A probability distribution over the possible parse
        trees for the given sentence.  If there are no possible parse
        trees for the given sentence, return a probability distribution
        that assigns a probability of 1.0 to C{None}.
        
        @param sent: The sentence to be parsed
        @type sent: L{list} of L{string}
        @rtype: L{ProbDistI} of L{Tree}
        i    N(   R   t   batch_prob_parseR   (   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt
   prob_parseb   s    c         C   s(   g  } | D] } | |  i  | ƒ q ~ S(   s¬   
        Apply L{self.parse()} to each element of C{sents}.  I.e.:

            >>> return [self.parse(sent) for sent in sents]

        @rtype: C{list} of L{Tree}
        (   R   (   R   t   sentst   _[1]R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR   r   s    c         C   s+   g  } | D] } | |  i  | | ƒ q ~ S(   sÆ   
        Apply L{self.nbest_parse()} to each element of C{sents}.  I.e.:

            >>> return [self.nbest_parse(sent, n) for sent in sents]

        @rtype: C{list} of C{list} of L{Tree}
        (   R   (   R   R   R   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR   |   s    c         C   s(   g  } | D] } | |  i  | ƒ q ~ S(   sÅ   
        Apply L{self.iter_parse()} to each element of C{sents}.  I.e.:

            >>> return [self.iter_parse(sent) for sent in sents]

        @rtype: C{list} of C{iterator} of L{Tree}
        (   R   (   R   R   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR   †   s    c         C   s(   g  } | D] } | |  i  | ƒ q ~ S(   sÆ   
        Apply L{self.prob_parse()} to each element of C{sents}.  I.e.:

            >>> return [self.prob_parse(sent) for sent in sents]

        @rtype: C{list} of L{ProbDistI} of L{Tree}
        (   R   (   R   R   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR      s    s   Use parse() instead.c         C   s   |  i  | ƒ S(   N(   R   (   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt	   get_parse   s    s   Use nbest_parse() instead.c         C   s   |  i  | ƒ S(   N(   R   (   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt   get_parse_list    s    s   Use prob_parse() instead.c         C   s   |  i  | ƒ S(   N(   R   (   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt   get_parse_prob£   s    c         C   s   |  i  | ƒ S(   N(   R   (   R   R
   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt   get_parse_dict¦   s    s   No longer supported.c         C   s”   t  | ƒ } x | D]y } | i ƒ  } | p q n | i d ƒ o | GHq n d G| GH|  i | ƒ } d t | ƒ GHx | D] } | GHq} Wq Wd  S(   Nt   #s	   Sentence:s
   %d parses.(   t   opent   stript
   startswithR   t   len(   R   t   filenamet   ft   linet   parsesR   (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt
   batch_test©   s     	 (   t   __name__t
   __module__t   __doc__R   R   R	   R   R   R   R   R   R   R   R    R   R   R   R   R'   (    (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR      s   					

	
	t   ParseIc           B   s   e  Z d  Z RS(   s   Use ParserI instead.(   R(   R)   R*   (    (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR+   »   s   t   AbstractParserc           B   s#   e  Z d  Z e d ƒ d „  ƒ Z RS(   s   Use ParserI instead.s5   Use nltk.ContextFreeGrammar.check_coverage() instead.c         C   s   |  i  i | ƒ d  S(   N(   t   _grammart   check_coverage(   R   t   tokens(    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyt   _check_coverage¿   s    (   R(   R)   R*   R    R0   (    (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pyR,   ½   s   (	   R   t   nltk.internalsR    R   R   t   objectR   R+   R,   (    (    (    s$   /p/zhu/06/nlp/nltk/nltk/parse/api.pys   <module>
   s   ­