ó
ù`]c           @  s  d  d l  m Z d  d l m Z d  d l m Z m Z d  d l m Z d  d l	 m
 Z
 d  d l m Z m Z e e ƒ e d e f d „  ƒ  Yƒ ƒ Z e d	 e f d
 „  ƒ  Yƒ Z e e d e f d „  ƒ  Yƒ ƒ Z e d e f d „  ƒ  Yƒ Z e d e f d „  ƒ  Yƒ Z d S(   iÿÿÿÿ(   t   unicode_literals(   t   total_ordering(   t   ABCMetat   abstractmethod(   t   add_metaclass(   t   raise_unorderable_types(   t   python_2_unicode_compatiblet   unicode_reprt   AbstractCCGCategoryc           B  sŒ   e  Z d  Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z e d „  ƒ Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z RS(   u;   
    Interface for categories in combinatory grammars.
    c         C  s   d S(   u<   
        Returns true if the category is primitive.
        N(    (   t   self(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   is_primitive   t    c         C  s   d S(   uI   
        Returns true if the category is a function application.
        N(    (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   is_function   R   c         C  s   d S(   u=   
        Returns true if the category is a variable.
        N(    (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   is_var$   R   c         C  s   d S(   u–   
        Takes a set of (var, category) substitutions, and replaces every
        occurrence of the variable with the corresponding category.
        N(    (   R	   t   substitutions(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt
   substitute*   R   c         C  s   d S(   u·   
        Determines whether two categories can be unified.
         - Returns None if they cannot be unified
         - Returns a list of necessary substitutions if they can.
        N(    (   R	   t   other(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt	   can_unify1   R   c         C  s   d  S(   N(    (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __str__:   s    c         C  s"   |  j  | j  k o! |  j | j k S(   N(   t	   __class__t   _comparison_key(   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __eq__>   s    c         C  s   |  | k S(   N(    (   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __ne__D   s    c         C  s^   t  | t ƒ s" t d |  | ƒ n  |  j | j k rD |  j | j k  S|  j j | j j k  Sd  S(   Nu   <(   t
   isinstanceR   R   R   R   t   __name__(   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __lt__G   s
    c         C  s9   y |  j  SWn' t k
 r4 t |  j ƒ |  _  |  j  SXd  S(   N(   t   _hasht   AttributeErrort   hashR   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __hash__O   s
    (   R   t
   __module__t   __doc__R   R
   R   R   R   R   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR      s   				t   CCGVarc           B  s}   e  Z d  Z d Z e d „ Z e d „  ƒ Z e d „  ƒ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z RS(   u   
    Class representing a variable CCG category.
    Used for conjunctions (and possibly type-raising, if implemented as a
    unary rule).
    i    c         C  s(   |  j  ƒ  |  _ | |  _ |  j |  _ d S(   u×   Initialize a variable (selects a new identifier)

        :param prim_only: a boolean that determines whether the variable is
                          restricted to primitives
        :type prim_only: bool
        N(   t   new_idt   _idt
   _prim_onlyR   (   R	   t	   prim_only(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __init__a   s    	c         C  s   |  j  d |  _  |  j  d S(   uT   
        A class method allowing generation of unique variable identifiers.
        i   (   t   _maxID(   t   cls(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR!   l   s    c         C  s   d |  _  d  S(   Ni    (   R&   (   R'   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   reset_idt   s    c         C  s   t  S(   N(   t   False(   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR
   x   s    c         C  s   t  S(   N(   R)   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   {   s    c         C  s   t  S(   N(   t   True(   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   ~   s    c         C  s+   x$ | D] \ } } | |  k r | Sq W|  S(   ul   If there is a substitution corresponding to this variable,
        return the substituted category.
        (    (   R	   R   t   vart   cat(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR      s    c         C  s'   | j  ƒ  s |  j r# |  | f g Sd S(   uX    If the variable can be replaced with other
        a substitution is returned.
        N(   R
   R#   t   None(   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   Š   s    c         C  s   |  j  S(   N(   R"   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   id’   s    c         C  s   d t  |  j ƒ S(   Nu   _var(   t   strR"   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   •   s    (   R   R   R   R&   R)   R%   t   classmethodR!   R(   R
   R   R   R   R   R.   R   (    (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR    W   s   							t	   Directionc           B  sž   e  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 d „  Z d „  Z d „  Z d „  Z d „  Z RS(   u¨   
    Class representing the direction of a function application.
    Also contains maintains information as to which combinators
    may be used with the category.
    c         C  s+   | |  _  | |  _ | t | ƒ f |  _ d  S(   N(   t   _dirt   _restrst   tupleR   (   R	   t   dirt   restrictions(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR%   ¢   s    		c         C  s   |  j  d k S(   Nu   /(   R2   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt
   is_forward¨   s    c         C  s   |  j  d k S(   Nu   \(   R2   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   is_backward«   s    c         C  s   |  j  S(   N(   R2   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR5   ®   s    c         C  s   |  j  S(   u8  A list of restrictions on the combinators.
        '.' denotes that permuting operations are disallowed
        ',' denotes that function composition is disallowed
        '_' denotes that the direction has variable restrictions.
        (This is redundant in the current implementation of type-raising)
        (   R3   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   restrs±   s    c         C  s   |  j  d k S(   Nu   _(   R3   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   is_variableº   s    c         C  s^   | j  ƒ  r d |  j ƒ  f g S|  j  ƒ  r> d | j ƒ  f g S|  j ƒ  | j ƒ  k rZ g  Sd  S(   Nu   _(   R:   R9   R-   (   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   À   s    c         C  sG   |  j  ƒ  s |  Sx0 | D]( \ } } | d k r t |  j | ƒ Sq W|  S(   Nu   _(   R:   R1   R2   (   R	   t   subsR+   R9   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   Ê   s    c         C  s   d |  j  k S(   Nu   ,(   R3   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   can_composeÔ   s    c         C  s   d |  j  k S(   Nu   .(   R3   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt	   can_cross×   s    c         C  s"   |  j  | j  k o! |  j | j k S(   N(   R   R   (   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   Ú   s    c         C  s   |  | k S(   N(    (   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   à   s    c         C  s^   t  | t ƒ s" t d |  | ƒ n  |  j | j k rD |  j | j k  S|  j j | j j k  Sd  S(   Nu   <(   R   R1   R   R   R   R   (   R	   R   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   ã   s
    c         C  s9   y |  j  SWn' t k
 r4 t |  j ƒ |  _  |  j  SXd  S(   N(   R   R   R   R   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   ë   s
    c         C  s9   d } x |  j  D] } | d | } q Wd |  j | f S(   Nu    u   %su   %s%s(   R3   R2   (   R	   t   r_strt   r(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   ò   s    c         C  s3   |  j  d k r t d |  j ƒ St d |  j ƒ Sd  S(   Nu   /u   \(   R2   R1   R3   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   __neg__ù   s    (   R   R   R   R%   R7   R8   R5   R9   R:   R   R   R<   R=   R   R   R   R   R   R@   (    (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR1   ™   s"   								
	
							t   PrimitiveCategoryc           B  sb   e  Z d  Z g  d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z RS(
   u«   
    Class representing primitive categories.
    Takes a string representation of the category, and a
    list of strings specifying the morphological subcategories.
    c         C  s+   | |  _  | |  _ | t | ƒ f |  _ d  S(   N(   t   _categR3   R4   R   (   R	   t   categR6   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR%     s    		c         C  s   t  S(   N(   R*   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR
     s    c         C  s   t  S(   N(   R)   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR     s    c         C  s   t  S(   N(   R)   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR     s    c         C  s   |  j  S(   N(   R3   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR9     s    c         C  s   |  j  S(   N(   RB   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyRC     s    c         C  s   |  S(   N(    (   R	   R;   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR     s    c         C  ss   | j  ƒ  s d  S| j ƒ  r) | |  f g S| j ƒ  |  j ƒ  k ro x' |  j D] } | | j ƒ  k rK d  SqK Wg  Sd  S(   N(   R
   R-   R   RC   R3   R9   (   R	   R   t   restr(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   #  s    c         C  sK   |  j  g  k r d |  j Sd d j d „  |  j  Dƒ ƒ } d |  j | f S(   Nu   %su   [%s]u   ,c         s  s   |  ] } t  | ƒ Vq d  S(   N(   R   (   t   .0R?   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pys	   <genexpr>2  s    u   %s%s(   R3   RB   t   join(   R	   R6   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   /  s     (   R   R   R   R%   R
   R   R   R9   RC   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyRA      s   							t   FunctionalCategoryc           B  sh   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z RS(   uœ   
    Class that represents a function application category.
    Consists of argument and result categories, together with
    an application direction.
    c         C  s1   | |  _  | |  _ | |  _ | | | f |  _ d  S(   N(   t   _rest   _argR2   R   (   R	   t   rest   argR5   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR%   >  s    			c         C  s   t  S(   N(   R)   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR
   D  s    c         C  s   t  S(   N(   R*   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   G  s    c         C  s   t  S(   N(   R)   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   J  s    c         C  sI   |  j  j | ƒ } |  j j | ƒ } |  j j | ƒ } t | | |  j ƒ S(   N(   RH   R   R2   RI   RG   (   R	   R;   t   sub_rest   sub_dirt   sub_arg(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   O  s    c         C  sµ   | j  ƒ  r | |  f g S| j ƒ  r± |  j j | j ƒ  ƒ } |  j j | j ƒ  ƒ } | d  k	 r± | d  k	 r± |  j j	 | ƒ j | j
 ƒ  j	 | ƒ ƒ } | d  k	 r® | | Sq± n  d  S(   N(   R   R   RH   R   RJ   R2   R5   R-   RI   R   RK   (   R	   R   t   sat   sdt   sb(    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   W  s    *c         C  s   |  j  S(   N(   RI   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyRK   d  s    c         C  s   |  j  S(   N(   RH   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyRJ   g  s    c         C  s   |  j  S(   N(   R2   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR5   j  s    c         C  s   d |  j  |  j |  j f S(   Nu   (%s%s%s)(   RH   R2   RI   (   R	   (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyR   m  s    (   R   R   R   R%   R
   R   R   R   R   RK   RJ   R5   R   (    (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyRG   6  s   									N(   t
   __future__R    t	   functoolsR   t   abcR   R   t   sixR   t   nltk.internalsR   t   nltk.compatR   R   t   objectR   R    R1   RA   RG   (    (    (    s+   lib/python2.7/site-packages/nltk/ccg/api.pyt   <module>   s"   	DAe5