
    Ng'                         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dS )    )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dS )AbstractCCGCategoryz;
    Interface for categories in combinatory grammars.
    c                     dS )z<
        Returns true if the category is primitive.
        N selfs    H/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/ccg/api.pyis_primitivez AbstractCCGCategory.is_primitive             c                     dS )zI
        Returns true if the category is a function application.
        Nr
   r   s    r   is_functionzAbstractCCGCategory.is_function   r   r   c                     dS )z=
        Returns true if the category is a variable.
        Nr
   r   s    r   is_varzAbstractCCGCategory.is_var    r   r   c                     dS )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                     dS )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                     d S Nr
   r   s    r   __str__zAbstractCCGCategory.__str__6   s    r   c                 >    | j         |j         u o| j        |j        k    S r   	__class___comparison_keyr   s     r   __eq__zAbstractCCGCategory.__eq__:   &    Neo- >$(==	
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5 	6#Cu555>U_,,'%*???>*U_-EEEr   c                 r    	 | 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   J    	: 	 	 	d233DJ:	   	 *66N)r,   
__module____qualname____doc__r   r   r   r   r   r   r   r#   r&   r-   r3   r
   r   r   r   r      s            ^
   ^
   ^
   ^   ^   ^
 
 
! ! !F F F    r   r   )	metaclassc                   t    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dS )CCGVarz
    Class representing a variable CCG category.
    Used for conjunctions (and possibly type-raising, if implemented as a
    unary rule).
    r   Fc                 ^    |                                  | _        || _        | j        | _        dS )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*     ;;==##xr   c                 4    | 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    
 Z!^
zA~r   c                     d| _         d S )Nr   rD   rF   s    r   reset_idzCCGVar.reset_ido   s    


r   c                     dS NFr
   r   s    r   r   zCCGVar.is_primitives       ur   c                     dS rK   r
   r   s    r   r   zCCGVar.is_functionv   rL   r   c                     dS NTr
   r   s    r   r   zCCGVar.is_vary       tr   c                 *    |D ]\  }}|| k    r|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|   s3     & 	 	HCd{{


 r   c                 F    |                                 s| j        s| |fgS dS )zWIf the variable can be replaced with other
        a substitution is returned.
        N)r   r?   r   s     r   r   zCCGVar.can_unify   s2      	#t 	#5M?"tr   c                     | j         S r   )r>   r   s    r   idz	CCGVar.id   s	    xr   c                 0    dt          | j                  z   S )N_var)strr>   r   s    r   r   zCCGVar.__str__   s    DH%%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                   r    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dS )	Directionz
    Class representing the direction of a function application.
    Also contains maintains information as to which combinators
    may be used with the category.
    c                 N    || _         || _        |t          |          f| _        d S r   )_dir_restrstupler"   )r   dirrestrictionss      r   rA   zDirection.__init__   s+    	# #U<%8%89r   c                     | j         dk    S )N/r^   r   s    r   
is_forwardzDirection.is_forward   s    yCr   c                     | j         dk    S )N\re   r   s    r   is_backwardzDirection.is_backward   s    yD  r   c                     | j         S r   re   r   s    r   ra   zDirection.dir   
    y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                 
   |                                 rd|                                 fgS |                                  rd|                                fgS |                                 |                                k    rg S d S rp   )rr   rn   r   s     r   r   zDirection.can_unify   s{     	$++--()) 	%,,..)**{{}}..	tr   c                 |    |                                  s| S |D ]"\  }}|dk    rt          | j        |          c S #| S rp   )rr   r\   r^   )r   subsrR   rn   s       r   r   zDirection.substitute   sY    !! 	K 	4 	4KCczz F333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                 >    | j         |j         u o| 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[    %++ 	6#Cu555>U_,,'%*???>*U_-EEEr   c                 r    	 | 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                 @    d}| j         D ]
}|d|z  z   }| j         | S )N %s)r_   r^   )r   r_strrs      r   r   zDirection.__str__   s;     	% 	%AD1H$EE)$U$$$r   c                 l    | j         dk    rt          d| j                  S t          d| j                  S )Nrd   rh   )r^   r\   r_   r   s    r   __neg__zDirection.__neg__   s3    9T4<0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\      s        : : :     ! ! !    # # #    ' ' '' ' '
 
 
! ! !F F F  % % %0 0 0 0 0r   r\   c                   L    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dS )PrimitiveCategoryz
    Class representing primitive categories.
    Takes a string representation of the category, and a
    list of strings specifying the morphological subcategories.
    c                 N    || _         || _        |t          |          f| _        d S r   )_categr_   r`   r"   )r   categrb   s      r   rA   zPrimitiveCategory.__init__  s+    # %u\':':;r   c                     dS rO   r
   r   s    r   r   zPrimitiveCategory.is_primitive  rP   r   c                     dS rK   r
   r   s    r   r   zPrimitiveCategory.is_function	  rL   r   c                     dS 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                    |                                 sd S |                                r|| fgS |                                |                                 k    r%| j        D ]}||                                vr d S g S d S r   )r   r   r   r_   rn   )r   r   restrs      r   r   zPrimitiveCategory.can_unify  s    !!## 	4<<>> 	#DM?";;==DJJLL((    ..44 /Itr   c                     | j         g k    r
d| j        z  S dd                    d | j         D                       z  }| j         | S )Nr   z[%s]rw   c              3   4   K   | ]}t          |          V  d S r   )repr).0r   s     r   	<genexpr>z,PrimitiveCategory.__str__.<locals>.<genexpr>+  s(      (G(GQa(G(G(G(G(G(Gr   )r_   r   join)r   rb   s     r   r   zPrimitiveCategory.__str__(  sV    <2$+%%(G(G$,(G(G(G G GG+-|---r   N)r,   r6   r7   r8   rA   r   r   r   rn   r   r   r   r   r
   r   r   r   r      s          ,. < < < <
            
 
 
. . . . .r   r   c                   N    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S )FunctionalCategoryz
    Class that represents a function application category.
    Consists of argument and result categories, together with
    an application direction.
    c                 D    || _         || _        || _        |||f| _        d S r   )_res_argr^   r"   )r   resargra   s       r   rA   zFunctionalCategory.__init__6  s+    			 #S#r   c                     dS rK   r
   r   s    r   r   zFunctionalCategory.is_primitive<  rL   r   c                     dS rO   r
   r   s    r   r   zFunctionalCategory.is_function?  rP   r   c                     dS rK   r
   r   s    r   r   zFunctionalCategory.is_varB  rL   r   c                     | 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  sU    )&&t,,)&&t,,)&&t,,!'7DI>>>r   c                    |                                 r|| fgS |                                r| j                            |                                          }| j                            |                                          }|[|Y| j                            |                              |	                                                    |                    }|||z   S d S 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[[11B$$UYY[[11B~".Y))"--77		8N8Nr8R8RSS>7Ntr   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                 4    d| j          | j         | j         dS )N())r   r^   r   r   s    r   r   zFunctionalCategory.__str__e  s#    5495di55555r   N)r,   r6   r7   r8   rA   r   r   r   r   r   r   r   ra   r   r
   r   r   r   r   /  s         / / /      
? ? ?
 
 
      6 6 6 6 6r   r   N)abcr   r   	functoolsr   nltk.internalsr   r   r;   r\   r   r   r
   r   r   <module>r      sR   ( ' ' ' ' ' ' ' $ $ $ $ $ $ 2 2 2 2 2 2 A A A A AG A A A AH>& >& >& >& >&  >& >& >&B b0 b0 b0 b0 b0 b0 b0 b0J2. 2. 2. 2. 2.+ 2. 2. 2.j76 76 76 76 76, 76 76 76 76 76r   