o
    ¹i7(  ã                   @   sr  d Z ddlmZmZ ddlmZ G dd„ dedZG dd„ dedZG d	d
„ d
eƒZG dd„ deƒZ	G dd„ deƒZ
dd„ Zdd„ Zee
ƒ eƒZe	e
ƒ eƒZG dd„ deƒZdd„ Zdd„ Zdd„ Zdd„ Zeeƒ eƒZe	eƒ eƒZe	eƒ eddZG dd „ d eƒZd!d"„ Zd#d$„ Zeeƒ eƒZe	eƒ edƒZd%d&„ ZG d'd(„ d(eƒZd)d*„ Zd+d,„ Zeeƒ eƒZ e	eƒ eƒZ!d-S ).z
CCG Combinators
é    )ÚABCMetaÚabstractmethod)ÚFunctionalCategoryc                   @   ó(   e Zd ZdZedd„ ƒZedd„ ƒZdS )ÚUndirectedBinaryCombinatora«  
    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   ó   d S ©N© ©ÚselfÚfunctionÚargumentr	   r	   úN/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/nltk/ccg/combinator.pyÚcan_combine   ó   z&UndirectedBinaryCombinator.can_combinec                 C   r   r   r	   r
   r	   r	   r   Úcombine    r   z"UndirectedBinaryCombinator.combineN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r	   r	   r	   r   r      s    
r   )Ú	metaclassc                   @   r   )ÚDirectedBinaryCombinatorzÝ
    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   r   r   r	   ©r   ÚleftÚrightr	   r	   r   r   -   r   z$DirectedBinaryCombinator.can_combinec                 C   r   r   r	   r   r	   r	   r   r   1   r   z DirectedBinaryCombinator.combineNr   r	   r	   r	   r   r   %   s    
r   c                   @   ó2   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZdS )ÚForwardCombinatorzÏ
    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.
    Ú c                 C   ó   || _ || _|| _d S r   ©Ú_combinatorÚ
_predicateÚ_suffix©r   Ú
combinatorÚ	predicateÚsuffixr	   r	   r   Ú__init__>   ó   
zForwardCombinator.__init__c                 C   s   | j  ||¡o|  ||¡S r   ©r!   r   r"   r   r	   r	   r   r   C   ó   ÿzForwardCombinator.can_combinec                 c   s    | j  ||¡E d H  d S r   ©r!   r   r   r	   r	   r   r   H   ó   €zForwardCombinator.combinec                 C   ó   d| j › | j› S )Nú>©r!   r#   ©r   r	   r	   r   Ú__str__K   ó   zForwardCombinator.__str__N©r   ©r   r   r   r   r(   r   r   r2   r	   r	   r	   r   r   6   s    
r   c                   @   r   )ÚBackwardCombinatorzA
    The backward equivalent of the ForwardCombinator class.
    r   c                 C   r   r   r    r$   r	   r	   r   r(   T   r)   zBackwardCombinator.__init__c                 C   s   | j  ||¡o|  ||¡S r   r*   r   r	   r	   r   r   Y   r+   zBackwardCombinator.can_combinec                 c   s    | j  ||¡E d H  d S r   r,   r   r	   r	   r   r   ^   r-   zBackwardCombinator.combinec                 C   r.   )Nú<r0   r1   r	   r	   r   r2   a   r3   zBackwardCombinator.__str__Nr4   r5   r	   r	   r	   r   r6   O   s    
r6   c                   @   ó(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚUndirectedFunctionApplicationzœ
    Class representing function application.
    Implements rules of the form:
    X/Y Y -> X (>)
    And the corresponding backwards application rule
    c                 C   s   |  ¡ sdS | ¡  |¡d uS ©NF)Úis_functionÚargÚ	can_unifyr
   r	   r	   r   r   m   s   z)UndirectedFunctionApplication.can_combinec                 c   s<    |  ¡ sd S | ¡  |¡}|d u rd S | ¡  |¡V  d S r   )r;   r<   r=   ÚresÚ
substitute©r   r   r   Úsubsr	   r	   r   r   s   s   €z%UndirectedFunctionApplication.combinec                 C   ó   dS )Nr   r	   r1   r	   r	   r   r2   }   ó   z%UndirectedFunctionApplication.__str__N©r   r   r   r   r   r   r2   r	   r	   r	   r   r9   e   s
    
r9   c                 C   s   |   ¡  ¡ S r   ©ÚdirÚ
is_forward©r   r   r	   r	   r   ÚforwardOnly…   ó   rI   c                 C   s   |  ¡  ¡ S r   ©rF   Úis_backwardrH   r	   r	   r   ÚbackwardOnlyŠ   rJ   rM   c                   @   r8   )	ÚUndirectedCompositionz¬
    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   sF   |  ¡ r|  ¡ s
dS | ¡  ¡ r!| ¡  ¡ r!| ¡  | ¡ ¡d uS dS r:   )r;   rF   Úcan_composer<   r=   r>   r
   r	   r	   r   r   ›   s
   z!UndirectedComposition.can_combinec                 c   s~    |  ¡ r	|  ¡ sd S | ¡  ¡ r9| ¡  ¡ r;| ¡  | ¡ ¡}|d ur=t| ¡  |¡| ¡  |¡| ¡ ƒV  d S d S d S d S r   )r;   rF   rO   r<   r=   r>   r   r?   r@   r	   r	   r   r   ¤   s   €
ýýzUndirectedComposition.combinec                 C   rB   )NÚBr	   r1   r	   r	   r   r2   °   rC   zUndirectedComposition.__str__NrD   r	   r	   r	   r   rN   “   s
    	rN   c                 C   ó   |   ¡  ¡ o|  ¡  ¡ S r   rE   rH   r	   r	   r   ÚbothForwardµ   ó   rR   c                 C   rQ   r   rK   rH   r	   r	   r   ÚbothBackward¹   rS   rT   c                 C   s   |   ¡  ¡ o|  ¡  ¡ S r   )rF   rG   rL   rH   r	   r	   r   ÚcrossedDirs¾   rS   rU   c                 C   s6   t | |ƒsdS |  ¡  ¡ s| ¡  ¡ rdS |  ¡  ¡ S r:   )rU   rF   Ú	can_crossr<   Úis_primitiverH   r	   r	   r   ÚbackwardBxConstraintÂ   s
   
rX   Úx)r'   c                   @   r8   )	ÚUndirectedSubstitutionzˆ
    Substitution (permutation) combinator.
    Implements rules of the form
    Y/Z (X\Y)/Z -> X/Z (<Sx)
    And other variations.
    c                 C   st   |  ¡ s|  ¡ r
dS | ¡   ¡ rdS | ¡   ¡ sdS | ¡  ¡ r&| ¡  ¡ s(dS | ¡  ¡ | ¡ ko9| ¡ | ¡ kS r:   )rW   r>   r<   rF   rO   r
   r	   r	   r   r   ß   s   ÿz"UndirectedSubstitution.can_combinec                 c   s4    |   ||¡rt| ¡  ¡ | ¡ | ¡ ƒV  d S d S r   )r   r   r>   r<   rF   r
   r	   r	   r   r   ð   s   €
ÿÿzUndirectedSubstitution.combinec                 C   rB   )NÚSr	   r1   r	   r	   r   r2   ö   rC   zUndirectedSubstitution.__str__NrD   r	   r	   r	   r   rZ   ×   s
    rZ   c                 C   s*   t | |ƒsdS |  ¡  ¡  ¡ o|  ¡  ¡ S r:   )rR   r>   rF   rG   r<   rW   rH   r	   r	   r   ÚforwardSConstraintû   s   
r\   c                 C   sF   |   ¡  ¡ s|  ¡  ¡ rdS t| |ƒsdS | ¡   ¡  ¡ o"| ¡  ¡ S r:   )rF   rV   rR   r>   rL   r<   rW   rH   r	   r	   r   ÚbackwardSxConstraint  s
   
r]   c                 C   s$   |   ¡  ¡ r|   ¡ } |   ¡  ¡ s| S r   )r>   r;   )Úcategr	   r	   r   ÚinnermostFunction  s   ÿr_   c                   @   r8   )	ÚUndirectedTypeRaisez1
    Undirected combinator for type raising.
    c                 C   s>   |  ¡ r
| ¡   ¡ sdS t|ƒ}t t ¡ ¡}|d urdS dS )NFT)r;   r>   r_   r   r=   Ú	arg_categr<   )r   r   r<   rA   r	   r	   r   r     s   zUndirectedTypeRaise.can_combinec                 c   sv    |  ¡ r| ¡ r| ¡  ¡ sd S t|ƒ}| | ¡ ¡}|d ur9| ¡  |¡}t|t||| ¡ ƒ| ¡  ƒV  d S d S r   )	rW   r;   r>   r_   r=   r<   r?   r   rF   )r   r   r<   rA   Úxcatr	   r	   r   r   /  s    €ÿÿ
ÿ
ÿþzUndirectedTypeRaise.combinec                 C   rB   )NÚTr	   r1   r	   r	   r   r2   ?  rC   zUndirectedTypeRaise.__str__NrD   r	   r	   r	   r   r`     s
    r`   c                 C   s    t |ƒ}| ¡  ¡ o| ¡  ¡ S r   )r_   rF   rL   r>   rW   ©r   r   r<   r	   r	   r   ÚforwardTConstraintH  ó   re   c                 C   s    t | ƒ}| ¡  ¡ o| ¡  ¡ S r   )r_   rF   rG   r>   rW   rd   r	   r	   r   ÚbackwardTConstraintM  rf   rg   N)"r   Úabcr   r   Únltk.ccg.apir   r   r   r   r6   r9   rI   rM   ÚForwardApplicationÚBackwardApplicationrN   rR   rT   rU   rX   ÚForwardCompositionÚBackwardCompositionÚ
BackwardBxrZ   r\   r]   ÚForwardSubstitutionÚ
BackwardSxr_   r`   re   rg   ÚForwardTÚ	BackwardTr	   r	   r	   r   Ú<module>   sB    "ÿ$	1