
    /h7(                     
   S r SSKJrJr  SSKJr   " S S\S9r " S S\S9r " S	 S
\5      r " S S\5      r	 " S S\5      r
S rS r\" \
" 5       \5      r\	" \
" 5       \5      r " S S\5      rS rS rS rS r\" \" 5       \5      r\	" \" 5       \5      r\	" \" 5       \SS9r " S S\5      rS rS r\" \" 5       \5      r\	" \" 5       \S5      rS r " S S\5      rS  rS! r\" \" 5       \5      r \	" \" 5       \5      r!g")#z
CCG Combinators
    )ABCMetaabstractmethod)FunctionalCategoryc                   8    \ rS rSrSr\S 5       r\S 5       rSrg)UndirectedBinaryCombinator   a  
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                     g N selffunctionarguments      K/var/www/auris/envauris/lib/python3.13/site-packages/nltk/ccg/combinator.pycan_combine&UndirectedBinaryCombinator.can_combine           c                     g r
   r   r   s      r   combine"UndirectedBinaryCombinator.combine    r   r   r   N	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__r   r   r   r   r      s/    	    r   r   )	metaclassc                   8    \ rS rSrSr\S 5       r\S 5       rSrg)DirectedBinaryCombinator%   z
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                     g r
   r   r   leftrights      r   r   $DirectedBinaryCombinator.can_combine-   r   r   c                     g r
   r   r$   s      r   r    DirectedBinaryCombinator.combine1   r   r   r   Nr   r   r   r   r!   r!   %   s/        r   r!   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
ForwardCombinator6   z
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                 (    Xl         X l        X0l        g r
   _combinator
_predicate_suffixr   
combinator	predicatesuffixs       r   __init__ForwardCombinator.__init__>       %#r   c                 h    U R                   R                  X5      =(       a    U R                  X5      $ r
   r/   r   r0   r$   s      r   r   ForwardCombinator.can_combineC   s.    ++D8 
T__>
 	
r   c              #   V   #    U R                   R                  X5       S h  vN   g  N7fr
   r/   r   r$   s      r   r   ForwardCombinator.combineH   s     ##++D888   )')c                 8    SU R                    U R                   3$ )N>r/   r1   r   s    r   __str__ForwardCombinator.__str__K       4##$T\\N33r   r.   N 
r   r   r   r   r   r6   r   r   rD   r   r   r   r   r+   r+   6   s    


94r   r+   c                   4    \ rS rSrSrS	S jrS rS rS rSr	g)
BackwardCombinatorO   z9
The backward equivalent of the ForwardCombinator class.
c                 (    Xl         X l        X0l        g r
   r.   r2   s       r   r6   BackwardCombinator.__init__T   r8   r   c                 h    U R                   R                  X!5      =(       a    U R                  X5      $ r
   r:   r$   s      r   r   BackwardCombinator.can_combineY   s.    ++E8 
T__>
 	
r   c              #   V   #    U R                   R                  X!5       S h  vN   g  N7fr
   r=   r$   s      r   r   BackwardCombinator.combine^   s     ##++E888r?   c                 8    SU R                    U R                   3$ )N<rB   rC   s    r   rD   BackwardCombinator.__str__a   rF   r   r.   NrG   rI   r   r   r   rK   rK   O   s    


94r   rK   c                   *    \ rS rSrSrS rS rS rSrg)UndirectedFunctionApplicatione   z
Class representing function application.
Implements rules of the form:
X/Y Y -> X (>)
And the corresponding backwards application rule
c                 p    UR                  5       (       d  gUR                  5       R                  U5      S L$ NF)is_functionarg	can_unifyr   s      r   r   )UndirectedFunctionApplication.can_combinem   s0    ##%%<<>++H5==r   c              #      #    UR                  5       (       d  g UR                  5       R                  U5      nUc  g UR                  5       R	                  U5      v   g 7fr
   )r[   r\   r]   res
substituter   r   r   subss       r   r   %UndirectedFunctionApplication.combines   sL     ##%%||~''1<lln''--s   AAc                     g)NrH   r   rC   s    r   rD   %UndirectedFunctionApplication.__str__}   s    r   r   N	r   r   r   r   r   r   r   rD   r   r   r   r   rW   rW   e   s    >.r   rW   c                 >    U R                  5       R                  5       $ r
   dir
is_forwardr%   r&   s     r   forwardOnlyrm      s    88:  ""r   c                 >    UR                  5       R                  5       $ r
   rj   is_backwardrl   s     r   backwardOnlyrq      s    99;""$$r   c                   *    \ rS rSrSrS rS rS rSrg)UndirectedComposition   z
Functional composition (harmonic) combinator.
Implements rules of the form
X/Y Y/Z -> X/Z (B>)
And the corresponding backwards and crossed variations.
c                 D   UR                  5       (       a  UR                  5       (       d  gUR                  5       R                  5       (       aR  UR                  5       R                  5       (       a/  UR                  5       R	                  UR                  5       5      S L$ grZ   )r[   rj   can_composer\   r]   r`   r   s      r   r   !UndirectedComposition.can_combine   sr     $$&&8+?+?+A+A<<>%%''HLLN,F,F,H,H||~//?4GGr   c              #     #    UR                  5       (       a  UR                  5       (       d  g UR                  5       R                  5       (       a  UR                  5       R                  5       (       a  UR                  5       R	                  UR                  5       5      nUbX  [        UR                  5       R                  U5      UR                  5       R                  U5      UR                  5       5      v   g g g g 7fr
   )r[   rj   rv   r\   r]   r`   r   ra   rb   s       r   r   UndirectedComposition.combine   s     $$&&8+?+?+A+A<<>%%''HLLN,F,F,H,H<<>++HLLN;D(LLN--d3LLN--d3LLN    -I's   C=C?c                     g)NBr   rC   s    r   rD   UndirectedComposition.__str__       r   r   Nrg   r   r   r   rs   rs      s    
r   rs   c                     U R                  5       R                  5       =(       a    UR                  5       R                  5       $ r
   ri   rl   s     r   bothForwardr      s+    88:  "?uyy{'='='??r   c                     U R                  5       R                  5       =(       a    UR                  5       R                  5       $ r
   ro   rl   s     r   bothBackwardr      s+    88:!!#A		(?(?(AAr   c                     U R                  5       R                  5       =(       a    UR                  5       R                  5       $ r
   )rj   rk   rp   rl   s     r   crossedDirsr      s+    88:  "@uyy{'>'>'@@r   c                     [        X5      (       d  gU R                  5       R                  5       (       d$  UR                  5       R                  5       (       a  gU R                  5       R	                  5       $ rZ   )r   rj   	can_crossr\   is_primitiverl   s     r   backwardBxConstraintr      sQ    t##88:!!eiik&;&;&=&=88:""$$r   x)r5   c                   *    \ rS rSrSrS rS rS rSrg)UndirectedSubstitution   zt
Substitution (permutation) combinator.
Implements rules of the form
Y/Z (X\Y)/Z -> X/Z (<Sx)
And other variations.
c                 $   UR                  5       (       d  UR                  5       (       a  gUR                  5       R                  5       (       a  gUR                  5       R                  5       (       d  gUR                  5       R	                  5       (       a#  UR                  5       R	                  5       (       d  gUR                  5       R                  5       UR                  5       :H  =(       a!    UR                  5       UR                  5       :H  $ rZ   )r   r`   r\   rj   rv   r   s      r   r   "UndirectedSubstitution.can_combine   s      ""h&;&;&=&= <<>&&((||~**,,**,,1K1K1M1M""$6 
LLNhlln,	
r   c              #      #    U R                  X5      (       aH  [        UR                  5       R                  5       UR                  5       UR	                  5       5      v   g g 7fr
   )r   r   r`   r\   rj   r   s      r   r   UndirectedSubstitution.combine   sJ     H//$""$hllnhlln  0s   A A"c                     g)NSr   rC   s    r   rD   UndirectedSubstitution.__str__   r}   r   r   Nrg   r   r   r   r   r      s    
"r   r   c                     [        X5      (       d  gU R                  5       R                  5       R                  5       =(       a    U R	                  5       R                  5       $ rZ   )r   r`   rj   rk   r\   r   rl   s     r   forwardSConstraintr      s@    t##88:>>&&(FTXXZ-D-D-FFr   c                 T   U R                  5       R                  5       (       d$  UR                  5       R                  5       (       a  g[        X5      (       d  gUR                  5       R                  5       R	                  5       =(       a    UR                  5       R                  5       $ rZ   )rj   r   r   r`   rp   r\   r   rl   s     r   backwardSxConstraintr     sl    88:!!eiik&;&;&=&=t##99;??((*Iuyy{/G/G/IIr   c                     U R                  5       R                  5       (       a5  U R                  5       n U R                  5       R                  5       (       a  M5  U $ r
   )r`   r[   )categs    r   innermostFunctionr     s>    
))+
!
!
#
#		 ))+
!
!
#
#Lr   c                   *    \ rS rSrSrS rS rS rSrg)UndirectedTypeRaisei  z)
Undirected combinator for type raising.
c                     UR                  5       (       a#  UR                  5       R                  5       (       d  g[        U5      n[        R	                  [
        R                  5       5      nUb  gg)NFT)r[   r`   r   r%   r]   	arg_categr\   )r   r   r\   rc   s       r   r   UndirectedTypeRaise.can_combine  sT     !!cggi&;&;&=&=$ ~~immo.r   c           	   #     #    UR                  5       (       a8  UR                  5       (       a#  UR                  5       R                  5       (       d  g [        U5      nUR	                  UR                  5       5      nUbV  UR                  5       R                  U5      n[        U[        XAUR                  5       5      UR                  5       * 5      v   g g 7fr
   )	r   r[   r`   r   r]   r\   ra   r   rj   )r   r   r\   rc   xcats        r   r   UndirectedTypeRaise.combine/  s     !!##(9(9cggi>S>S>U>U  $!!#''),779''-D$(Cswwy\  s   CCc                     g)NTr   rC   s    r   rD   UndirectedTypeRaise.__str__?  r}   r   r   Nrg   r   r   r   r   r     s    & r   r   c                     [        U5      nUR                  5       R                  5       =(       a    UR                  5       R	                  5       $ r
   )r   rj   rp   r`   r   r%   r&   r\   s      r   forwardTConstraintr   H  s5    
E
"C779  "?swwy'='='??r   c                     [        U 5      nUR                  5       R                  5       =(       a    UR                  5       R	                  5       $ r
   )r   rj   rk   r`   r   r   s      r   backwardTConstraintr   M  s5    
D
!C779!>cggi&<&<&>>r   N)"r   abcr   r   nltk.ccg.apir   r   r!   r+   rK   rW   rm   rq   ForwardApplicationBackwardApplicationrs   r   r   r   r   ForwardCompositionBackwardComposition
BackwardBxr   r   r   ForwardSubstitution
BackwardSxr   r   r   r   ForwardT	BackwardTr   r   r   <module>r      sd   ( +7 * "40 4241 4,$> @#
%
 ''D'FT ()F)H,W 6 D@B
A% ''<'>L ()>)@,O   1#

 7  HGJ ((>(@BTU  6 8:NPST

)4 )b@
? 024FG246IJ	r   