JL iR.dZddlZddlZddlmZmZddlmZmZddl m Z m Z ddl m Z GddeeZGd d eeZdd Zd Zd ZdZdZdZdddgfdddgfgZdZedk(reyy)zA A model builder that makes use of the external 'Mace4' package. N)BaseModelBuilderCommand ModelBuilder)Prover9CommandParent Prover9Parent) Expression Valuation) is_indvarczeZdZdZdZd dZedZdZe dZ e dZ e dZ d Z d Zgd fd Zy) MaceCommandz A ``MaceCommand`` specific to the ``Mace`` model builder. It contains a print_assumptions() method that is used to print the list of assumptions in multiple formats. Ncr|t|ts Jt|}tj||||y)a :param goal: Input expression to prove :type goal: sem.Expression :param assumptions: Input expressions to use as assumptions in the proof. :type assumptions: list(sem.Expression) :param max_models: The maximum number of models that Mace will try before simply returning false. (Use 0 for no maximum.) :type max_models: int N) isinstanceMacer__init__)selfgoal assumptions max_models model_builders Y/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/nltk/inference/mace.pyrzMaceCommand.__init__s8  $mT2 22 ,M((}dKPc$|jdS)N valuation)model)mbcs rrzMaceCommand.valuation1syy%%rcx|j|d}g}|jdD]}|j}|jdr>t ||j ddz|j dj}c|jdr|j dd k(r||j ddz|j dj}t|r|j}t ||j d dz|j d j}|j|tj|f<|jd sO||j ddzd }d|vr|d |j dj}||j d dz|j d jdD cgc]} t | j} } |j|tj| f|d |j dj}t ||j d dz|j d j}|j||dk(ft|Scc} w)z Transform the output file into an NLTK-style Valuation. :return: A model if one is generated; None otherwise. :rtype: sem.Valuation standardFinterpretation(,function_[]relationN)_transform_output splitlinesstrip startswithintindexfindr upperappendr _make_model_varsplit_make_relation_setr) r valuation_strvaluation_standard_formatvallinel num_entitiesnamevaluevvaluess r _convert2valzMaceCommand._convert2val5sQ%)$:$:=*$U!-88? 3D A||,-"1QWWS\A%5 #E#K#K#MN j)affSkR.?)AGGCL9??AT?::DDFG D+"="=e"DEFj)aggclQ&()!8^qwws|,224D"#1773I#q!q&I H EEk66xVW   Js A%A%ct|dk(rgSt||z}||z}t||z}|||z|dz|z}tj|gtj |||zSNr)lenr+r r0rC)rFr<r8 sublist_size sublist_startsublist_positionsublists rrCz MaceCommand._make_relation_tupless v;! Iv;,6L$ 4M"8l#:;  , 0A\/QG++M:00 '< rcDgd|}|dz}|dkDr|t|zS|S)z Pick an alphabetic character as identifier for an entity in the model. :param value: where to index into the list of characters :type value: int )abcdefghijkr7mnopqrDstur;wxyzr)str)r:letternums rr0zMaceCommand._make_model_vars8 6 78rk$'!GvC 77rcZ|s|S|dk(r|j|S|j||S)a_ Print out a Mace4 model using any Mace4 ``interpformat`` format. See https://www.cs.unm.edu/~mccune/mace4/manual/ for details. :param valuation_str: str with the model builder's output :param format: str indicating the format for displaying models. Defaults to 'standard' format. :return: str r)r=r'rr3formats r_decorate_modelzMaceCommand._decorate_models9 { "$$]3 3))-@ @rcL|dvr|j||gdStd)z Transform the output file into any Mace4 ``interpformat`` format. :param format: Output format for displaying models. :type format: str )r standard2portabletabularrawcookedxmltexrz#The specified format does not exist)_call_interpformat LookupErrorrks rr'zMaceCommand._transform_outputs9   **=6(CAF FCD DrFc|j!|jjd||_|jj||j||S)a Call the ``interpformat`` binary with the given input. :param input_str: A string whose contents are used as stdin. :param args: A list of command-line arguments. :return: A tuple (stdout, returncode) :see: ``config_prover9`` interpformat)_interpformat_bin _modelbuilder _find_binary_call)r input_strargsverboses rrvzMaceCommand._call_interpformatsX  ! ! )%)%7%7%D%D&D "!!'' t--tW  r)NNN)__name__ __module__ __qualname____doc__rzrpropertyrr= staticmethodr2rCr0rmr'rvrrr r s Q$&&+Z "$8$8LA"E*24U rr c,eZdZdZddZddZgdfdZy)rNc||_y)N) _end_size)rend_sizes rrz Mace.__init__s! ?rFcd|sg}|j|j|||\}}|dk(|fS)z Use Mace4 to build a first order model. :return: ``True`` if a model was found (i.e. Mace returns value of 0), else ``False`` )rr) _call_mace4 prover9_input)rrrrstdout returncodes r _build_modelzMace._build_modelsIK!--   t[ 17.  a((rc|j|jd||_d}|jdkDr|d|jzz }||z }|j||j||S)a  Call the ``mace4`` binary with the given input. :param input_str: A string whose contents are used as stdin. :param args: A list of command-line arguments. :return: A tuple (stdout, returncode) :see: ``config_prover9`` mace4rzassign(end_size, %d). ) _mace4_binr|rr})rr~rrupdated_input_strs rrzMace._call_mace4sn ?? ""//ADO >>A  ! gives(Socrates,x,y))rzAssumptions and GoalrrrrrN)rrr rrrrr)rrUrOrrZs rtest_build_modelr.s n-A    a  E  A5)AMMO H ! H  gk Cs"]1==?34B 78 H + H !++t3 sC(ctj|d}|dDcgc]}tj|}}t ||}|j |D]}t d|zt d|d|j ddD]?}tt d |ztt |j| Ay cc}w) zJ Transform the model into various Mace4 ``interpformat`` formats. rrrrrrr)rrprtrszUsing '%s' format)rlN) rrrrr rrrr) argument_pairrUrOrrZrls rtest_transform_outputrOs mA./A"/"2 3QRXXa[ 3E 3A5)AMMO  gk Cs"Q]]_%R ();& !F*+ aggVg$% & 4sCcttjdgdddhk(ttjdgddhk(ttjdgd d d hk(y) N)rrr)r8r<)rQ)rO) rrrrrrrrr)rQrO)rrrrrrrr)rOrPrO)rPrPrO)rr r2rrrtest_make_relation_setras &&Ai&H F   &&#> '  <   &&A>V&W _ - .rzmortal(Socrates)zall x.(man(x) -> mortal(x))rz(not mortal(Socrates))cdttttttdyrH)rrrrrrrdemorxsYY)A,'r__main__))rostempfilenltk.inference.apirrnltk.inference.prover9rrnltk.semrrnltk.sem.logicr r rrrrrrrrrrrrrrs DF*$L &(?L ^(M=,(MV  3B&$$7IJ =OP  (  zFr