o
    rZh7(  ć                   @   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	   śB/var/www/auris/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   Z
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   r1   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ś<r/   r0   r	   r	   r   r1   a   r2   zBackwardCombinator.__str__Nr3   r4   r	   r	   r	   r   r5   O   s    
r5   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	   r0   r	   r	   r   r1   }   ó   z%UndirectedFunctionApplication.__str__N©r   r   r   r   r   r   r1   r	   r	   r	   r   r8   e   s
    
r8   c                 C   s   |   ”  ” S r   ©ŚdirŚ
is_forward©r   r   r	   r	   r   ŚforwardOnly   ó   rH   c                 C   s   |  ”  ” S r   ©rE   Śis_backwardrG   r	   r	   r   ŚbackwardOnly   rI   rL   c                   @   r7   )	Ś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 r9   )r:   rE   Ś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:   rE   rN   r;   r<   r=   r   r>   r?   r	   r	   r   r   ¤   s   
żżzUndirectedComposition.combinec                 C   rA   )NŚBr	   r0   r	   r	   r   r1   °   rB   zUndirectedComposition.__str__NrC   r	   r	   r	   r   rM      s
    	rM   c                 C   ó   |   ”  ” o|  ”  ” S r   rD   rG   r	   r	   r   ŚbothForwardµ   ó   rQ   c                 C   rP   r   rJ   rG   r	   r	   r   ŚbothBackward¹   rR   rS   c                 C   s   |   ”  ” o|  ”  ” S r   )rE   rF   rK   rG   r	   r	   r   ŚcrossedDirs¾   rR   rT   c                 C   s6   t | |sdS |  ”  ” s| ”  ” rdS |  ”  ” S r9   )rT   rE   Ś	can_crossr;   Śis_primitiverG   r	   r	   r   ŚbackwardBxConstraintĀ   s
   
rW   Śx)r&   c                   @   r7   )	Ś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 r9   )rV   r=   r;   rE   rN   r
   r	   r	   r   r   ß   s   ’z"UndirectedSubstitution.can_combinec                 c   s4    |   ||”rt| ”  ” | ” | ” V  d S d S r   )r   r   r=   r;   rE   r
   r	   r	   r   r   š   s   
’’zUndirectedSubstitution.combinec                 C   rA   )NŚSr	   r0   r	   r	   r   r1   ö   rB   zUndirectedSubstitution.__str__NrC   r	   r	   r	   r   rY   ×   s
    rY   c                 C   s*   t | |sdS |  ”  ”  ” o|  ”  ” S r9   )rQ   r=   rE   rF   r;   rV   rG   r	   r	   r   ŚforwardSConstraintū   s   
r[   c                 C   sF   |   ”  ” s|  ”  ” rdS t| |sdS | ”   ”  ” o"| ”  ” S r9   )rE   rU   rQ   r=   rK   r;   rV   rG   r	   r	   r   ŚbackwardSxConstraint  s
   
r\   c                 C   s$   |   ”  ” r|   ” } |   ”  ” s| S r   )r=   r:   )Zcategr	   r	   r   ŚinnermostFunction  s   ’r]   c                   @   r7   )	Ś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<   Z	arg_categr;   )r   r   r;   r@   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   )	rV   r:   r=   r]   r<   r;   r>   r   rE   )r   r   r;   r@   Zxcatr	   r	   r   r   /  s    ’’
’
’žzUndirectedTypeRaise.combinec                 C   rA   )NŚTr	   r0   r	   r	   r   r1   ?  rB   zUndirectedTypeRaise.__str__NrC   r	   r	   r	   r   r^     s
    r^   c                 C   s    t |}| ”  ” o| ”  ” S r   )r]   rE   rK   r=   rV   ©r   r   r;   r	   r	   r   ŚforwardTConstraintH  ó   ra   c                 C   s    t | }| ”  ” o| ”  ” S r   )r]   rE   rF   r=   rV   r`   r	   r	   r   ŚbackwardTConstraintM  rb   rc   N)"r   Śabcr   r   Znltk.ccg.apir   r   r   r   r5   r8   rH   rL   ZForwardApplicationZBackwardApplicationrM   rQ   rS   rT   rW   ZForwardCompositionZBackwardCompositionZ
BackwardBxrY   r[   r\   ZForwardSubstitutionZ
BackwardSxr]   r^   ra   rc   ZForwardTZ	BackwardTr	   r	   r	   r   Ś<module>   sB    "’$	1