
    Ngfc                        d Z ddlZddlZddlZddlZddlmZ ddlmZ ddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ  G d de          Z G d d	e          Zd
 Zd Zd Zd Z  G d de!          Z" ej#        d          Z$ ej#        d          Z% ej#        dej&                  Z'd Z(d#dZ) G d de!          Z* G d d          Z+dZ,d#dZ-d$dZ.d#dZ/d#dZ0d%dZ1e2d k    r e1d!d"           dS dS )&zK
This module provides data structures for representing first-order
models.
    Npformat)	decorator)AbstractVariableExpressionAllExpressionAndExpressionApplicationExpressionEqualityExpressionExistsExpression
ExpressionIffExpressionImpExpressionIndividualVariableExpressionIotaExpressionLambdaExpressionNegatedExpressionOrExpressionVariable	is_indvarc                       e Zd ZdS )ErrorN__name__
__module____qualname__     M/var/www/html/ai-engine/env/lib/python3.11/site-packages/nltk/sem/evaluate.pyr   r   ,           Dr   r   c                       e Zd ZdS )	UndefinedNr   r   r   r   r!   r!   0   r   r   r!   c                    t          j        |           }t          t          |d         |                    }|                    dd           r7t                       |                                D ]}t          d|z              | |i |S )Nr   tracez%s => %s)inspectgetfullargspecdictzippopprintitems)fargskwargspecditems         r   r#   r#   4   s    $Q''GST""##AuuWd %GGII 	% 	%D*t#$$$$1d>b>>r   c                     t          |           dk    rdS t          d | D                       r<t          t          |                     t          t          |                     k    rdS t	          d| z            )z
    Check whether a set represents a relation (of any arity).

    :param s: a set containing tuples of str elements
    :type s: set
    :rtype: bool
    r   Tc              3   @   K   | ]}t          |t                    V  d S N)
isinstancetuple).0els     r   	<genexpr>zis_rel.<locals>.<genexpr>J   s,      //rZE""//////r   z.Set %r contains sequences of different lengths)lenallmaxmin
ValueError)ss    r   is_relr?   >   ss     1vv{{t	//Q///	/	/ OCAKK3s1vv;;4N4NtIAMNNNr   c                    t                      }| D ]{}t          |t                    r|                    |f           .t          |t                    r#|                    t          |                     f|                    |           ||S )aR  
    Convert a set containing individuals (strings or numbers) into a set of
    unary tuples. Any tuples of strings already in the set are passed through
    unchanged.

    For example:
      - set(['a', 'b']) => set([('a',), ('b',)])
      - set([3, 27]) => set([('3',), ('27',)])

    :type s: set
    :rtype: set of tuple of str
    )setr4   straddint)r>   newelems      r   set2relrG   P   s     %%C  dC   	GGTGc"" 	GGCIIGGDMMMMJr   c                 p    t          |           dk    rdS t          t          |           d                   S )ze
    Check the arity of a relation.
    :type rel: set of tuples
    :rtype: int of tuple of str
    r   )r9   list)rels    r   arityrK   h   s0     3xx1}}qtCyy|r   c                   p     e Zd ZdZ fdZd Zd Zed             Zed             Z	e
d             Z xZS )	Valuationa  
    A dictionary which represents a model-theoretic Valuation of non-logical constants.
    Keys are strings representing the constants to be interpreted, and values correspond
    to individuals (represented as strings) and n-ary relations (represented as sets of tuples
    of strings).

    An instance of ``Valuation`` will raise a KeyError exception (i.e.,
    just behave like a standard  dictionary) if indexed with an expression that
    is not in its list of symbols.
    c                 \   t                                                       |D ]\  }}t          |t                    st          |t                    r|| |<   5t          |t
                    rt          |          | |<   ]t          j        d|d|d          }t          |          dS )z=
        :param xs: a list of (symbol, value) pairs.
        z@Error in initializing Valuation. Unrecognized value for symbol 'z':
B   )widthN)
super__init__r4   rB   boolrA   rG   textwrapfillr=   )selfxssymvalmsg	__class__s        r   rR   zValuation.__init__   s     	 	& 	&HC#s## &z#t'<'< &S		C%% 	&#CLLS		mmADccK   !oo%	& 	&r   c                 d    || v rt                               | |          S t          d|z            )NzUnknown expression: '%s'r&   __getitem__r!   rV   keys     r   r^   zValuation.__getitem__   s5    $;;##D#...6<===r   c                      t          |           S r3   r   rV   s    r   __str__zValuation.__str__   s    t}}r   c                    g }|                                  D ]a}t          |t                    r|                    |           -t          |t                    s|                    d |D                        bt          |          S )z7Set-theoretic domain of the value-space of a Valuation.c                      g | ]}|D ]}||S r3   r   )r6   tuple_rF   s      r   
<listcomp>z$Valuation.domain.<locals>.<listcomp>   s*    SSSfSS$BRTBRBRBRBRr   )valuesr4   rB   appendrS   extendrA   )rV   domrY   s      r   domainzValuation.domain   s     ;;== 	 	C#s## 

3T** 

SSSSS   3xxr   c                 D    t          |                                           S )z9The non-logical constants which the Valuation recognizes.)sortedkeysrb   s    r   symbolszValuation.symbols   s     diikk"""r   c                      t          |          S r3   )read_valuation)clsr>   s     r   
fromstringzValuation.fromstring   s    a   r   )r   r   r   __doc__rR   r^   rc   propertyrl   rp   classmethodrt   __classcell__r[   s   @r   rM   rM   s   s        	 	& & & & &&> > >   
 
 X
 # # X# ! ! [! ! ! ! !r   rM   z	\s*=+>\s*z\s*,\s*zg\s*
                                (\([^)]+\))  # tuple-expression
                                \s*c                    t                               |           }|d         }|d         }|                    d          r|dd         }t                              |          }|rNg }|D ]H}|dd         }t          t                              |                    }|                    |           Int                              |          }t          |          }||fS )a  
    Read a line in a valuation file.

    Lines are expected to be of the form::

      noosa => n
      girl => {g1, g2}
      chase => {(b1, g1), (b2, g1), (g1, d1), (g2, d2)}

    :param s: input line
    :type s: str
    :return: a pair (symbol, value)
    :rtype: tuple
    r      {)	_VAL_SPLIT_REsplit
startswith
_TUPLES_REfindallr5   _ELEMENT_SPLIT_REri   rA   )r>   piecessymbolvaluetuple_stringsset_elementstselements           r   _read_valuation_liner      s       ##FAYF1IE "ad"**511 	:L# - -"X 1 7 7 ; ;<<##G,,,,-
 -22599LL!!5=r   c                    ||                      |          } g }t          |                                           D ]\  }}|                                }|                    d          s|dk    r5	 |                    t          |                     Y# t          $ r}t          d| d|           |d}~ww xY wt          |          S )a  
    Convert a valuation string into a valuation.

    :param s: a valuation string
    :type s: str
    :param encoding: the encoding of the input string, if it is binary
    :type encoding: str
    :return: a ``nltk.sem`` valuation
    :rtype: Valuation
    N# zUnable to parse line z: )	decode	enumerate
splitlinesstripr   ri   r   r=   rM   )r>   encoding
statementslinenumlinees         r   rr   rr      s     HHXJ"1<<>>22 O Ozz||??3 	42::	O24889999 	O 	O 	OFWFFFFGGQN	OZ   s   1"B
B9B44B9c                   J     e Zd ZdZd
 fd	Zd Zd Zd
dZd Zd Z	d	 Z
 xZS )
Assignmentae  
    A dictionary which represents an assignment of values to variables.

    An assignment can only assign values from its domain.

    If an unknown expression *a* is passed to a model *M*\ 's
    interpretation function *i*, *i* will first check whether *M*\ 's
    valuation assigns an interpretation to *a* as a constant, and if
    this fails, *i* will delegate the interpretation of *a* to
    *g*. *g* only assigns values to individual variables (i.e.,
    members of the class ``IndividualVariableExpression`` in the ``logic``
    module. If a variable is not assigned a value by *g*, it will raise
    an ``Undefined`` exception.

    A variable *Assignment* is a mapping from individual variables to
    entities in the domain. Individual variables are usually indicated
    with the letters ``'x'``, ``'y'``, ``'w'`` and ``'z'``, optionally
    followed by an integer (e.g., ``'x0'``, ``'y332'``).  Assignments are
    created using the ``Assignment`` constructor, which also takes the
    domain as a parameter.

        >>> from nltk.sem.evaluate import Assignment
        >>> dom = set(['u1', 'u2', 'u3', 'u4'])
        >>> g3 = Assignment(dom, [('x', 'u1'), ('y', 'u2')])
        >>> g3 == {'x': 'u1', 'y': 'u2'}
        True

    There is also a ``print`` format for assignments which uses a notation
    closer to that in logic textbooks:

        >>> print(g3)
        g[u1/x][u2/y]

    It is also possible to update an assignment using the ``add`` method:

        >>> dom = set(['u1', 'u2', 'u3', 'u4'])
        >>> g4 = Assignment(dom)
        >>> g4.add('x', 'u1')
        {'x': 'u1'}

    With no arguments, ``purge()`` is equivalent to ``clear()`` on a dictionary:

        >>> g4.purge()
        >>> g4
        {}

    :param domain: the domain of discourse
    :type domain: set
    :param assign: a list of (varname, value) associations
    :type assign: list
    Nc                 :   t                                                       || _        |rU|D ]R\  }}|| j        v s#J d                    || j                              t	          |          sJ d|z              || |<   Sd | _        |                                  d S )Nz'{}' is not in the domain: {}-Wrong format for an Individual Variable: '%s')rQ   rR   rl   formatr   variant_addvariant)rV   rl   assignvarrY   r[   s        r   rR   zAssignment.__init__0  s     		 "    Sdk)))+J+Q+QK, ,))) !~~  CcI    S		r   c                 d    || v rt                               | |          S t          d|z            )Nz"Not recognized as a variable: '%s'r]   r_   s     r   r^   zAssignment.__getitem__@  s5    $;;##D#...@3FGGGr   c                 X    t          | j                  }|                    |            |S r3   )r   rl   update)rV   rE   s     r   copyzAssignment.copyF  s(    %%

4
r   c                 b    |r| |= n|                                   |                                  dS )z
        Remove one or all keys (i.e. logic variables) from an
        assignment, and update ``self.variant``.

        :param var: a Variable acting as a key for the assignment.
        N)clearr   )rV   r   s     r   purgezAssignment.purgeK  s9      	S		JJLLLtr   c                 Z    d}t          | j                  }|D ]\  }}|d| d| dz  }|S )zQ
        Pretty printing for assignments. {'x', 'u'} appears as 'g[u/x]'
        g[/])rn   r   )rV   gstringr   rY   r   s        r   rc   zAssignment.__str__Y  sP     && 	( 	(HC'3''''''GGr   c                     g }|                                  D ]'}|d         |d         f}|                    |           (|| _        dS )zK
        Create a more pretty-printable version of the assignment.
        r{   r   N)r*   ri   r   )rV   list_r0   pairs       r   r   zAssignment._addvariantd  sS     JJLL 	 	DGT!W%DLLtr   c                     || j         v sJ | d| j                      t          |          sJ d|z              || |<   |                                  | S )zh
        Add a new variable-value pair to the assignment, and update
        ``self.variant``.

        z is not in the domain r   )rl   r   r   )rV   r   rY   s      r   rC   zAssignment.addo  sp     dk!!!c#N#N#N#N!!!~~TTNQTTTTTS	r   r3   )r   r   r   ru   rR   r^   r   r   rc   r   rC   rx   ry   s   @r   r   r      s        2 2h      H H H  
   	 	 		 	 	
 
 
 
 
 
 
r   r   c                   D    e Zd ZdZd Zd Zd ZddZddZdd	Z	ddZ
dS )Modela[  
    A first order model is a domain *D* of discourse and a valuation *V*.

    A domain *D* is a set, and a valuation *V* is a map that associates
    expressions with values in the model.
    The domain of *V* should be a subset of *D*.

    Construct a new ``Model``.

    :type domain: set
    :param domain: A set of entities representing the domain of discourse of the model.
    :type valuation: Valuation
    :param valuation: the valuation of the model.
    :param prop: If this is set, then we are building a propositional    model and don't require the domain of *V* to be subset of *D*.
    c                     t          |t                    sJ || _        || _        |                    |j                  st          d|j        d|          d S )NzThe valuation domain, z*, must be a subset of the model's domain, )r4   rA   rl   	valuation
issupersetr   )rV   rl   r   s      r   rR   zModel.__init__  sr    &#&&&&&"  !122 	%###VV-  	 	r   c                 (    d| j         d| j        dS )N(z, )rl   r   rb   s    r   __repr__zModel.__repr__  s    74;77DN7777r   c                 &    d| j          d| j         S )Nz	Domain = z,
Valuation = 
r   rb   s    r   rc   zModel.__str__  s    I4;IIIIIr   Nc                    	 t          j        |          }|                     |||          }|r&t                       t          d| d| d|            |S # t          $ r) |r#t                       t          d| d|            Y dS w xY w)aA  
        Read input expressions, and provide a handler for ``satisfy``
        that blocks further propagation of the ``Undefined`` error.
        :param expr: An ``Expression`` of ``logic``.
        :type g: Assignment
        :param g: an assignment to individual variables.
        :rtype: bool or 'Undefined'
        r#   'z' evaluates to z
 under M, z' is undefined under M, r!   )r   rt   satisfyr)   r!   )rV   exprr   r#   parsedr   s         r   evaluatezModel.evaluate  s    	*400FLL%L88E EC$CCuCCCCDDDL 	 	 	 =;$;;;;<<<;;		s   AA /B
Bc                 p    t          |t                    r|                                \  }}t          |t                    r6                     |          }t           fd|D                       }||v S                      |j                  }                     |j                  }||         S t          |t                    r                     |j	                   S t          |t                    r6                     |j                  o                     |j                  S t          |t                    r6                     |j                  p                     |j                  S t          |t                    r7                     |j                   p                     |j                  S t          |t                    r8                     |j                                       |j                  k    S t          |t                     r8                     |j                                       |j                  k    S t          |t"                    r^                                }	 j        D ]@}
|	                    |j        j        |
                                |j	        |	          s dS AdS t          |t.                    r^                                }	 j        D ]@}
|	                    |j        j        |
                                |j	        |	          r dS AdS t          |t0                    r^                                }	 j        D ]@}
|	                    |j        j        |
                                |j	        |	          r dS AdS t          |t2                    rNi }|j        j        } j        D ]6}
                     |j	                            ||
                    }|||
<   7|S                      ||          S )a  
        Recursive interpretation function for a formula of first-order logic.

        Raises an ``Undefined`` error when ``parsed`` is an atomic string
        but is not a symbol or an individual variable.

        :return: Returns a truth value or ``Undefined`` if ``parsed`` is        complex, and calls the interpretation function ``i`` if ``parsed``        is atomic.

        :param parsed: An expression of ``logic``.
        :type g: Assignment
        :param g: an assignment to individual variables.
        c              3   D   K   | ]}                     |          V  d S r3   )r   )r6   argr   rV   s     r   r8   z Model.satisfy.<locals>.<genexpr>  s1      JJS! 4 4JJJJJJr   FT)r4   r	   uncurryr   r   r5   functionargumentr   termr   firstsecondr   r   r   r
   r   r   rl   rC   variablenamer   r   r   i)rV   r   r   r#   r   	argumentsfunvalargvalsargvalnew_gucfr   rY   s   ` `           r   r   zModel.satisfy  s     f344 9	,"(.."2"2Hi($>?? 	&h22JJJJJ	JJJJJ&(( foq99foq99f~% 122 -	,||FK3333.. +	,<<a00ST\\&-QR5S5SS-- )	,<<a00RDLLPQ4R4RR.. '	,V\1555X$,,v}VW:X:XX.. %	,<<a00DLLPQ4R4RRR 233 #	,<<a00DLLPQ4R4RRR.. !	,FFHHE[ ! !		&/.222||FK77 ! 55!4 011 	,FFHHE[    		&/.222<<U33  44 5// 	,FFHHE[    		&/.222<<U33  44 5 011 	,B/&C[  ll6;c1>>
 1I66&!U+++r   Fc                     |j         j        | j        j        v r| j        |j         j                 S t	          |t
                    r||j         j                 S t          d|z            )a  
        An interpretation function.

        Assuming that ``parsed`` is atomic:

        - if ``parsed`` is a non-logical constant, calls the valuation *V*
        - else if ``parsed`` is an individual variable, calls assignment *g*
        - else returns ``Undefined``.

        :param parsed: an ``Expression`` of ``logic``.
        :type g: Assignment
        :param g: an assignment to individual variables.
        :return: a semantic value
        zCan't find a value for %s)r   r   r   rp   r4   r   r!   )rV   r   r   r#   s       r   r   zModel.i   se    $ ?4>#999>&/"677 <== 	BV_)** 7&@AAAr   r   c           
         d}|||z  z   }g }t          |t                    rt          |          }	n|}	|	|                                v r|r)t	                       t	          ||z  d| d| z              | j        D ]}
|                                }|                    |	j        |
           |r|dk    r|dz
  }nd}| 	                    |||          }|rt	          |d|z  z              |dk    r|rt	          |d| d	| d
z              |
                    |
           |rt	          |d| d	| d| z              d |D             }nt          |	j         d|           |S )a  
        Generate the entities from the model's domain that satisfy an open formula.

        :param parsed: an open formula
        :type parsed: Expression
        :param varex: the relevant free individual variable in ``parsed``.
        :type varex: VariableExpression or str
        :param g: a variable assignment
        :type g:  Assignment
        :return: a set of the entities that satisfy ``parsed``.
        z   zOpen formula is 'z' with assignment r{   r   z(trying assignment %s)Fz
value of 'z' under z	 is Falsez is c                     h | ]}|S r   r   )r6   cs     r   	<setcomp>z#Model.satisfiers.<locals>.<setcomp>N  s    ,,,Aa,,,r   z is not free in )r4   rB   r   freer)   rl   r   rC   r   r   ri   r!   )rV   r   varexr   r#   nestingspacerindent
candidatesr   r   r   lowtracer   results                  r   
satisfierszModel.satisfiers  s    6G+,
eS!! 	5//CCC&++-- g%G&GGAGGH   [ X X		#(A&&& !UQYY$qyHH HVUH== E&#;e#CCDDD E>> Vf'TF'T'TE'T'T'TTUUU %%a((( Xf'VF'V'VE'V'Vu'V'VVWWW,,,,,FF sxAAAABBBr   r3   )F)Nr   )r   r   r   ru   rR   r   rc   r   r   r   r   r   r   r   r   r   |  s         "  8 8 8J J J   ,I, I, I, I,XB B B B49 9 9 9 9 9r   r      c           
         t          g d          at                      at	          t          t                    at          t                    at                       t          dt          z             t          d           t          dt          z             t          d           t                       t          dt
                     t          dt          z             g d}|D ]g}| r0t                       t
          
                    |t          |            4t          d| dt
          
                    |t                                hd	S )
z!Example of a propositional model.))PT)QT)RF*zPropositional Formulas Demoz7(Propositional constants treated as nullary predicates)z
Model m1:
)z(P & Q)z(P & R)z- Pz- Rz- - Pz	- (P & R)z(P | R)z(R | P)z(R | R)z	(- P | R)z	(P | - P)z(P -> Q)z(P -> R)z(R -> P)z	(P <-> P)z	(R <-> R)z	(P <-> R)The value of '' is: N)rM   val1rA   dom1r   m1r   g1r)   multr   )r#   	sentencessents      r   propdemor   _  s>    ===>>D55D	tT		B	D		B	GGG	#*	
'(((	#*	
CDDD	GGG	-	#*  I(  H H 	HGGGKKb%((((F4FFr{{4/D/DFFGGGGH Hr   Fc           
         ddddddhfddd	hfd
dhfdh dfga t          t                     at          j        at          t          t                    at          t          ddg          a| st                       t          dt          z             t          d           t          dt          z             t          dddt                     t          dt                     g d}d |D             }t                       |D ]X}	 t          d|dt                              |t                               7# t          $ r t          d|z             Y Uw xY wg d}|D ]\  }}	 t                              t          j        |          t                    }t          d |D                       }	t          | d| d|	|v             k# t          $ r t          | d| d           Y w xY wd S d S )!zExample of a first-order model.)adamb1)bettyr   )fidod1girlr   g2boyr   b2dogr   love>   r   r   r   r   r   r   r   r   )xr   )yr   r   zModels Demoz
Model m2:
z--------------
zVariable assignment = )r   r   r   walksr  r  zc                 6    g | ]}t          j        |          S r   r   rt   )r6   r   s     r   rg   zfolmodel.<locals>.<listcomp>  s#    @@@Q
-a00@@@r   zThe interpretation of 'z' in m2 is z-The interpretation of '%s' in m2 is Undefined))r   r   )r  )r   )r   )r   r  )r   )r  r   c              3   z   K   | ]6}t                               t          j        |          t                    V  7d S r3   )m2r   r   rt   r   )r6   r   s     r   r8   zfolmodel.<locals>.<genexpr>  s;      UUZ%:3%?%? D DUUUUUUr   r   z) evaluates to z) evaluates to UndefinedN)v2rM   val2rl   dom2r   r  r   r   r)   r   r   r!   r   rt   r5   )
quietr#   exprsparsed_exprsr   applicationsfunr,   r   argsvals
             r   folmodelr    s{    		$	t		IIIJ
B R==D;D	tT		B	D;4	5	5B "?cDjmcDjmXtR000&+++???@@%@@@" 	P 	PFPvvrttFB///1     P P PENOOOOOP
 
 
 & 	? 	?IC?j3C88"==UUPTUUUUUGGtGGGv4EGGHHHH ? ? ?==t===>>>>>?C"? "?8	? 	?s%   3D;;EE)A$GG0/G0c           
         t          d           t                       t          dt          z             t          d           t          dt          z             g d}|D ]r}t                                           | r"t
                              |t          |            ?t          d| dt
                              |t                                sdS )	zF
    Interpretation of closed expressions in a first-order model.
    Tr  r   zFOL Formulas Demo)zlove (adam, betty)z(adam = mia)z\x. (boy(x) | girl(x))z\x. boy(x)(adam)z\x y. love(x, y)z\x y. love(x, y)(adam)(betty)z\x y. love(x, y)(adam, betty)z\x y. (boy(x) & love(x, y))z#\x. exists y. (boy(x) & love(x, y))zexists z1. boy(z1)z!exists x. (boy(x) &  -(x = adam))z&exists x. (boy(x) & all y. love(y, x))zall x. (boy(x) | girl(x))z1all x. (girl(x) -> exists y. boy(y) & love(x, y))z3exists x. (boy(x) & all y. (girl(y) -> love(y, x)))z3exists x. (boy(x) & all y. (girl(y) -> love(x, y)))zall x. (dog(x) -> - girl(x))z-exists x. exists y. (love(x, y) & love(x, y))r   r   N)r  r)   r   r   r   r  r   )r#   formulasfmlas      r   foldemor    s     4	GGG	#*	
	#*  H*  H H



 	HKKb%((((F4FFr{{4/D/DFFGGGGH Hr   c                    t                       t          dt          z             t          d           t          dt          z             t          d           g d}| rt          t                     |D ]%}t          |           t	          j        |           &d |D             }|D ]^}t                                           t          d                    |t          	                    |dt          |                                _d	S )
z5Satisfiers of an open formula in a first order model.r   zSatisfiers DemoTr  )zboy(x)z(x = x)z(boy(x) | girl(x))z(boy(x) & girl(x))zlove(adam, x)zlove(x, adam)z-(x = adam)zexists z22. love(x, z22)exists y. love(y, x)zall y. (girl(y) -> love(x, y))zall y. (girl(y) -> love(y, x))z)all y. (girl(y) -> (boy(x) & love(y, x)))z)(boy(x) & all y. (girl(y) -> love(x, y)))z)(boy(x) & all y. (girl(y) -> love(y, x)))z+(boy(x) & exists y. (girl(y) & love(y, x)))z(girl(x) -> dog(x))zall y. (dog(y) -> (x = y))r  z&exists y. (love(adam, y) & love(y, x))c                 6    g | ]}t          j        |          S r   r  )r6   r  s     r   rg   zsatdemo.<locals>.<listcomp>  s#    ???dj#D))???r   zThe satisfiers of '{}' are: {}r  N)
r)   r   r  r  r   rt   r   r   r   r   )r#   r  r  r   ps        r   satdemor!    s    
GGG	#*	
	#*4  H,  b			 $ $dd####??h???F 
 




,33Ar}}QRQV7W7WXX	
 	
 	
 	

 
r   c                     t           t          t          t          d}	  ||          |           dS # t          $ r |D ]}  ||          |           Y dS w xY w)aO  
    Run exists demos.

     - num = 1: propositional logic demo
     - num = 2: first order model demo (only if trace is set)
     - num = 3: first order sentences demo
     - num = 4: satisfaction of open formulas demo
     - any other value: run all the demos

    :param trace: trace = 1, or trace = 2 for more verbose tracing
    )r{            r   N)r   r  r  r!  KeyError)numr#   demoss      r   demor)  (  s     X'g>>E$c
 $ $ $ 	$ 	$CE#JU#####	$ 	$ 	$$s   1 !AA__main__r#  r   r3   )FN)r   N)3ru   r$   resysrT   pprintr   nltk.decoratorsr   nltk.sem.logicr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   	Exceptionr   r!   r#   r?   rG   rK   r&   rM   compiler~   r   VERBOSEr   r   rr   r   r   r   r   r  r  r!  r)  r   r   r   r   <module>r3     s>   
  				 



        % % % % % %                                   (	 	 	 	 	I 	 	 		 	 	 	 	 	 	 	  O O O$  0  <! <! <! <! <! <! <! <!D 
<((BJz** RZ' J	 
     F! ! ! !2~ ~ ~ ~ ~ ~ ~ ~BW W W W W W W W| 

*H *H *H *Hb5? 5? 5? 5?x%H %H %H %HX-
 -
 -
 -
`$ $ $ $* zD! r   