JL i7(dZddlmZmZddlmZGddeZGddeZGd d eZGd d eZ Gd deZ dZ dZ ee e Z e e e ZGddeZdZdZdZdZeee Ze ee Ze eedZGddeZdZdZeeeZe eedZdZGddeZd Zd!ZeeeZ e eeZ!y")#z CCG Combinators )ABCMetaabstractmethod)FunctionalCategoryc0eZdZdZedZedZy)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. cyNselffunctionarguments Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/ccg/combinator.py can_combinez&UndirectedBinaryCombinator.can_combine cyr r r s rcombinez"UndirectedBinaryCombinator.combine rrN__name__ __module__ __qualname____doc__rrrr rrrrs/     rr) metaclassc0eZdZdZedZedZy)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. cyr r r leftrights rrz$DirectedBinaryCombinator.can_combine-rrcyr r rs rrz DirectedBinaryCombinator.combine1rrNrr rrrr%s/    rrc*eZdZdZddZdZdZdZy)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.||_||_||_yr  _combinator _predicate_suffixr combinator predicatesuffixs r__init__zForwardCombinator.__init__>%# rcb|jj||xr|j||Sr r&rr'rs rrzForwardCombinator.can_combineCs2++D%8 T__ %>  rc#XK|jj||Ed{y7wr r&rrs rrzForwardCombinator.combineHs"##++D%888 *(*c8d|j|jS)N>r&r(r s r__str__zForwardCombinator.__str__K4##$T\\N33rNrrrrr-rrr8r rrr#r#6s  94rr#c*eZdZdZddZdZdZdZy)BackwardCombinatorzA The backward equivalent of the ForwardCombinator class. c.||_||_||_yr r%r)s rr-zBackwardCombinator.__init__Tr.rcb|jj||xr|j||Sr r0rs rrzBackwardCombinator.can_combineYs2++E48 T__ %>  rc#XK|jj||Ed{y7wr r2rs rrzBackwardCombinator.combine^s"##++E4888r3c8d|j|jS)Nr>Os  94rr>c"eZdZdZdZdZdZy)UndirectedFunctionApplicationz Class representing function application. Implements rules of the form: X/Y Y -> X (>) And the corresponding backwards application rule cf|jsy|jj|duSNF) is_functionarg can_unifyr s rrz)UndirectedFunctionApplication.can_combinems-##%<<>++H5==rc#K|jsy|jj|}|y|jj |ywr )rHrIrJres substituter r rsubss rrz%UndirectedFunctionApplication.combinessJ##% ||~''1 < lln''--sAAcy)Nr;r r7s rr8z%UndirectedFunctionApplication.__str__}srNrrrrrrr8r rrrErEes> .rrEc>|jjSr dir is_forwardrr s r forwardOnlyrWs 88: ""rc>|jjSr rT is_backwardrVs r backwardOnlyr[s 99; " " $$rc"eZdZdZdZdZdZy)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|jr|jsy|jjrM|jjr/|jj |j duSyrG)rHrT can_composerIrJrLr s rrz!UndirectedComposition.can_combinesf$$&8+?+?+A <<> % % 'HLLN,F,F,H||~// ?4G Grc#K|jr|jsy|jjr|jjr|jj |j }|Xt |j j||jj||jyyyywr )rHrTr_rIrJrLrrMrNs rrzUndirectedComposition.combines$$&8+?+?+A  <<> % % 'HLLN,F,F,H<<>++HLLN;D(LLN--d3LLN--d3LLN -I 'sC(C*cy)NBr r7s rr8zUndirectedComposition.__str__rNrQr rrr]r]s rr]c~|jjxr|jjSr rSrVs r bothForwardres+ 88: " ?uyy{'='='??rc~|jjxr|jjSr rYrVs r bothBackwardrgs+ 88: ! ! # A (?(?(AArc~|jjxr|jjSr )rTrUrZrVs r crossedDirsris+ 88: " @uyy{'>'>'@@rct||sy|jjs|jjry|jj SrG)rirT can_crossrI is_primitiverVs rbackwardBxConstraintrmsJ tU # 88:   !eiik&;&;&= 88: " " $$rx)r,c"eZdZdZdZdZdZy)UndirectedSubstitutionz Substitution (permutation) combinator. Implements rules of the form Y/Z (X\Y)/Z -> X/Z ( & & (||~**, **,1K1K1M ""$ 6 LLNhlln , rc#K|j||rHt|jj|j|j yywr )rrrLrIrTr s rrzUndirectedSubstitution.combinesJ   Hh /$ ""$hllnhlln  0sAAcy)NSr r7s rr8zUndirectedSubstitution.__str__rcrNrQr rrrprps " rrpct||sy|jjjxr|j j SrG)rerLrTrUrIrlrVs rforwardSConstraintrvs? tU # 88:>>  & & ( FTXXZ-D-D-FFrc.|jjs|jjryt||sy|jjj xr|j j SrG)rTrkrerLrZrIrlrVs rbackwardSxConstraintrxse 88:   !eiik&;&;&= tU # 99;??  ( ( * Iuyy{/G/G/IIrc|jjr/|j}|jjr/|Sr )rLrH)categs rinnermostFunctionr{s8 ))+ ! ! #  ))+ ! ! # Lrc"eZdZdZdZdZdZy)UndirectedTypeRaisez1 Undirected combinator for type raising. c|jr|jjsyt|}tj t j }|yy)NFT)rHrLr{rrJ arg_categrI)r r rIrOs rrzUndirectedTypeRaise.can_combinesN!cggi&;&;&=$~~immo.  rc #K|jr.|jr|jjsyt|}|j |j }|W|jj |}t|t|||j|j yywr ) rlrHrLr{rJrIrMrrT)r r rIrOxcats rrzUndirectedTypeRaise.combine/s  ! ! #(9cggi>S>S>U  $!!#''),  779''-D$(xCswwy\  sCCcy)NTr r7s rr8zUndirectedTypeRaise.__str__?rcrNrQr rrr}r}s& rr}ct|}|jjxr|jj Sr )r{rTrZrLrlrr rIs rforwardTConstraintrHs5 E "C 779 " ?swwy'='='??rct|}|jjxr|jj Sr )r{rTrUrLrlrs rbackwardTConstraintrMs5 D !C 779   ! >cggi&<&<&>>rN)"rabcrr nltk.ccg.apirrrr#r>rErWr[ForwardApplicationBackwardApplicationr]rergrirmForwardCompositionBackwardComposition BackwardBxrprvrxForwardSubstitution BackwardSxr{r}rrForwardT BackwardTr rrrsd(+ 7 *  "4042414,$>@# % ''D'F T()F)H,W6D@B A%''<'> L()>)@,O 1# 7 HGJ((>(@BTU  6 8:NPS T  )4)b@ ? 024F G 246I J r