ó
ù`]c           @  sZ  d  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 e 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 e	 d e f d „  ƒ  Yƒ Z d „  Z d „  Z e e ƒ  e ƒ Z e e ƒ  e ƒ Z e	 d e f d „  ƒ  Yƒ Z d „  Z d „  Z d „  Z d „  Z e e ƒ  e ƒ Z e e ƒ  e ƒ Z e e ƒ  e d d ƒZ e	 d e f d „  ƒ  Yƒ Z d „  Z d „  Z  e e ƒ  e ƒ Z! e e ƒ  e  d ƒ Z" d „  Z# e	 d  e f d! „  ƒ  Yƒ Z$ d" „  Z% d# „  Z& e e$ ƒ  e% ƒ Z' e e$ ƒ  e& ƒ Z( d$ S(%   u   
CCG Combinators
iÿÿÿÿ(   t   unicode_literals(   t   ABCMetat   abstractmethod(   t   add_metaclass(   t   python_2_unicode_compatible(   t   FunctionalCategoryt   UndirectedBinaryCombinatorc           B  s,   e  Z d  Z e d „  ƒ Z e d „  ƒ Z RS(   u«  
    Abstract class for representing a binary combinator.
    Merely defines functions for checking if the function and argument
    are able to be combined, and what the resulting category is.

    Note that as no assumptions are made as to direction, the unrestricted
    combinators can perform all backward, forward and crossed variations
    of the combinators; these restrictions must be added in the rule
    class.
    c         C  s   d  S(   N(    (   t   selft   functiont   argument(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   can_combine    s    c         C  s   d  S(   N(    (   R   R   R	   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   combine$   s    (   t   __name__t
   __module__t   __doc__R   R
   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR      s   t   DirectedBinaryCombinatorc           B  s,   e  Z d  Z e d „  ƒ Z e d „  ƒ Z RS(   uÝ   
    Wrapper for the undirected binary combinator.
    It takes left and right categories, and decides which is to be
    the function, and which the argument.
    It then decides whether or not they can be combined.
    c         C  s   d  S(   N(    (   R   t   leftt   right(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   2   s    c         C  s   d  S(   N(    (   R   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   6   s    (   R   R   R   R   R
   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   )   s   t   ForwardCombinatorc           B  s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   uÏ   
    Class representing combinators where the primary functor is on the left.

    Takes an undirected combinator, and a predicate which adds constraints
    restricting the cases in which it may apply.
    u    c         C  s   | |  _  | |  _ | |  _ d  S(   N(   t   _combinatort
   _predicatet   _suffix(   R   t
   combinatort	   predicatet   suffix(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   __init__D   s    		c         C  s%   |  j  j | | ƒ o$ |  j | | ƒ S(   N(   R   R
   R   (   R   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   I   s    c         c  s)   x" |  j  j | | ƒ D] } | Vq Wd  S(   N(   R   R   (   R   R   R   t   cat(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   N   s    c         C  s   d |  j  |  j f S(   Nu   >%s%s(   R   R   (   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   __str__R   s    (   R   R   R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   ;   s
   		t   BackwardCombinatorc           B  s5   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z RS(   uA   
    The backward equivalent of the ForwardCombinator class.
    u    c         C  s   | |  _  | |  _ | |  _ d  S(   N(   R   R   R   (   R   R   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   \   s    		c         C  s%   |  j  j | | ƒ o$ |  j | | ƒ S(   N(   R   R
   R   (   R   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   a   s    c         c  s)   x" |  j  j | | ƒ D] } | Vq Wd  S(   N(   R   R   (   R   R   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   f   s    c         C  s   d |  j  |  j f S(   Nu   <%s%s(   R   R   (   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   j   s    (   R   R   R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   V   s
   		t   UndirectedFunctionApplicationc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   uœ   
    Class representing function application.
    Implements rules of the form:
    X/Y Y -> X (>)
    And the corresponding backwards application rule
    c         C  s)   | j  ƒ  s t S| j ƒ  j | ƒ d  k	 S(   N(   t   is_functiont   Falset   argt	   can_unifyt   None(   R   R   R	   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   w   s    c         c  sM   | j  ƒ  s d  S| j ƒ  j | ƒ } | d  k r5 d  S| j ƒ  j | ƒ Vd  S(   N(   R   R    R!   R"   t   rest
   substitute(   R   R   R	   t   subs(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   }   s    c         C  s   d S(   Nu    (    (   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   ‡   s    (   R   R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   n   s   		
c         C  s   |  j  ƒ  j ƒ  S(   N(   t   dirt
   is_forward(   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   forwardOnlyŽ   s    c         C  s   | j  ƒ  j ƒ  S(   N(   R&   t   is_backward(   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   backwardOnly“   s    t   UndirectedCompositionc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   u¬   
    Functional composition (harmonic) combinator.
    Implements rules of the form
    X/Y Y/Z -> X/Z (B>)
    And the corresponding backwards and crossed variations.
    c         C  sc   | j  ƒ  o | j  ƒ  s t S| j ƒ  j ƒ  r_ | j ƒ  j ƒ  r_ | j ƒ  j | j ƒ  ƒ d  k	 St S(   N(   R   R   R&   t   can_composeR    R!   R#   R"   (   R   R   R	   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   ¥   s
    $c         c  s¦   | j  ƒ  o | j  ƒ  s d  S| j ƒ  j ƒ  r¢ | j ƒ  j ƒ  r¢ | j ƒ  j | j ƒ  ƒ } | d  k	 r¢ t | j ƒ  j | ƒ | j ƒ  j | ƒ | j ƒ  ƒ Vq¢ n  d  S(   N(	   R   R&   R,   R    R!   R#   R"   R   R$   (   R   R   R	   R%   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   ®   s    $c         C  s   d S(   Nu   B(    (   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   º   s    (   R   R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR+   œ   s   			c         C  s"   |  j  ƒ  j ƒ  o! | j  ƒ  j ƒ  S(   N(   R&   R'   (   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   bothForward¿   s    c         C  s"   |  j  ƒ  j ƒ  o! | j  ƒ  j ƒ  S(   N(   R&   R)   (   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   bothBackwardÃ   s    c         C  s"   |  j  ƒ  j ƒ  o! | j  ƒ  j ƒ  S(   N(   R&   R'   R)   (   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   crossedDirsÈ   s    c         C  sL   t  |  | ƒ s t S|  j ƒ  j ƒ  r< | j ƒ  j ƒ  r< t S|  j ƒ  j ƒ  S(   N(   R/   R   R&   t	   can_crossR    t   is_primitive(   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   backwardBxConstraintÌ   s
    %R   u   xt   UndirectedSubstitutionc           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   uˆ   
    Substitution (permutation) combinator.
    Implements rules of the form
    Y/Z (X\Y)/Z -> X/Z (<Sx)
    And other variations.
    c         C  s¤   | j  ƒ  s | j  ƒ  r t S| j ƒ  j  ƒ  r2 t S| j ƒ  j  ƒ  sH t S| j ƒ  j ƒ  oi | j ƒ  j ƒ  sp t S| j ƒ  j ƒ  | j ƒ  k o£ | j ƒ  | j ƒ  k S(   N(   R1   R   R#   R    R&   R,   (   R   R   R	   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   ê   s    $c         c  sB   |  j  | | ƒ r> t | j ƒ  j ƒ  | j ƒ  | j ƒ  ƒ Vn  d  S(   N(   R
   R   R#   R    R&   (   R   R   R	   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   û   s    c         C  s   d S(   Nu   S(    (   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR     s    (   R   R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR3   á   s   		c         C  s;   t  |  | ƒ s t S|  j ƒ  j ƒ  j ƒ  o: |  j ƒ  j ƒ  S(   N(   R-   R   R#   R&   R'   R    R1   (   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   forwardSConstraint  s    c         C  sd   |  j  ƒ  j ƒ  r) | j  ƒ  j ƒ  r) t St |  | ƒ s< t S| j ƒ  j  ƒ  j ƒ  oc | j ƒ  j ƒ  S(   N(   R&   R0   R   R-   R#   R)   R    R1   (   R   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   backwardSxConstraint  s
    %c         C  s)   x" |  j  ƒ  j ƒ  r$ |  j  ƒ  }  q W|  S(   N(   R#   R   (   t   categ(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   innermostFunction  s    t   UndirectedTypeRaisec           B  s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   u1   
    Undirected combinator for type raising.
    c         C  sW   | j  ƒ  o | j ƒ  j  ƒ  s" t St | ƒ } t j t j ƒ  ƒ } | d  k	 rS t	 St S(   N(
   R   R#   R   R7   R   R!   t	   arg_categR    R"   t   True(   R   R   R    R%   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR
   (  s    c         c  s¡   | j  ƒ  o' | j ƒ  o' | j ƒ  j ƒ  s. d  St | ƒ } | j | j ƒ  ƒ } | d  k	 r | j ƒ  j | ƒ } t | t | | | j	 ƒ  ƒ | j	 ƒ  ƒ Vn  d  S(   N(
   R1   R   R#   R7   R!   R    R"   R$   R   R&   (   R   R   R    R%   t   xcat(    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   ;  s    *c         C  s   d S(   Nu   T(    (   R   (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR   K  s    (   R   R   R   R
   R   R   (    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyR8   "  s   		c         C  s.   t  | ƒ } | j ƒ  j ƒ  o- | j ƒ  j ƒ  S(   N(   R7   R&   R)   R#   R1   (   R   R   R    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   forwardTConstraintT  s    c         C  s.   t  |  ƒ } | j ƒ  j ƒ  o- | j ƒ  j ƒ  S(   N(   R7   R&   R'   R#   R1   (   R   R   R    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   backwardTConstraintY  s    N()   R   t
   __future__R    t   abcR   R   t   sixR   t   nltk.compatR   t   nltk.ccg.apiR   t   objectR   R   R   R   R   R(   R*   t   ForwardApplicationt   BackwardApplicationR+   R-   R.   R/   R2   t   ForwardCompositiont   BackwardCompositiont
   BackwardBxR3   R4   R5   t   ForwardSubstitutiont
   BackwardSxR7   R8   R<   R=   t   ForwardTt	   BackwardT(    (    (    s2   lib/python2.7/site-packages/nltk/ccg/combinator.pyt   <module>	   sT   		"				$				1		