
    g'                         d dl mZmZ d dlmZ d dlmZ e G d de             Z G d de      Ze G d	 d
             Z	 G d de      Z
 G d de      Zy)    )ABCMetaabstractmethod)total_ordering)raise_unorderable_typesc                       e Zd 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y)AbstractCCGCategoryz;
    Interface for categories in combinatory grammars.
    c                      y)z<
        Returns true if the category is primitive.
        N selfs    A/var/www/openai/venv/lib/python3.12/site-packages/nltk/ccg/api.pyis_primitivez AbstractCCGCategory.is_primitive           c                      y)zI
        Returns true if the category is a function application.
        Nr
   r   s    r   is_functionzAbstractCCGCategory.is_function   r   r   c                      y)z=
        Returns true if the category is a variable.
        Nr
   r   s    r   is_varzAbstractCCGCategory.is_var    r   r   c                      y)z
        Takes a set of (var, category) substitutions, and replaces every
        occurrence of the variable with the corresponding category.
        Nr
   )r   substitutionss     r   
substitutezAbstractCCGCategory.substitute&   r   r   c                      y)z
        Determines whether two categories can be unified.
         - Returns None if they cannot be unified
         - Returns a list of necessary substitutions if they can.
        Nr
   r   others     r   	can_unifyzAbstractCCGCategory.can_unify-   r   r   c                      y Nr
   r   s    r   __str__zAbstractCCGCategory.__str__6   s    r   c                 h    | j                   |j                   u xr | j                  |j                  k(  S r   	__class___comparison_keyr   s     r   __eq__zAbstractCCGCategory.__eq__:   0    NNeoo- >$$(=(==	
r   c                     | |k(   S r   r
   r   s     r   __ne__zAbstractCCGCategory.__ne__@       5=  r   c                     t        |t              st        d| |       | j                  |j                  u r| j                  |j                  k  S | j                  j
                  |j                  j
                  k  S N<)
isinstancer   r   r!   r"   __name__r   s     r   __lt__zAbstractCCGCategory.__lt__C   s_    %!45#Cu5>>U__,''%*?*???>>**U__-E-EEEr   c                     	 | j                   S # t        $ r) t        | j                        | _         | j                   cY S w xY wr   _hashAttributeErrorhashr"   r   s    r   __hash__zAbstractCCGCategory.__hash__K   <    	:: 	d223DJ::	    /A A N)r,   
__module____qualname____doc__r   r   r   r   r   r   r   r#   r&   r-   r3   r
   r   r   r   r      s      
  
  
      
!Fr   r   )	metaclassc                   f    e Zd ZdZdZddZed        Zed        Zd Z	d Z
d Zd	 Zd
 Zd Zd Zy)CCGVarz
    Class representing a variable CCG category.
    Used for conjunctions (and possibly type-raising, if implemented as a
    unary rule).
    r   c                 ^    | j                         | _        || _        | j                  | _        y)zInitialize 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)new_id_id
_prim_onlyr"   )r   	prim_onlys     r   __init__zCCGVar.__init__\   s$     ;;=##xxr   c                 H    | j                   dz   | _         | j                   dz
  S )zT
        A class method allowing generation of unique variable identifiers.
           _maxIDclss    r   r=   zCCGVar.new_idg   s!    
 ZZ!^
zzA~r   c                     d| _         y )Nr   rD   rF   s    r   reset_idzCCGVar.reset_ido   s	    
r   c                      yNFr
   r   s    r   r   zCCGVar.is_primitives       r   c                      yrK   r
   r   s    r   r   zCCGVar.is_functionv   rL   r   c                      yNTr
   r   s    r   r   zCCGVar.is_vary       r   c                 ,    |D ]  \  }}|| k(  s|c S  | S )zlIf there is a substitution corresponding to this variable,
        return the substituted category.
        r
   )r   r   varcats       r   r   zCCGVar.substitute|   s%     &HCd{
 & r   c                 F    |j                         s| j                  s| |fgS y)zWIf the variable can be replaced with other
        a substitution is returned.
        N)r   r?   r   s     r   r   zCCGVar.can_unify   s%     t5M?"r   c                     | j                   S r   )r>   r   s    r   idz	CCGVar.id   s    xxr   c                 2    dt        | j                        z   S )N_var)strr>   r   s    r   r   zCCGVar.__str__   s    DHH%%r   N)F)r,   r6   r7   r8   rE   rA   classmethodr=   rI   r   r   r   r   r   rV   r   r
   r   r   r;   r;   S   s^     F	(    &r   r;   c                   p    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d Zy)	Directionz
    Class representing the direction of a function application.
    Also contains maintains information as to which combinators
    may be used with the category.
    c                 D    || _         || _        |t        |      f| _        y r   )_dir_restrstupler"   )r   dirrestrictionss      r   rA   zDirection.__init__   s"    	# #U<%89r   c                      | j                   dk(  S )N/r^   r   s    r   
is_forwardzDirection.is_forward   s    yyCr   c                      | j                   dk(  S )N\re   r   s    r   is_backwardzDirection.is_backward   s    yyD  r   c                     | j                   S r   re   r   s    r   ra   zDirection.dir       yyr   c                     | j                   S )a8  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)
        r_   r   s    r   restrszDirection.restrs   s     ||r   c                      | j                   dk(  S N_rm   r   s    r   is_variablezDirection.is_variable   s    ||s""r   c                     |j                         rd| j                         fgS | j                         rd|j                         fgS | j                         |j                         k(  rg S y rp   )rr   rn   r   s     r   r   zDirection.can_unify   s^    $++-())%,,.)**{{}.	r   c                 x    | j                         s| S |D ]"  \  }}|dk(  st        | j                  |      c S  | S rp   )rr   r\   r^   )r   subsrR   rn   s       r   r   zDirection.substitute   s@    !KKCcz F33   r   c                     d| j                   vS )N,rm   r   s    r   can_composezDirection.can_compose       $,,&&r   c                     d| j                   vS )N.rm   r   s    r   	can_crosszDirection.can_cross   ry   r   c                 h    | j                   |j                   u xr | j                  |j                  k(  S r   r    r   s     r   r#   zDirection.__eq__   r$   r   c                     | |k(   S r   r
   r   s     r   r&   zDirection.__ne__   r'   r   c                     t        |t              st        d| |       | j                  |j                  u r| j                  |j                  k  S | j                  j
                  |j                  j
                  k  S r)   )r+   r\   r   r!   r"   r,   r   s     r   r-   zDirection.__lt__   s^    %+#Cu5>>U__,''%*?*???>>**U__-E-EEEr   c                     	 | j                   S # t        $ r) t        | j                        | _         | j                   cY S w xY wr   r/   r   s    r   r3   zDirection.__hash__   r4   r5   c                 X    d}| j                   D ]
  }|d|z  z   } | j                   | S )N %s)r_   r^   )r   r_strrs      r   r   zDirection.__str__   s6    AD1H$E ))UG$$r   c                 x    | j                   dk(  rt        d| j                        S t        d| j                        S )Nrd   rh   )r^   r\   r_   r   s    r   __neg__zDirection.__neg__   s0    99T4<<00S$,,//r   N)r,   r6   r7   r8   rA   rf   ri   ra   rn   rr   r   r   rx   r|   r#   r&   r-   r3   r   r   r
   r   r   r\   r\      sX    : !#''
!F%0r   r\   c                   J    e Zd ZdZg fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)PrimitiveCategoryz
    Class representing primitive categories.
    Takes a string representation of the category, and a
    list of strings specifying the morphological subcategories.
    c                 D    || _         || _        |t        |      f| _        y r   )_categr_   r`   r"   )r   categrb   s      r   rA   zPrimitiveCategory.__init__  s"    # %u\':;r   c                      yrO   r
   r   s    r   r   zPrimitiveCategory.is_primitive  rP   r   c                      yrK   r
   r   s    r   r   zPrimitiveCategory.is_function	  rL   r   c                      yrK   r
   r   s    r   r   zPrimitiveCategory.is_var  rL   r   c                     | j                   S r   rm   r   s    r   rn   zPrimitiveCategory.restrs  s    ||r   c                     | j                   S r   )r   r   s    r   r   zPrimitiveCategory.categ  s    {{r   c                     | S r   r
   )r   ru   s     r   r   zPrimitiveCategory.substitute  s    r   c                     |j                         sy |j                         r|| fgS |j                         | j                         k(  r'| j                  D ]  }||j	                         vs y  g S y r   )r   r   r   r_   rn   )r   r   restrs      r   r   zPrimitiveCategory.can_unify  sc    !!#<<>DM?";;=DJJL(. & Ir   c                     | j                   g k(  rd| j                  z  S ddj                  d | j                   D              z  }| j                   | S )Nr   z[%s]rw   c              3   2   K   | ]  }t        |        y wr   )repr).0r   s     r   	<genexpr>z,PrimitiveCategory.__str__.<locals>.<genexpr>+  s     (G,Qa,s   )r_   r   join)r   rb   s     r   r   zPrimitiveCategory.__str__(  sM    <<2$++%%(G$,,(G GG++|n--r   N)r,   r6   r7   r8   rA   r   r   r   rn   r   r   r   r   r
   r   r   r   r      s9     ,. <

.r   r   c                   L    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y)FunctionalCategoryz
    Class that represents a function application category.
    Consists of argument and result categories, together with
    an application direction.
    c                 B    || _         || _        || _        |||f| _        y r   )_res_argr^   r"   )r   resargra   s       r   rA   zFunctionalCategory.__init__6  s%    			 #S#r   c                      yrK   r
   r   s    r   r   zFunctionalCategory.is_primitive<  rL   r   c                      yrO   r
   r   s    r   r   zFunctionalCategory.is_function?  rP   r   c                      yrK   r
   r   s    r   r   zFunctionalCategory.is_varB  rL   r   c                     | j                   j                  |      }| j                  j                  |      }| j                  j                  |      }t	        ||| j                        S r   )r   r   r^   r   r   )r   ru   sub_ressub_dirsub_args        r   r   zFunctionalCategory.substituteG  sQ    ))&&t,))&&t,))&&t,!'7DII>>r   c                    |j                         r|| fgS |j                         r| j                  j                  |j	                               }| j
                  j                  |j                               }|P|N| j                  j                  |      j                  |j                         j                  |            }|||z   S y r   )
r   r   r   r   r   r^   ra   r   r   r   )r   r   sasdsbs        r   r   zFunctionalCategory.can_unifyO  s    <<>DM?"$$UYY[1B$$UYY[1B~".YY))"-77		8N8Nr8RS>7Nr   c                     | j                   S r   )r   r   s    r   r   zFunctionalCategory.arg\  rk   r   c                     | j                   S r   )r   r   s    r   r   zFunctionalCategory.res_  rk   r   c                     | j                   S r   re   r   s    r   ra   zFunctionalCategory.dirb  rk   r   c                 R    d| j                    | j                   | j                   dS )N())r   r^   r   r   s    r   r   zFunctionalCategory.__str__e  s%    499+dii[155r   N)r,   r6   r7   r8   rA   r   r   r   r   r   r   r   ra   r   r
   r   r   r   r   /  s9    /
?
6r   r   N)abcr   r   	functoolsr   nltk.internalsr   r   r;   r\   r   r   r
   r   r   <module>r      su    ( $ 2 AG A AH>&  >&B b0 b0 b0J2.+ 2.j76, 76r   