JL i'ddlmZmZddlmZddlmZeGddeZGddeZeGd d Z Gd d eZ Gd deZ y))ABCMetaabstractmethod)total_ordering)raise_unorderable_typesceZdZdZedZedZedZedZedZ edZ dZ d Z d Z d Zy ) AbstractCCGCategoryz; Interface for categories in combinatory grammars. cy)z< Returns true if the category is primitive. Nselfs R/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/ccg/api.py is_primitivez AbstractCCGCategory.is_primitivecy)zI Returns true if the category is a function application. Nr r s r is_functionzAbstractCCGCategory.is_functionrrcy)z= Returns true if the category is a variable. Nr r s r is_varzAbstractCCGCategory.is_var rrcy)z Takes a set of (var, category) substitutions, and replaces every occurrence of the variable with the corresponding category. Nr )r substitutionss r substitutezAbstractCCGCategory.substitute&rrcy)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_unifyzAbstractCCGCategory.can_unify-rrcyNr r s r __str__zAbstractCCGCategory.__str__6s rch|j|juxr|j|jk(Sr __class___comparison_keyrs r __eq__zAbstractCCGCategory.__eq__:0 NNeoo - >$$(=(== rc||k( Srr rs r __ne__zAbstractCCGCategory.__ne__@5=  rct|ts td|||j|jur|j|jkS|jj |jj kSN<) isinstancerrr!r"__name__rs r __lt__zAbstractCCGCategory.__lt__Cs_%!45 #Cu 5 >>U__ ,''%*?*?? ?>>**U__-E-EE Erc |jS#t$r)t|j|_|jcYSwxYwr_hashAttributeErrorhashr"r s r __hash__zAbstractCCGCategory.__hash__K< ::  d223DJ::   /AAN)r, __module__ __qualname____doc__rrrrrrrr#r&r-r3r rr rrs             !Frr) metaclasscfeZdZdZdZddZedZedZdZ dZ dZ d Z d Z d Zd Zy )CCGVarz Class representing a variable CCG category. Used for conjunctions (and possibly type-raising, if implemented as a unary rule). rc^|j|_||_|j|_y)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__zCCGVar.__init__\s$;;=##xxrcH|jdz|_|jdz S)zT A class method allowing generation of unique variable identifiers. _maxIDclss r r=z CCGVar.new_idgs! ZZ!^ zzA~rcd|_y)NrrDrFs r reset_idzCCGVar.reset_idos  rcyNFr r s r rzCCGVar.is_primitivesrcyrKr r s r rzCCGVar.is_functionvrLrcyNTr r s r rz CCGVar.is_varyrc,|D]\}}||k(s |cS|S)zlIf there is a substitution corresponding to this variable, return the substituted category. r )r rvarcats r rzCCGVar.substitute|s*& HCd{   rcF|js |js||fgSy)zWIf the variable can be replaced with other a substitution is returned. N)rr?rs r rzCCGVar.can_unifys%    t5M? "rc|jSr)r>r s r idz CCGVar.ids xxrc2dt|jzS)N_var)strr>r s r rzCCGVar.__str__sDHH %%rN)F)r,r6r7r8rErA classmethodr=rIrrrrrrVrr rr r;r;Ss^ F (&rr;cpeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZy) Directionz Class representing the direction of a function application. Also contains maintains information as to which combinators may be used with the category. cD||_||_|t|f|_yr)_dir_restrstupler")r dir restrictionss r rAzDirection.__init__s" # #U<%89rc |jdk(S)N/r^r s r is_forwardzDirection.is_forwardsyyCrc |jdk(S)N\rer s r is_backwardzDirection.is_backwardsyyD  rc|jSrrer s r raz Direction.dir yyrc|jS)a8A 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) r_r s r restrszDirection.restrss||rc |jdk(SN_rmr s r is_variablezDirection.is_variables||s""rc|jrd|jfgS|jrd|jfgS|j|jk(rgSyrp)rrrnrs r rzDirection.can_unifys^    $++-() )    %,,.)* *{{} . rcx|js|S|D]"\}}|dk(s t|j|cS|Srp)rrr\r^)r subsrRrns r rzDirection.substitutesE!K 4KCcz F33 4 rcd|jvS)N,rmr s r can_composezDirection.can_compose$,,&&rcd|jvS)N.rmr s r can_crosszDirection.can_crossryrch|j|juxr|j|jk(Srr rs r r#zDirection.__eq__r$rc||k( Srr rs r r&zDirection.__ne__r'rct|ts td|||j|jur|j|jkS|jj |jj kSr))r+r\rr!r"r,rs r r-zDirection.__lt__s^%+ #Cu 5 >>U__ ,''%*?*?? ?>>**U__-E-EE Erc |jS#t$r)t|j|_|jcYSwxYwrr/r s r r3zDirection.__hash__r4r5cXd}|jD] }|d|zz} |j|S)N%s)r_r^)r r_strrs r rzDirection.__str__s; %AD1H$E %))UG$$rcx|jdk(rtd|jStd|jS)Nrdrh)r^r\r_r s r __neg__zDirection.__neg__s0 99 T4<<0 0S$,,/ /rN)r,r6r7r8rArfrirarnrrrrrxr|r#r&r-r3rrr rr r\r\sX :  !# '' !F%0rr\cJeZdZdZgfdZdZdZdZdZdZ dZ d Z d Z y ) PrimitiveCategoryz Class representing primitive categories. Takes a string representation of the category, and a list of strings specifying the morphological subcategories. cD||_||_|t|f|_yr)_categr_r`r")r categrbs r rAzPrimitiveCategory.__init__s" # %u\':;rcyrOr r s r rzPrimitiveCategory.is_primitiverPrcyrKr r s r rzPrimitiveCategory.is_function rLrcyrKr r s r rzPrimitiveCategory.is_var rLrc|jSrrmr s r rnzPrimitiveCategory.restrss ||rc|jSr)rr s r rzPrimitiveCategory.categs {{rc|Srr )r rus r rzPrimitiveCategory.substitutes rc|jsy|jr||fgS|j|jk(r'|jD]}||j vsygSyr)rrrr_rn)r rrestrs r rzPrimitiveCategory.can_unifysh!!# <<>DM? " ;;=DJJL (  . Irc|jgk(rd|jzSddjd|jDz}|j|S)Nrz[%s]rwc32K|]}t|ywr)repr).0rs r z,PrimitiveCategory.__str__..+s(GQa(Gs)r_rjoin)r rbs r rzPrimitiveCategory.__str__(sM <<2 $++% %(G$,,(G GG ++|n--rN) r,r6r7r8rArrrrnrrrrr rr rrs9 ,.<  .rrcLeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) FunctionalCategoryz Class that represents a function application category. Consists of argument and result categories, together with an application direction. cB||_||_||_|||f|_yr)_res_argr^r")r resargras r rAzFunctionalCategory.__init__6s%   #S#rcyrKr r s r rzFunctionalCategory.is_primitive<rLrcyrOr r s r rzFunctionalCategory.is_function?rPrcyrKr r s r rzFunctionalCategory.is_varBrLrc|jj|}|jj|}|jj|}t |||jSr)rrr^rr)r rusub_ressub_dirsub_args r rzFunctionalCategory.substituteGsQ))&&t,))&&t,))&&t,!'7DII>>rc|jr||fgS|jr|jj|j }|j j|j }|P|N|jj|j|jj|}|||zSyr) rrrrrr^rarrr)r rsasdsbs r rzFunctionalCategory.can_unifyOs <<>DM? "    $$UYY[1B$$UYY[1B~".YY))"-77 8N8Nr8RS>7Nrc|jSr)rr s r rzFunctionalCategory.arg\rkrc|jSr)rr s r rzFunctionalCategory.res_rkrc|jSrrer s r razFunctionalCategory.dirbrkrcRd|j|j|jdS)N())rr^rr s r rzFunctionalCategory.__str__es%499+dii[ 155rN)r,r6r7r8rArrrrrrrrarr rr rr/s9 /  ? 6rrN) abcrr functoolsrnltk.internalsrrr;r\rrr rr rsu($2AGAAH>& >&Bb0b0b0J2.+2.j76,76r