a
     ˜ëj'  ã                   @   s„   d dl mZmZ d dlmZ d dlmZ eG dd„ ded�ƒZG dd„ deƒZeG d	d
„ d
ƒƒZ	G dd„ deƒZ
G dd„ deƒZdS )é    )ÚABCMetaÚabstractmethod)Útotal_ordering)Úraise_unorderable_typesc                   @   sx   e 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	edd„ ƒZ
dd„ Zdd„ Zdd„ Zdd„ ZdS )ÚAbstractCCGCategoryz;
    Interface for categories in combinatory grammars.
    c                 C   s   dS )z<
        Returns true if the category is primitive.
        N© ©Úselfr   r   úK/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/nltk/ccg/api.pyÚis_primitive   s    z AbstractCCGCategory.is_primitivec                 C   s   dS )zI
        Returns true if the category is a function application.
        Nr   r   r   r   r
   Úis_function   s    zAbstractCCGCategory.is_functionc                 C   s   dS )z=
        Returns true if the category is a variable.
        Nr   r   r   r   r
   Úis_var    s    zAbstractCCGCategory.is_varc                 C   s   dS )z–
        Takes a set of (var, category) substitutions, and replaces every
        occurrence of the variable with the corresponding category.
        Nr   )r	   Úsubstitutionsr   r   r
   Ú
substitute&   s    zAbstractCCGCategory.substitutec                 C   s   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	   Úotherr   r   r
   Ú	can_unify-   s    zAbstractCCGCategory.can_unifyc                 C   s   d S ©Nr   r   r   r   r
   Ú__str__6   s    zAbstractCCGCategory.__str__c                 C   s   | j |j u o| j|jkS r   ©Ú	__class__Ú_comparison_keyr   r   r   r
   Ú__eq__:   s    
þzAbstractCCGCategory.__eq__c                 C   s
   | |k S r   r   r   r   r   r
   Ú__ne__@   s    zAbstractCCGCategory.__ne__c                 C   sB   t |tƒstd| |ƒ | j|ju r.| j|jk S | jj|jjk S d S ©Nú<)Ú
isinstancer   r   r   r   Ú__name__r   r   r   r
   Ú__lt__C   s
    
zAbstractCCGCategory.__lt__c                 C   s2   z| j W S  ty,   t| jƒ| _ | j  Y S 0 d S r   ©Ú_hashÚAttributeErrorÚhashr   r   r   r   r
   Ú__hash__K   s
    zAbstractCCGCategory.__hash__N)r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r#   r   r   r   r
   r      s"   





r   )Ú	metaclassc                   @   sn   e Zd ZdZdZddd„Zedd„ ƒZedd	„ ƒZd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zd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                 C   s   |   ¡ | _|| _| j| _dS )z×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)Únew_idÚ_idÚ
_prim_onlyr   )r	   Z	prim_onlyr   r   r
   Ú__init__\   s    
zCCGVar.__init__c                 C   s   | j d | _ | j d S )zT
        A class method allowing generation of unique variable identifiers.
        é   ©Ú_maxID©Úclsr   r   r
   r)   g   s    zCCGVar.new_idc                 C   s
   d| _ d S )Nr   r.   r0   r   r   r
   Úreset_ido   s    zCCGVar.reset_idc                 C   s   dS ©NFr   r   r   r   r
   r   s   s    zCCGVar.is_primitivec                 C   s   dS r3   r   r   r   r   r
   r   v   s    zCCGVar.is_functionc                 C   s   dS ©NTr   r   r   r   r
   r   y   s    zCCGVar.is_varc                 C   s"   |D ]\}}|| kr|  S q| S )zlIf there is a substitution corresponding to this variable,
        return the substituted category.
        r   )r	   r   ÚvarÚcatr   r   r
   r   |   s    
zCCGVar.substitutec                 C   s   |  ¡ s| js| |fgS dS )zWIf the variable can be replaced with other
        a substitution is returned.
        N)r   r+   r   r   r   r
   r   …   s    
zCCGVar.can_unifyc                 C   s   | j S r   )r*   r   r   r   r
   Úid�   s    z	CCGVar.idc                 C   s   dt | jƒ S )NZ_var)Ústrr*   r   r   r   r
   r   �   s    zCCGVar.__str__N)F)r   r$   r%   r&   r/   r,   Úclassmethodr)   r2   r   r   r   r   r   r7   r   r   r   r   r
   r(   S   s   


	r(   c                   @   s�   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd 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                 C   s   || _ || _|t|ƒf| _d S r   )Ú_dirÚ_restrsÚtupler   )r	   ÚdirÚrestrictionsr   r   r
   r,   œ   s    zDirection.__init__c                 C   s
   | j dkS )Nú/©r;   r   r   r   r
   Ú
is_forward¢   s    zDirection.is_forwardc                 C   s
   | j dkS )Nú\rA   r   r   r   r
   Úis_backward¥   s    zDirection.is_backwardc                 C   s   | j S r   rA   r   r   r   r
   r>   ¨   s    zDirection.dirc                 C   s   | 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   r   r   r
   Úrestrs«   s    zDirection.restrsc                 C   s
   | j dkS ©NÚ_rE   r   r   r   r
   Úis_variable´   s    zDirection.is_variablec                 C   sD   |  ¡ rd|  ¡ fgS |   ¡ r,d| ¡ fgS |  ¡ | ¡ kr@g S d S rG   )rI   rF   r   r   r   r
   r   º   s    zDirection.can_unifyc                 C   s6   |   ¡ s| S |D ] \}}|dkrt| j|ƒ  S q| S rG   )rI   r:   r;   )r	   Úsubsr5   rF   r   r   r
   r   Ä   s    zDirection.substitutec                 C   s
   d| j vS )Nú,rE   r   r   r   r
   Úcan_composeÎ   s    zDirection.can_composec                 C   s
   d| j vS )NÚ.rE   r   r   r   r
   Ú	can_crossÑ   s    zDirection.can_crossc                 C   s   | j |j u o| j|jkS r   r   r   r   r   r
   r   Ô   s    
þzDirection.__eq__c                 C   s
   | |k S r   r   r   r   r   r
   r   Ú   s    zDirection.__ne__c                 C   sB   t |tƒstd| |ƒ | j|ju r.| j|jk S | jj|jjk S d S r   )r   r:   r   r   r   r   r   r   r   r
   r   Ý   s
    
zDirection.__lt__c                 C   s2   z| j W S  ty,   t| jƒ| _ | j  Y S 0 d S r   r   r   r   r   r
   r#   å   s
    zDirection.__hash__c                 C   s*   d}| j D ]}|d|  }q
| j› |› �S )NÚ ú%s)r<   r;   )r	   Zr_strÚrr   r   r
   r   ì   s    
zDirection.__str__c                 C   s&   | j dkrtd| jƒS td| jƒS d S )Nr@   rC   )r;   r:   r<   r   r   r   r
   Ú__neg__ó   s    
zDirection.__neg__N)r   r$   r%   r&   r,   rB   rD   r>   rF   rI   r   r   rL   rN   r   r   r   r#   r   rR   r   r   r   r
   r:   ”   s"   	

r:   c                   @   s\   e Zd ZdZg fdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zd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                 C   s   || _ || _|t|ƒf| _d S r   )Ú_categr<   r=   r   )r	   Úcategr?   r   r   r
   r,     s    zPrimitiveCategory.__init__c                 C   s   dS r4   r   r   r   r   r
   r     s    zPrimitiveCategory.is_primitivec                 C   s   dS r3   r   r   r   r   r
   r   	  s    zPrimitiveCategory.is_functionc                 C   s   dS r3   r   r   r   r   r
   r     s    zPrimitiveCategory.is_varc                 C   s   | j S r   rE   r   r   r   r
   rF     s    zPrimitiveCategory.restrsc                 C   s   | j S r   )rT   r   r   r   r
   rU     s    zPrimitiveCategory.categc                 C   s   | S r   r   )r	   rJ   r   r   r
   r     s    zPrimitiveCategory.substitutec                 C   sT   |  ¡ sd S | ¡ r|| fgS | ¡ |  ¡ krP| jD ]}|| ¡ vr4 d S q4g S d S r   )r   r   rU   r<   rF   )r	   r   Úrestrr   r   r
   r     s    

zPrimitiveCategory.can_unifyc                 C   s<   | j g krd| j S dd dd„ | j D ƒ¡ }| j› |› �S )NrP   z[%s]rK   c                 s   s   | ]}t |ƒV  qd S r   )Úrepr)Ú.0rQ   r   r   r
   Ú	<genexpr>+  ó    z,PrimitiveCategory.__str__.<locals>.<genexpr>)r<   rT   Újoin)r	   r?   r   r   r
   r   (  s    

zPrimitiveCategory.__str__N)r   r$   r%   r&   r,   r   r   r   rF   rU   r   r   r   r   r   r   r
   rS   ú   s   rS   c                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ ZdS )ÚFunctionalCategoryzœ
    Class that represents a function application category.
    Consists of argument and result categories, together with
    an application direction.
    c                 C   s"   || _ || _|| _|||f| _d S r   )Ú_resÚ_argr;   r   )r	   ÚresÚargr>   r   r   r
   r,   6  s    zFunctionalCategory.__init__c                 C   s   dS r3   r   r   r   r   r
   r   <  s    zFunctionalCategory.is_primitivec                 C   s   dS r4   r   r   r   r   r
   r   ?  s    zFunctionalCategory.is_functionc                 C   s   dS r3   r   r   r   r   r
   r   B  s    zFunctionalCategory.is_varc                 C   s2   | j  |¡}| j |¡}| j |¡}t||| jƒS r   )r]   r   r;   r^   r\   )r	   rJ   Zsub_resZsub_dirZsub_argr   r   r
   r   G  s    zFunctionalCategory.substitutec                 C   sz   |  ¡ r|| fgS | ¡ rv| j | ¡ ¡}| j | ¡ ¡}|d urv|d urv| j |¡ | 	¡  |¡¡}|d urv|| S d S r   )
r   r   r]   r   r_   r;   r>   r^   r   r`   )r	   r   ÚsaÚsdZsbr   r   r
   r   O  s    
zFunctionalCategory.can_unifyc                 C   s   | j S r   )r^   r   r   r   r
   r`   \  s    zFunctionalCategory.argc                 C   s   | j S r   )r]   r   r   r   r
   r_   _  s    zFunctionalCategory.resc                 C   s   | j S r   rA   r   r   r   r
   r>   b  s    zFunctionalCategory.dirc                 C   s   d| j › | j› | j› d�S )Nú(ú))r]   r;   r^   r   r   r   r
   r   e  s    zFunctionalCategory.__str__N)r   r$   r%   r&   r,   r   r   r   r   r   r`   r_   r>   r   r   r   r   r
   r\   /  s   r\   N)Úabcr   r   Ú	functoolsr   Znltk.internalsr   r   r(   r:   rS   r\   r   r   r   r
   Ú<module>   s   DAe5