1fH "ddlejdkreefZnefZGddeZGddeZ Gdde Z Gd d e Z e d ed ZGdde ZGdde ZdZeddZeej*ej,<eddZeddZdZdZdZdZdZdZeZdZ dZ!d Z"d!Z#d"Z$d#Z%d$Z&e'e&e(ee)e!e*ee+e e,e"iZ-ia.d.d%Z/ia0d/d&Z1ga2d0d(Z3e4Z5d)Z6d*Z7d+Z8Gd,d-e Z9y'#e$rd ZYwxYw)1)*)ceZdZdZy)InvalidTypeErrorcV|xr|dxsd}d|z}tj||g|y)NrUnknownz$Term is expected to be of type: '%s' Exception__init__)selfargstype_msgs U/var/lib/jenkins/workspace/metta-wam/venv/lib/python3.12/site-packages/pyswip/easy.pyr zInvalidTypeError.__init__%s4 a-I4u<4,t,N)__name__ __module__ __qualname__r rrrr$s-rrceZdZdZdZy)ArgumentTypeErrorz5 Thrown when an argument has the wrong type. cBd|d|d}tj||y)NzExpected an argument of type 'z ' but got ''r )r expectedgotrs rr zArgumentTypeError.__init__/sBJCP4%rN)rrr__doc__r rrrrr+s &rrcbeZdZdZd dZdZeeZdZdZe eZ dZ dZ d Z d Zy) AtomhandlecharsNct|trt||_||_y||_t |j|/t }t|jt||_y||_y)zQCreate an atom. ``handleOrChars``: handle or string of the atom. N) isinstancestr PL_new_atomr r!PL_register_atomc_size_tPL_atom_wcharsbyref)r handleOrCharsr!slens rr z Atom.__init__7s] mS )%m4DK&DJ'DK T[[ )}z+DKKtE " rcTt|tr |j}nPt|ttfs:t t tt tft t|t}t|t|r||jt|Sy)z*Create an atom from a Term or term handle.N) r#Termr c_void_p integer_typesrr$typeatom_t PL_get_atomr)value getAtomChars)clstermas rfromTermz Atom.fromTermHsx dD !;;DD8]";<#SYH $>DJP P H tU1X &qww T 23 3 'rc<tst|jyyN)cleanedPL_unregister_atomr r s r__del__z Atom.__del__Us t{{ +rc^|j}t|ts|j}|Sr:)r!r#r$decode)r rets r get_valuezAtom.get_valueYs%jj#s#**,C rcR|j |jS|jSr:)r!r3__repr__r=s r__str__z Atom.__str__as" :: !:: ==? "rcNt|jjddgS)NzAtom('z'))r$r joinr=s rrDz Atom.__repr__gs!4;;$$h%566rcdt|t|k7ry|j|jk(S)NF)r0r r others r__eq__z Atom.__eq__js( :e $;;%,,. .rc|jSr:r r=s r__hash__z Atom.__hash__p {{rr:)rrr __slots__r r8 classmethodr>rBpropertyr3rErDrKrNrrrrr4sG!I#" 48$H, Y E# 7/ rrc<eZdZdZd dZdZdZdZdZdZ d Z y) r-)r r!__valuea0NcR|r||_nt|_d|_||_yr:)r PL_new_term_refr!rU)r r rUs rr z Term.__init__ws$  DK)+DK rct|Sr:)_notr=s r __invert__zTerm.__invert__s Dzrcyr:rr=s rrBzTerm.get_values rcxt|t|k7ryt|j|jdk(SNFrr0 PL_comparer rIs rrKz Term.__eq__/ :e $dkk5<<8A= =rc|jSr:rMr=s rrNz Term.__hash__rOrcJt|jjS)NrMVariabler rEr=s rrEz Term.__str__st{{+3355rcPdt|jjzS)Nz(Term)rMrcr=s rrDz Term.__repr__s($++6>>@@@rNN) rrrrPr rZrBrKrNrErDrrrr-r-ts+2I > 6Arr-c"t|tSr:)r# basestringss risstrrls!Z((rc"t|tSr:)r#r$rjs rrlrls!S!!rc`eZdZdZd dZdZdZdZeeeZ dZ dZ d Z d Z d Zd Zy)rdrNcd|_|r||_|r\||_td}t|t}t |t |ttztzr!|j|_nt|_|j;t|jts |jj|_yyy)Ns@)r!r create_string_buffercastc_char_p PL_get_charsr) CVT_VARIABLEBUF_RINGREP_UTF8r3rWr#r$r@)r r namerkptrs rr zVariable.__init__s DJ  DK$Y/Aq(#CFE#J X0Eh0NO YY )+DK JJ "Jtzz3,G**,DJ-H "rc|jt|j}nt|j}|j||||_yr:)r rWPL_copy_term_ref_fun)r r3ts runifyzVariable.unifys= ;;  ,A -A % rc t|tk(rt}|j}nt |rt }|j }nt|tk(rt}nt|tk(rt}nwt|tk(rt}n]t|tk(rt}nCt|t r t#||yt|tr t#||yt|tr t#||yt|t$r t#||yt|t&r t#||yt|t(rt+||jyt|t&r|j-|yt|tr t/||yt|trt}|j1}n%t3dj5||t|t|tk(r]t7|j}|}|D]5}t7|j}|||||j9|||}7t;|y|||y)Nz>Cannot unify {} with value {} due to the value unknown type {})r0r PL_unify_atomr rlPL_unify_string_charsencodeintPL_unify_integerbool PL_unify_boolfloatPL_unify_floatlist PL_unify_listr#r$putTermFunctorrdr- PL_put_termputputListrB TypeErrorformatrWr{ PL_unify_nil)r r3r|funr7 list_termelement tail_terms rr{z Variable._funs ;$ CLLE 5\'CLLNE %[C "C %[D C %[E ! C %[D C s # Au   s # Au   u % Au   w ' Au   x ( Au   t $ 5<< (  8 $ IIaL  t $ Au   t $COO%E\"F4U <> > ;$  ,AI +DKK8 Iq), '1%% !  # 5Mrc,t|jSr:)getTermr r=s rrBzVariable.get_valuest{{##rc:t|jtk(Sr:) PL_term_typer PL_VARIABLEr=s runifiedzVariable.unifiedsDKK(K77rcP|j |jSd|jzS)Nz_G%s)r!r r=s rrEzVariable.__str__s% :: !:: DKK' 'rc d|jzS)Nz Variable(%s)rMr=s rrDzVariable.__repr__s ++rc0t||jyr:)rr )r r6s rrz Variable.putsD$++&rcxt|t|k7ryt|j|jdk(Sr]r^rIs rrKzVariable.__eq__ r`rc|jSr:rMr=s rrNzVariable.__hash__rOrrf)rrrrPr r}r{rBrRr3rrErDrrKrNrrrrdrdsH!I- 8t$ Y &E8( ,'> rrdcbeZdZdZiZd dZdZeeZedZ dZ dZ dZ d Z d Zy) r)r rwarityr rTrUNc|xsg|_||_||_t|trJt ||_t|j j||_d|jz|_ yt|t rA||_t|j j||_d|jz|_ y||_t t|j|_t|j|_ |j|j|jg|j|_ y#t$rt ||_ YywxYw)zYCreate a functor. ``handleOrName``: functor handle, a string or an atom. z Functor%dN)r rrUr#r$rrwPL_new_functorr _Functor__valuePL_functor_namePL_functor_arityfuncKeyError)r handleOrNamerr rUs rr zFunctor.__init__s JB   lC (\*DI()9)95ADK&4DL  d +$DI()9)95ADK&4DL&DK_T[[9:DI)$++6DJ )5tyy5djjM499M  )"4y  )s 9EE E c&t|tr |j}nPt|ttfs:t t tt tft t|t}t|t|rg}t|j}t|}tt!d|dzD]3\}}t#||||zs|j%t'||z5||j||Sy)z,Create a functor from a Term or term handle.)r rUN)r#r-r r.r/rr$rr0 functor_tPL_get_functorr)rr3PL_new_term_refs enumeraterange PL_get_argappendr)r5r6fr rrUir7s rr8zFunctor.fromTerm4s dD !;;DD8]";<#SYC$93tDz?K K K $a )D$QWW-E!%(B!%519"561arAv.KKQ07qwwTb1 1 *rc|jSr:)rrjs rzFunctor.Jsqyyrc|jt|k(sJtt|}t|D]\}}t ||z|t }t ||j|t|Sr:) rlenrrrrWPL_cons_functor_vr r-)r r r7rargr|s r__call__zFunctor.__call__LsizzSY&&& SY 'oFAs AE3 &  !T[[!,Awrc |jN|jB|jddj|jDcgc] }t |c}dS|j Scc}w)N(z, ))rwrrGr r$rD)r rs rrEzFunctor.__str__Vs[ 99 TZZ%;#yy#yydii)Hs#c()HIK K==? "*IsA+ cdjddjd|j|jg|jzDdgS)NrgzFunctor(,c32K|]}t|ywr:)r$).0xs r z#Functor.__repr__..^s-3SV-3sr)rGr rr r=s rrDzFunctor.__repr__]sKww CHH-3 DJJ' 1-3%3479: :rcxt|t|k7ryt|j|jdk(Sr]r^rIs rrKzFunctor.__eq__ar`rc|jSr:rMr=s rrNzFunctor.__hash__grOr)rNN)rrrrPrr r8rQrRr3rrErDrKrNrrrrrsFBI D)42(8$H ( )E#:> rrc|dk(sJ |dj|djiS#t$r|dj|dicYSwxYw)Nrr)r3AttributeError)rr s r_unifierrksT A::'Q d1gmm,, 'Q d1g&&'s'AA=rnotrrc6t|trt||jyt|tr t ||yt|t r t||yt|tr t||yt|tr|j|yt|tr t||yt|tr tdyt|t rt#||jyt%dt'|d|)NATOMzNot implemented r)r#r-rr r$PL_put_atom_charsrPL_put_integerr PL_put_floatrdrrrrprintrPL_put_functorr r0)r6r3s rrrxs%D%,,' E3 $& E3 tU# E5 !T5! E8 $ $ E4 e E4  f E7 #tU\\**4;-q@AArct|t|D]%}t}t||t |||'yr:) PL_put_nilreversedrWr PL_cons_list)llsitemr7s rrrs5qM   4Q1rct}t|t|ttzr |j St d)zNIf t is an atom, return it as a string, otherwise raise InvalidTypeError. atom)rrrsr)CVT_ATOMrvr3rr|rks rr4r4s4  AAuQx(!23wwv&&rc,tj|S)zCIf t is an atom, return it , otherwise raise InvalidTypeError. )rr8r|s rgetAtomrs == rct}t|t|rt|jSt d)zGIf t is of type bool, return it, otherwise raise InvalidTypeError. r)c_int PL_get_longr)rr3r)r|bs rgetBoolrs2 A1eAhAGG}v&&rcnt}t|t|r |jSt d)zGIf t is of type long, return it, otherwise raise InvalidTypeError. long)c_longrr)r3r)r|rs rgetLongrs- A1eAhwwv&&rcnt}t|t|r |jSt d)zHIf t is of type float, return it, otherwise raise InvalidTypeError. r)c_double PL_get_floatr)r3r)r|ds rgetFloatrs-  AAuQx www''rct}t|t|ttzr |j St d)zIIf t is of type string, return it, otherwise raise InvalidTypeError. string)rrrsr)rv CVT_STRINGr3rrs r getStringrs4  AAuQx*!45wwx((rc|yt5t|}|tkrt||}n7t |r t |}n |t k(r t|}n t|}|cdddS#1swYyxYwr:) PL_STRINGS_MARKrPL_TERM_getterm_router PL_is_listgetListPL_DICTgetDict getFunctor)r|press rrrspy    O w;!!$Q'C ]!*C '\!*CQ-C   s AA44A=ct|tr |j}nPt|ttfs:t t tt tft t|t}t|t|rg}t|j}t|}ttd|dzD]=\}}t!||||zr|j#t%||z4t'dt)|dd}t+||D cic]\}} | j|} }} | St-|} | Scc} }w)z& Return term as a dictionary. rz Missing argN)r#r-r r.rrr$r0rrr)rr3rrrrrrr iterzipr) r6rr rrUrr7itvkrrs rrrs ${{ xo .TCH 5s4:GG AdE!H% ) e $eAuqy12DAq!T26* GBFO, .. 3 $qr(^$'BK 0DAqQWWaZ 0 0 1s$E ct|}t}g}t|||r2|jt |t}t|||r2|S)z Return t as a list. )rzrW PL_get_listrr)rr|headresults rrrsT A  D F aq ! gdm$  aq ! Mrc,tj|S)zReturn t as a functor )rr8rs rrr s   A rct|Sr:)rdrs r getVariabler s A;rctj||f}|F|r!ttgtg|zzt gz}nttgtg|zz}|t||f<|Sr:)aritiesget CFUNCTYPE foreign_tterm_t control_t)rnondeterministicrs r_callbackWrapperr"sl ++u./ 0C { ykVHu,<< {JLCykVHu,<<>C-0()* JrcZtj}|fd}|}|t<|S)Ncr$|ddDcgc] }t|c}|dgz}n|Dcgc] }t|}}|}|duxrdxs|Scc}wcc}w)NT)r)r rrrrs rwrapperz _foreignWrapper..wrapper7sg04Sb : :d2hZG045 55T AI'4,1 , ;5s AA)funwrapsr)rrrrs`` r_foreignWrapperr2s2 ,,s C { - JrNc| |j}| |j}t|tz}t ||}t ||}||}t j|t||||S)avRegister a Python predicate ``func``: Function to be registered. The function should return a value in ``foreign_t``, ``True`` or ``False``. ``name`` : Name of the function. If this value is not used, ``func.func_name`` should exist. ``arity``: Arity (number of arguments) of the function. If this value is not used, ``func.arity`` should exist. ) rrrPL_FA_NONDETERMINISTICrrcwrapsrPL_register_foreign)rrwrflagsrcwrapfwrapfwrap2s rregisterForeignr%Gsq }  |}}E$::; U$4 5E D"2 3E 5\F MM& tUFE ::rcHt|}tt|||zSr:)rrr)countr7s r newTermRefsr(fs"A aU# $$rc|D] }|dvst|jdd}|d}|ddD]}t||}t|j|S)z=Call term in module. ``term``: a Term or term handle )moduler*Nrr)rr_commaPL_callr )termskwargskwargr*r|txs rcallr1ksd  "NZZ$ 'F aAABi 1bM 188V $$rcbt|tr t|}t|jS)z;Create a new module. ``name``: An Atom or a string )r#r$r PL_new_moduler )rws r newModuler4|s&$Dz  %%rc\eZdZdZdZdZdZeeZdZeeZdZ ee Z y)QueryNcd|D]}|dvstd|z||jdttz}|jdd}|d}|ddD]}t ||}t j |}t|j|} t||| |jt_ y)N)r!r*zInvalid kwarg: %sr!r*rr) r r PL_Q_NODEBUGPL_Q_CATCH_EXCEPTIONr+rr8PL_predr PL_open_queryrUr6qid) r r-r.keyr!r*r|r0rrs rr zQuery.__init__sC-- 3c 93?? 7L1E$EFHd+ !H)Bq" A   Q  AHHf %!&%ADD9 rc4ttjSr:)PL_next_solutionr6r<rrr nextSolutionzQuery.nextSolutions **rc6ttjyr:) PL_cut_queryr6r<rrrcutQueryzQuery.cutQuerysUYYrcntj%ttjdt_yyr:)r6r<PL_close_queryrrr closeQueryzQuery.closeQuerys$ 99 599 %EI !r) rrrr<fidr r@ staticmethodrCrFrrrr6r6s@ C C: + -L H%Hj)Jrr6)rF)F)NNr): pyswip.coresys version_inforrr/rrr robjectrr-r#rirl NameErrorrdrr_unifyrr rYr+rrr4rrr getIntegerrrrrrrr rPL_ATOM PL_STRING PL_INTEGERPL_FLOATrrrrrrrr%rW newTermRefr(r1r4r6rrrrUs4d$LMFM-y-& &=6=@A6AH"r:)rvrjRfRj' a& V]]ua aB*' '' ()  <    GizXG    $ ;8 % %"& *F *U"""s DD D