a
     ˜ëjfc  ã                   @   sv  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„ deƒZG dd	„ d	eƒZd
d„ Zdd„ Zdd„ Zdd„ Z G dd„ de!ƒZ"e #d¡Z$e #d¡Z%e #dej&¡Z'dd„ Z(d.dd„Z)G dd„ de!ƒZ*G dd„ dƒZ+dZ,d/d d!„Z-d0d#d$„Z.d1d%d&„Z/d2d'd(„Z0d3d)d*„Z1e2d+k�rre1d,dd-� dS )4zK
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                   @   s   e Zd ZdS )ÚErrorN©Ú__name__Ú
__module__Ú__qualname__© r   r   úP/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/nltk/sem/evaluate.pyr   ,   s   r   c                   @   s   e Zd ZdS )Ú	UndefinedNr   r   r   r   r   r   0   s   r   c                 O   sV   t  | ¡}tt|d |ƒƒ}| dd ¡rHtƒ  | ¡ D ]}td| ƒ q6| |i |¤ŽS )Nr   Útracez%s => %s)ÚinspectÚgetfullargspecÚdictÚzipÚpopÚprintÚitems)ÚfÚargsÚkwZargspecÚdÚitemr   r   r   r   4   s    
r   c                 C   sN   t | ƒdkrdS tdd„ | D ƒƒr>t t| ƒƒt t| ƒƒkr>dS td|  ƒ‚dS )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                 s   s   | ]}t |tƒV  qd S ©N)Ú
isinstanceÚtuple)Ú.0Úelr   r   r   Ú	<genexpr>J   ó    zis_rel.<locals>.<genexpr>z.Set %r contains sequences of different lengthsN)ÚlenÚallÚmaxÚminÚ
ValueError)Úsr   r   r   Úis_rel>   s
    	*r7   c                 C   sP   t ƒ }| D ]@}t|tƒr&| |f¡ q
t|tƒr@| t|ƒ¡ q
| |¡ q
|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
    )Úsetr+   ÚstrÚaddÚint)r6   ÚnewÚelemr   r   r   Úset2relP   s    

r>   c                 C   s    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   )r1   Úlist)Úrelr   r   r   Úarityh   s    rA   c                       sT   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zedd	„ ƒZed
d„ ƒZ	e
dd„ ƒZ‡  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                    sp   t ƒ  ¡  |D ]\\}}t|tƒs*t|tƒr4|| |< qt|tƒrLt|ƒ| |< qtjd||f dd�}t	|ƒ‚qdS )z=
        :param xs: a list of (symbol, value) pairs.
        zGError in initializing Valuation. Unrecognized value for symbol '%s':
%séB   )ÚwidthN)
ÚsuperÚ__init__r+   r9   Úboolr8   r>   ÚtextwrapÚfillr5   )ÚselfÚxsÚsymÚvalÚmsg©Ú	__class__r   r   rF      s    


ÿýzValuation.__init__c                 C   s$   || v rt  | |¡S td| ƒ‚d S )NzUnknown expression: '%s'©r    Ú__getitem__r   ©rJ   Úkeyr   r   r   rR   ’   s    zValuation.__getitem__c                 C   s   t | ƒS r*   r   ©rJ   r   r   r   Ú__str__˜   s    zValuation.__str__c                 C   sN   g }|   ¡ D ]8}t|tƒr&| |¡ qt|tƒs| dd„ |D ƒ¡ qt|ƒS )z7Set-theoretic domain of the value-space of a Valuation.c                 S   s"   g | ]}|D ]}|d ur|‘qqS r*   r   )r-   Útuple_r=   r   r   r   Ú
<listcomp>¤   r0   z$Valuation.domain.<locals>.<listcomp>)Úvaluesr+   r9   ÚappendrG   Úextendr8   )rJ   ÚdomrM   r   r   r   Údomain›   s    

ÿzValuation.domainc                 C   s   t |  ¡ ƒS )z9The non-logical constants which the Valuation recognizes.)ÚsortedÚkeysrU   r   r   r   Úsymbols¨   s    zValuation.symbolsc                 C   s   t |ƒS r*   )Úread_valuation)Úclsr6   r   r   r   Ú
fromstring­   s    zValuation.fromstring)r   r   r   Ú__doc__rF   rR   rV   Úpropertyr]   r`   Úclassmethodrc   Ú__classcell__r   r   rO   r   rB   s   s   

rB   z	\s*=+>\s*z\s*,\s*zg\s*
                                (\([^)]+\))  # tuple-expression
                                \s*c                 C   sŒ   t  | ¡}|d }|d }| d¡r„|dd… }t |¡}|rrg }|D ](}|dd… }tt |¡ƒ}| |¡ qFn
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Úfindallr,   Ú_ELEMENT_SPLIT_RErZ   r8   )r6   ÚpiecesÚsymbolÚvalueZtuple_stringsZset_elementsÚtsÚelementr   r   r   Ú_read_valuation_line¿   s    



rv   c                 C   sž   |dur|   |¡} g }t|  ¡ ƒD ]r\}}| ¡ }| d¡s"|dkrFq"z| t|ƒ¡ W q" ty’ } z"td|› d|› �ƒ|‚W Y d}~q"d}~0 0 q"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Ústriprm   rZ   rv   r5   rB   )r6   ÚencodingZ
statementsÚlinenumÚlineÚer   r   r   ra   â   s    
.ra   c                       sT   e Zd ZdZd‡ fdd„	Zdd„ Zdd„ Zdd	d
„Zdd„ Zdd„ Z	dd„ Z
‡  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                    sl   t ƒ  ¡  || _|rZ|D ]@\}}|| jv s<J d || j¡ƒ‚t|ƒsPJ d| ƒ‚|| |< qd | _|  ¡  d S )Nz'{}' is not in the domain: {}ú-Wrong format for an Individual Variable: '%s')rE   rF   r]   Úformatr   ÚvariantÚ_addvariant)rJ   r]   ZassignÚvarrM   rO   r   r   rF   0  s    
þ
ÿ
zAssignment.__init__c                 C   s$   || v rt  | |¡S td| ƒ‚d S )Nz"Not recognized as a variable: '%s'rQ   rS   r   r   r   rR   @  s    zAssignment.__getitem__c                 C   s   t | jƒ}| | ¡ |S r*   )r�   r]   Úupdate)rJ   r<   r   r   r   ÚcopyF  s    

zAssignment.copyc                 C   s    |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…   )rJ   r†   r   r   r   ÚpurgeK  s
    zAssignment.purgec                 C   s6   d}t | jƒ}|D ]\}}|d|› d|› d�7 }q|S )zQ
        Pretty printing for assignments. {'x', 'u'} appears as 'g[u/x]'
        Úgú[ú/ú])r^   r„   )rJ   Zgstringr„   rM   r†   r   r   r   rV   Y  s
    
zAssignment.__str__c                 C   s6   g }|   ¡ D ]}|d |d f}| |¡ q|| _dS )zK
        Create a more pretty-printable version of the assignment.
        rh   r   N)r$   rZ   r„   )rJ   Úlist_r)   Úpairr   r   r   r…   d  s    zAssignment._addvariantc                 C   sF   || j v sJ |› d| j › �ƒ‚t|ƒs2J d| ƒ‚|| |< |  ¡  | S )zh
        Add a new variable-value pair to the assignment, and update
        ``self.variant``.

        z is not in the domain r‚   )r]   r   r…   )rJ   r†   rM   r   r   r   r:   o  s
    zAssignment.add)N)N)r   r   r   rd   rF   rR   rˆ   rŠ   rV   r…   r:   rg   r   r   rO   r   r�   û   s   4
r�   c                   @   sP   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	d
„Zddd„Zddd„Z	d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                 C   s<   t |tƒsJ ‚|| _|| _| |j¡s8td|j|f ƒ‚d S )NzDThe valuation domain, %s, must be a subset of the model's domain, %s)r+   r8   r]   Ú	valuationÚ
issupersetr   )rJ   r]   r’   r   r   r   rF   Ž  s    ÿÿzModel.__init__c                 C   s   d| j ›d| j›d�S )Nú(z, ú)©r]   r’   rU   r   r   r   Ú__repr__˜  s    zModel.__repr__c                 C   s   d| j › d| j› �S )Nz	Domain = z,
Valuation = 
r–   rU   r   r   r   rV   ›  s    zModel.__str__Nc                 C   s|   zDt  |¡}| j|||d�}|r@tƒ  td|› d|› d|› �ƒ |W S  tyv   |rptƒ  td|› d|› �ƒ Y dS 0 dS )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   N)r   rc   Úsatisfyr#   r   )rJ   Úexprr‹   r   Úparsedrs   r   r   r   Úevaluatež  s    	
zModel.evaluatec                    s”  t |tƒrt| ¡ \}}t |tƒrLˆ |ˆ ¡}t‡ ‡fdd„|D ƒƒ}||v S ˆ |jˆ ¡}ˆ |jˆ ¡}|| S �nt |tƒrŽˆ |j	ˆ ¡ S t |t
ƒr´ˆ |jˆ ¡o²ˆ |jˆ ¡S t |tƒrÚˆ |jˆ ¡pØˆ |jˆ ¡S t |tƒ�rˆ |jˆ ¡ �pˆ |jˆ ¡S t |tƒ�r.ˆ |jˆ ¡ˆ |jˆ ¡kS t |tƒ�rVˆ |jˆ ¡ˆ |jˆ ¡kS t |tƒ�r¢ˆ  ¡ }	ˆjD ],}
|	 |jj|
¡ ˆ |j	|	¡�sp dS �qpdS t |tƒ�rîˆ  ¡ }	ˆjD ],}
|	 |jj|
¡ ˆ |j	|	¡�r¼ dS �q¼dS t |tƒ�r:ˆ  ¡ }	ˆjD ],}
|	 |jj|
¡ ˆ |j	|	¡�r dS �qdS t |tƒ�r‚i }|jj}ˆjD ]$}
ˆ |j	ˆ  ||
¡¡}|||
< �qX|S ˆ |ˆ |¡S d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   s   | ]}ˆ  |ˆ ¡V  qd S r*   )rš   ©r-   Úarg©r‹   rJ   r   r   r/   É  r0   z Model.satisfy.<locals>.<genexpr>FTN)r+   r   Zuncurryr   rš   r,   ÚfunctionÚargumentr   Ztermr   ÚfirstÚsecondr   r   r   r	   r   rˆ   r]   r:   ÚvariableÚnamer
   r   r   Úi)rJ   rœ   r‹   r   r¡   Ú	argumentsÚfunvalZargvalsÚargvalÚnew_gÚuÚcfr†   rM   r   r    r   rš   ´  sd    




 






zModel.satisfyFc                 C   sD   |j j| jjv r| j|j j S t|tƒr4||j j S td| ƒ‚dS )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 %sN)r¥   r¦   r’   r`   r+   r   r   )rJ   rœ   r‹   r   r   r   r   r§      s
    
zModel.ir   c              	   C   s:  d}|||  }g }t |tƒr(t|ƒ}	n|}	|	| ¡ v �r"|r`tƒ  t|| d|› d|› � ƒ | jD ]ª}
| ¡ }| |	j|
¡ |r–|dkr–|d }nd}|  	|||¡}|r¼t|d|  ƒ |dkrä|rât|d|› d	|› d
� ƒ qf| 
|
¡ |rft|d|› d	|› d|› � ƒ qfd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 rh   r   z(trying assignment %s)Fz
value of 'z' under z	 is Falsez is c                 S   s   h | ]}|’qS r   r   )r-   Úcr   r   r   Ú	<setcomp>N  r0   z#Model.satisfiers.<locals>.<setcomp>z is not free in )r+   r9   r   Úfreer#   r]   rˆ   r:   r¦   rš   rZ   r   )rJ   rœ   Zvarexr‹   r   ZnestingZspacerÚindentÚ
candidatesr†   r¬   r«   Zlowtracers   Úresultr   r   r   Ú
satisfiers  s@    

ÿÿ


 zModel.satisfiers)N)N)F)Nr   )r   r   r   rd   rF   r—   rV   r�   rš   r§   r´   r   r   r   r   r‘   |  s   


L
r‘   é   c              	   C   sº   t g d¢ƒatƒ atttƒattƒatƒ  tdt	 ƒ tdƒ tdt	 ƒ tdƒ tƒ  tdtƒ tdt	 ƒ g d¢}|D ]:}| r˜tƒ  t 
|t| ¡ qztd|› dt 
|t¡› �ƒ qzd	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)rB   Zval1r8   Zdom1r‘   Úm1r�   Úg1r#   Úmultr�   )r   Ú	sentencesÚsentr   r   r   Úpropdemo_  s$    

rÁ   Fc           
   	   C   s†  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| �s‚t	ƒ  t	dt
 ƒ t	dƒ t	dt
 ƒ t	dddtƒ t	dtƒ g d¢}dd„ |D ƒ}t	ƒ  |D ]@}zt	d|t |t¡f ƒ W qº tyø   t	d| ƒ Y qº0 qºg d¢}|D ]x\}}zDt t |¡t¡}tdd„ |D ƒƒ}	t	|› d|› d|	|v › �ƒ W n( t�y|   t	|› d|› d �ƒ Y n0 �qd!S )"zExample of a first-order model.)ÚadamÚb1)Zbettyr½   )ZfidoÚd1Zgirlr½   Úg2ÚboyrÃ   Úb2Z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                 S   s   g | ]}t  |¡‘qS r   ©r   rc   )r-   r€   r   r   r   rX   ¬  r0   zfolmodel.<locals>.<listcomp>z&The interpretation of '%s' in m2 is %sz-The interpretation of '%s' in m2 is Undefined))rÆ   rÂ   )rÌ   )rÂ   )rÈ   )rÂ   rÊ   )rÈ   )rÊ   rÂ   c                 s   s    | ]}t  t |¡t¡V  qd S r*   )Úm2r§   r   rc   rÅ   rž   r   r   r   r/   Â  r0   zfolmodel.<locals>.<genexpr>r”   z) evaluates to z) evaluates to UndefinedN)Zv2rB   Zval2r]   Zdom2r‘   rÏ   r�   rÅ   r#   r¾   r§   r   r   rc   r,   )
Úquietr   ÚexprsZparsed_exprsrœ   ZapplicationsZfunr&   r©   Zargsvalr   r   r   Úfolmodel�  sN    


ù	

ÿÿ rÒ   c              	   C   s~   t dd� tƒ  tdt ƒ tdƒ tdt ƒ g d¢}|D ]<}t ¡  | r\t |t| ¡ q<td|› dt |t¡› �ƒ q<d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Úfmlar   r   r   ÚfoldemoÌ  s    
rÖ   c                 C   s    t ƒ  t dt ƒ t dƒ t dt ƒ tdd� g d¢}| rDt tƒ |D ]}t |ƒ t |¡ qHdd„ |D ƒ}|D ](}t ¡  t d |t 	|d	t| ¡¡ƒ qrd
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                 S   s   g | ]}t  |¡‘qS r   rÎ   )r-   rÕ   r   r   r   rX     r0   zsatdemo.<locals>.<listcomp>zThe satisfiers of '{}' are: {}rÉ   N)
r#   r¾   rÒ   rÏ   r   rc   rÅ   rŠ   rƒ   r´   )r   rÔ   rÕ   rœ   Úpr   r   r   Úsatdemoø  s"    
ÿrÙ   c                 C   sP   t tttdœ}z||  |d� W n* tyJ   |D ]} ||  |d� q2Y n0 dS )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
    )rh   é   é   é   r˜   N)rÁ   rÒ   rÖ   rÙ   ÚKeyError)Únumr   Zdemosr   r   r   Údemo(  s    rß   Ú__main__rÚ   r˜   )N)N)FN)N)N)r   N)3rd   r   ÚreÚsysrH   Úpprintr   Znltk.decoratorsr   Znltk.sem.logicr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   Ú	Exceptionr   r   r   r7   r>   rA   r    rB   Úcompilerk   rp   ÚVERBOSErn   rv   ra   r�   r‘   r¾   rÁ   rÒ   rÖ   rÙ   rß   r   r   r   r   r   Ú<module>   sD   H
B

ü#
  _
1
<
,
0

