
    /h'                         S SK JrJr  S SKJr  S SKJr  \ " S S\S95       r " S S\5      r\ " S	 S
5      5       r	 " S S\5      r
 " S S\5      rg)    )ABCMetaabstractmethod)total_ordering)raise_unorderable_typesc                       \ rS rSrSr\S 5       r\S 5       r\S 5       r\S 5       r	\S 5       r
\S 5       rS	 rS
 rS rS rSrg)AbstractCCGCategory   z3
Interface for categories in combinatory grammars.
c                     g)z,
Returns true if the category is primitive.
N selfs    D/var/www/auris/envauris/lib/python3.13/site-packages/nltk/ccg/api.pyis_primitive AbstractCCGCategory.is_primitive           c                     g)z9
Returns true if the category is a function application.
Nr   r   s    r   is_functionAbstractCCGCategory.is_function   r   r   c                     g)z-
Returns true if the category is a variable.
Nr   r   s    r   is_varAbstractCCGCategory.is_var    r   r   c                     g)z~
Takes a set of (var, category) substitutions, and replaces every
occurrence of the variable with the corresponding category.
Nr   )r   substitutionss     r   
substituteAbstractCCGCategory.substitute&   r   r   c                     g)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_unifyAbstractCCGCategory.can_unify-   r   r   c                     g Nr   r   s    r   __str__AbstractCCGCategory.__str__6   s    r   c                 r    U R                   UR                   L =(       a    U R                  UR                  :H  $ r#   	__class___comparison_keyr   s     r   __eq__AbstractCCGCategory.__eq__:   0    NNeoo- >$$(=(==	
r   c                     X:X  + $ r#   r   r   s     r   __ne__AbstractCCGCategory.__ne__@         r   c                    [        U[        5      (       d  [        SX5        U R                  UR                  L a  U R                  UR                  :  $ U R                  R
                  UR                  R
                  :  $ N<)
isinstancer   r   r(   r)   __name__r   s     r   __lt__AbstractCCGCategory.__lt__C   s`    %!455#C5>>U__,''%*?*???>>**U__-E-EEEr   c                      U R                   $ ! [         a)    [        U R                  5      U l         U R                   s $ f = fr#   _hashAttributeErrorhashr)   r   s    r   __hash__AbstractCCGCategory.__hash__K   <    	:: 	d223DJ::	    0A A)r:   N)r5   
__module____qualname____firstlineno____doc__r   r   r   r   r   r    r$   r*   r.   r6   r=   __static_attributes__r   r   r   r   r      s      
  
  
      
!Fr   r   )	metaclassc                   p    \ rS rSrSrSrSS jr\S 5       r\S 5       r	S r
S rS	 rS
 rS rS rS rSrg)CCGVarS   z
Class representing a variable CCG category.
Used for conjunctions (and possibly type-raising, if implemented as a
unary rule).
r   c                 \    U R                  5       U l        Xl        U R                  U l        g)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__CCGVar.__init__\   s"     ;;=##xxr   c                 H    U R                   S-   U l         U R                   S-
  $ )zD
A class method allowing generation of unique variable identifiers.
   _maxIDclss    r   rK   CCGVar.new_idg   s!    
 ZZ!^
zzA~r   c                     SU l         g )Nr   rS   rU   s    r   reset_idCCGVar.reset_ido   s	    
r   c                     gNFr   r   s    r   r   CCGVar.is_primitives       r   c                     gr\   r   r   s    r   r   CCGVar.is_functionv   r^   r   c                     gNTr   r   s    r   r   CCGVar.is_vary       r   c                 .    U H  u  p#X :X  d  M  Us  $    U $ )z\If there is a substitution corresponding to this variable,
return the substituted category.
r   )r   r   varcats       r   r   CCGVar.substitute|   s!     &HC{
 & r   c                 X    UR                  5       (       d  U R                  (       d  X4/$ g)zGIf the variable can be replaced with other
a substitution is returned.
N)r   rM   r   s     r   r    CCGVar.can_unify   s&     tM?"r   c                     U R                   $ r#   )rL   r   s    r   id	CCGVar.id   s    xxr   c                 2    S[        U R                  5      -   $ )N_var)strrL   r   s    r   r$   CCGVar.__str__   s    DHH%%r   )r)   rL   rM   N)F)r5   rA   rB   rC   rD   rT   rO   classmethodrK   rY   r   r   r   r   r    rl   r$   rE   r   r   r   rH   rH   S   s^     F	(    &r   rH   c                   x    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSrg)	Direction   z
Class representing the direction of a function application.
Also contains maintains information as to which combinators
may be used with the category.
c                 @    Xl         X l        U[        U5      4U l        g r#   )_dir_restrstupler)   )r   dirrestrictionss      r   rO   Direction.__init__   s    	# #U<%89r   c                      U R                   S:H  $ )N/rw   r   s    r   
is_forwardDirection.is_forward   s    yyCr   c                      U R                   S:H  $ )N\r   r   s    r   is_backwardDirection.is_backward   s    yyD  r   c                     U R                   $ r#   r   r   s    r   rz   Direction.dir       yyr   c                     U R                   $ )a  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)
rx   r   s    r   restrsDirection.restrs   s     ||r   c                      U R                   S:H  $ N_r   r   s    r   is_variableDirection.is_variable   s    ||s""r   c                     UR                  5       (       a  SU R                  5       4/$ U R                  5       (       a  SUR                  5       4/$ U R                  5       UR                  5       :X  a  / $ g r   )r   r   r   s     r   r    Direction.can_unify   sd    $++-())%,,.)**{{}.	r   c                     U R                  5       (       d  U $ U H#  u  p#US:X  d  M  [        U R                  U5      s  $    U $ r   )r   rt   rw   )r   subsrf   r   s       r   r   Direction.substitute   sA    !!KKCcz F33   r   c                      SU R                   ;  $ )N,r   r   s    r   can_composeDirection.can_compose       $,,&&r   c                      SU R                   ;  $ )N.r   r   s    r   	can_crossDirection.can_cross   r   r   c                 r    U R                   UR                   L =(       a    U R                  UR                  :H  $ r#   r'   r   s     r   r*   Direction.__eq__   r,   r   c                     X:X  + $ r#   r   r   s     r   r.   Direction.__ne__   r0   r   c                    [        U[        5      (       d  [        SX5        U R                  UR                  L a  U R                  UR                  :  $ U R                  R
                  UR                  R
                  :  $ r2   )r4   rt   r   r(   r)   r5   r   s     r   r6   Direction.__lt__   s_    %++#C5>>U__,''%*?*???>>**U__-E-EEEr   c                      U R                   $ ! [         a)    [        U R                  5      U l         U R                   s $ f = fr#   r9   r   s    r   r=   Direction.__hash__   r?   r@   c                 \    SnU R                    H  nUSU-  -   nM     U R                   U 3$ )N %s)rx   rw   )r   r_strrs      r   r$   Direction.__str__   s6    AD1H$E ))UG$$r   c                 z    U R                   S:X  a  [        SU R                  5      $ [        SU R                  5      $ )Nr~   r   )rw   rt   rx   r   s    r   __neg__Direction.__neg__   s0    99T4<<00S$,,//r   )r)   rw   r:   rx   N)r5   rA   rB   rC   rD   rO   r   r   rz   r   r   r    r   r   r   r*   r.   r6   r=   r$   r   rE   r   r   r   rt   rt      sX    : !#''
!F%0r   rt   c                   T    \ rS rSrSr/ 4S jrS rS rS rS r	S r
S	 rS
 rS rSrg)PrimitiveCategory   z
Class representing primitive categories.
Takes a string representation of the category, and a
list of strings specifying the morphological subcategories.
c                 @    Xl         X l        U[        U5      4U l        g r#   )_categrx   ry   r)   )r   categr{   s      r   rO   PrimitiveCategory.__init__  s    # %u\':;r   c                     grb   r   r   s    r   r   PrimitiveCategory.is_primitive  rd   r   c                     gr\   r   r   s    r   r   PrimitiveCategory.is_function	  r^   r   c                     gr\   r   r   s    r   r   PrimitiveCategory.is_var  r^   r   c                     U R                   $ r#   r   r   s    r   r   PrimitiveCategory.restrs  s    ||r   c                     U R                   $ r#   )r   r   s    r   r   PrimitiveCategory.categ  s    {{r   c                     U $ r#   r   )r   r   s     r   r   PrimitiveCategory.substitute  s    r   c                     UR                  5       (       d  g UR                  5       (       a  X4/$ UR                  5       U R                  5       :X  a*  U R                   H  nX!R	                  5       ;  d  M    g    / $ g r#   )r   r   r   rx   r   )r   r   restrs      r   r    PrimitiveCategory.can_unify  sd    !!##<<>>M?";;=DJJL(. & Ir   c                     U R                   / :X  a  SU R                  -  $ SSR                  S U R                    5       5      -  nU R                   U 3$ )Nr   z[%s]r   c              3   8   #    U  H  n[        U5      v   M     g 7fr#   )repr).0r   s     r   	<genexpr>,PrimitiveCategory.__str__.<locals>.<genexpr>+  s     (G,Qa,s   )rx   r   join)r   r{   s     r   r$   PrimitiveCategory.__str__(  sM    <<2$++%%(G$,,(G GG++|n--r   )r   r)   rx   N)r5   rA   rB   rC   rD   rO   r   r   r   r   r   r   r    r$   rE   r   r   r   r   r      s9     ,. <

.r   r   c                   T    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rS rS rSrg)FunctionalCategoryi/  z
Class that represents a function application category.
Consists of argument and result categories, together with
an application direction.
c                 :    Xl         X l        X0l        X#U4U l        g r#   )_res_argrw   r)   )r   resargrz   s       r   rO   FunctionalCategory.__init__6  s    			 ##r   c                     gr\   r   r   s    r   r   FunctionalCategory.is_primitive<  r^   r   c                     grb   r   r   s    r   r   FunctionalCategory.is_function?  rd   r   c                     gr\   r   r   s    r   r   FunctionalCategory.is_varB  r^   r   c                     U R                   R                  U5      nU R                  R                  U5      nU R                  R                  U5      n[	        X$U R                  5      $ r#   )r   r   rw   r   r   )r   r   sub_ressub_dirsub_args        r   r   FunctionalCategory.substituteG  sO    ))&&t,))&&t,))&&t,!'DII>>r   c                    UR                  5       (       a  X4/$ UR                  5       (       a  U R                  R                  UR	                  5       5      nU R
                  R                  UR                  5       5      nUbQ  UbN  U R                  R                  U5      R                  UR                  5       R                  U5      5      nUb  X$-   $ g r#   )
r   r   r   r    r   rw   rz   r   r   r   )r   r   sasdsbs        r   r    FunctionalCategory.can_unifyO  s    <<>>M?"$$UYY[1B$$UYY[1B~".YY))"-77		8N8Nr8RS>7Nr   c                     U R                   $ r#   )r   r   s    r   r   FunctionalCategory.arg\  r   r   c                     U R                   $ r#   )r   r   s    r   r   FunctionalCategory.res_  r   r   c                     U R                   $ r#   r   r   s    r   rz   FunctionalCategory.dirb  r   r   c                 R    SU R                    U R                   U R                   S3$ )N())r   rw   r   r   s    r   r$   FunctionalCategory.__str__e  s%    499+dii[155r   )r   r)   rw   r   N)r5   rA   rB   rC   rD   rO   r   r   r   r   r    r   r   rz   r$   rE   r   r   r   r   r   /  s9    /
?
6r   r   N)abcr   r   	functoolsr   nltk.internalsr   r   rH   rt   r   r   r   r   r   <module>r      su    ( $ 2 AG A AH>&  >&B b0 b0 b0J2.+ 2.j76, 76r   