ó
ù`]c           @  s$  d  Z  d d l m Z m Z d d l Z d d l m 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 d d l m Z m Z d d	 l m Z d
 e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ e d e  f d „  ƒ  Yƒ Z! d „  Z" d „  Z# d d d „ Z% d „  Z& d „  Z' d „  Z( d „  Z) e d e* f d „  ƒ  Yƒ Z+ d d „ Z, d „  Z- d e f d „  ƒ  YZ. d e f d  „  ƒ  YZ/ d! e* f d" „  ƒ  YZ0 d# „  Z1 d$ „  Z2 d% „  Z3 d& „  Z4 e5 d' k r e4 ƒ  n  d S((   u;   
Module for a resolution-based First Order theorem prover.
iÿÿÿÿ(   t   print_functiont   unicode_literalsN(   t   defaultdict(   t   reduce(   t	   skolemize(   t   VariableExpressiont   EqualityExpressiont   ApplicationExpressiont
   Expressiont   NegatedExpressiont   Variablet   AndExpressiont   unique_variablet   OrExpressiont	   is_indvart   IndividualVariableExpressionR   (   t   Provert   BaseProverCommand(   t   python_2_unicode_compatiblet   ProverParseErrorc           B  s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   &   s   t   ResolutionProverc           B  s/   e  Z d  Z e Z d d e d „ Z d „  Z RS(   u   ANSWERc         C  s÷   | s g  } n  d } y| g  } | r; | j t | ƒ ƒ n  x! | D] } | j t | ƒ ƒ qB W|  j | ƒ \ } } | r t t j | ƒ ƒ n  WnY t k
 rì } |  j rÐ t	 | ƒ j
 d ƒ rÐ t } g  } qí | rã t | ƒ qí | ‚ n X| | f S(   uÜ   
        :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)
        u    maximum recursion depth exceededN(   t   Nonet   extendt   clausifyt   _attempt_prooft   printt   ResolutionProverCommandt   _decorate_clausest   RuntimeErrort   _assume_falset   strt
   startswitht   False(   t   selft   goalt   assumptionst   verboset   resultt   clausest   at   e(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   _prove.   s*    			
c         C  sG  t  t ƒ } d } x(| t | ƒ k  r<| | j ƒ  s/| | rV | | d d } n
 | d } xÌ | t | ƒ k  r+| | k r| r| | j ƒ  r| | j | ƒ | | j | | ƒ } | rxH | D]@ } | d | d f | _ | j | ƒ t | ƒ sÍ t | f SqÍ Wd } Pqn  | d 7} qc Wn  | d 7} q Wt | f S(   Ni    iÿÿÿÿi   (	   R   t   listt   lent   is_tautologyt   appendt   unifyt   _parentst   TrueR"   (   R#   R(   t   triedt   it   jt
   newclausest	   newclause(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   O   s,    

#N(	   R   R   t
   ANSWER_KEYR2   R   R   R"   R+   R   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   *   s   !R   c           B  sA   e  Z d d d d  „ Z e d „ Z e d „ Z e d „  ƒ Z RS(   c         C  sP   | d k	 r$ t | t ƒ s- t ‚ n	 t ƒ  } t j |  | | | ƒ d |  _ d S(   ué   
        :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)
        N(   R   t
   isinstanceR   t   AssertionErrorR   t   __init__t   _clauses(   R#   R$   R%   t   prover(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR;   q   s
    	c         C  sa   |  j  d k rZ |  j j |  j ƒ  |  j ƒ  | ƒ \ |  _  } | |  _ t j | ƒ |  _	 n  |  j  S(   uh   
        Perform the actual proof.  Store the result to prevent unnecessary
        re-proving.
        N(
   t   _resultR   t   _proverR+   R$   R%   R<   R   R   t   _proof(   R#   R&   R(   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   prove   s    	$	c         C  s˜   |  j  | ƒ t ƒ  } t t t j ƒ ƒ } xf |  j D][ } xR | D]J } t | t ƒ rB | j	 | k rB t | j
 t ƒ rB | j | j
 ƒ qB qB Wq5 W| S(   N(   RA   t   setR   R
   R   R8   R<   R9   R   t   functiont   argumentR   t   add(   R#   R&   t   answerst	   answer_ext   clauset   term(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   find_answersŽ   s    	c   	      C  s"  d } t  g  |  D] } t t | ƒ ƒ ^ q ƒ } t t t |  ƒ ƒ ƒ } xÒ t t |  ƒ ƒ D]¾ } d } d } |  | j ƒ  r‡ d } n  |  | j rª t |  | j ƒ } n  d | t t |  | ƒ ƒ d | } d | t t | d ƒ ƒ t | d ƒ } | d | |  | | | f 7} q\ W| S(   u,   
        Decorate the proof output.
        u    u   Au	   Tautologyu    i   u   [%s] %s %s %s
(   t   maxR-   R    t   rangeR.   R1   (	   R(   t   outRH   t   max_clause_lent   max_seq_lenR4   t   parentst   tautt   seq(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR      s    +	&,"N(	   R   R   R   R;   R"   RA   RJ   t   staticmethodR   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   p   s   t   Clausec           B  s‰   e  Z d  „  Z d d d e d „ Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z RS(   c         C  s&   t  j |  | ƒ d  |  _ d  |  _ d  S(   N(   R,   R;   R   t   _is_tautologyR1   (   R#   t   data(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR;   ´   s    	c         C  sW  | d k r t ƒ  } n  | d k r3 g  g  f } n  | d k rN g  g  f } n  t | t ƒ rl t | ƒ } n  t |  | | | | t | ƒ } g  } x} t | ƒ D]o \ } }	 | | k r xT t | ƒ D]C \ }
 } | |
 k rÂ |
 | k rÂ |	 j | ƒ rÂ | j	 |
 ƒ qÂ qÂ Wq q Wg  } x: t
 t | ƒ ƒ D]& } | | k r)| j	 | | ƒ q)q)W| S(   uÔ  
        Attempt to unify this Clause with the other, returning a list of
        resulting, unified, Clauses.

        :param other: ``Clause`` with which to unify
        :param bindings: ``BindingDict`` containing bindings that should be used
        during the unification
        :param used: tuple of two lists of atoms.  The first lists the
        atoms from 'self' that were successfully unified with atoms from
        'other'.  The second lists the atoms from 'other' that were successfully
        unified with atoms from 'self'.
        :param skipped: tuple of two ``Clause`` objects.  The first is a list of all
        the atoms from the 'self' Clause that have not been unified with
        anything on the path.  The second is same thing for the 'other' Clause.
        :param debug: bool indicating whether debug statements should print
        :return: list containing all the resulting ``Clause`` objects that could be
        obtained by unification
        N(   R   t   BindingDictR9   t   boolt   DebugObjectt   _iterate_firstt   _complete_unify_patht	   enumeratet   subsumesR/   RL   R-   (   R#   t   othert   bindingst   usedt   skippedt   debugR6   t   subsumedR4   t   c1R5   t   c2R'   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR0   ¹   s*    'c         C  s%   x |  D] } | | k r t  Sq Wt S(   u„   
        Return True iff every term in 'self' is a term in 'other'.

        :param other: ``Clause``
        :return: bool
        (   R"   R2   (   R#   R^   R)   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt
   isSubsetOfè   s    c   	   	   C  s¨   g  } x> | D]6 } t  | t ƒ r5 | j | j ƒ q | j | ƒ q Wt | ƒ } t ƒ  } g  g  f } g  g  f } t t ƒ } t t	 |  | | | | t
 | ƒ ƒ d k S(   uì   
        Return True iff 'self' subsumes 'other', this is, if there is a
        substitution such that every term in 'self' can be unified with a term
        in 'other'.

        :param other: ``Clause``
        :return: bool
        i    (   R9   R	   R/   RI   RT   RW   RY   R"   R-   RZ   t   _subsumes_finalize(	   R#   R^   t   negatedothert   atomt   negatedotherClauseR_   R`   Ra   Rb   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR]   ô   s(    			c         C  s   t  t j |  | | ƒ ƒ S(   N(   RT   R,   t   __getslice__(   R#   t   startt   end(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRk     s    c         C  s)   t  g  |  D] } | | k r
 | ^ q
 ƒ S(   N(   RT   (   R#   R^   R)   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __sub__  s    c         C  s   t  t j |  | ƒ ƒ S(   N(   RT   R,   t   __add__(   R#   R^   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRo      s    c         C  så   |  j  d k	 r |  j  Sx¿ t |  ƒ D]± \ } } t | t ƒ s# t |  ƒ d } xƒ | | k rÐ |  | } t | t ƒ r• | j | k rÃ t |  _  t Sn. t | t ƒ rÃ | | j k rÃ t |  _  t Sn  | d 8} qQ Wq# q# Wt	 |  _  t	 S(   u›   
        Self is a tautology if it contains ground terms P and -P.  The ground
        term, P, must be an exact match, ie, not using unification.
        i   N(
   RU   R   R\   R9   R   R-   R	   RI   R2   R"   (   R#   R4   R)   R5   t   b(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR.   #  s$    
			c         C  s   t  t j d „  |  Dƒ ƒ S(   Nc         s  s%   |  ] } | j  ƒ  | j ƒ  BVq d  S(   N(   t   freet	   constants(   t   .0Ri   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pys	   <genexpr><  s    (   R   t   operatort   or_(   R#   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRq   ;  s    c         C  s)   t  g  |  D] } | j | | ƒ ^ q
 ƒ S(   u½   
        Replace every instance of variable with expression across every atom
        in the clause

        :param variable: ``Variable``
        :param expression: ``Expression``
        (   RT   t   replace(   R#   t   variablet
   expressionRi   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRv   >  s    c         C  s&   t  g  |  D] } | j | ƒ ^ q
 ƒ S(   u¾   
        Replace every binding

        :param bindings: A list of tuples mapping Variable Expressions to the
        Expressions to which they are bound
        :return: ``Clause``
        (   RT   t   substitute_bindings(   R#   R_   Ri   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRy   H  s    c         C  s   d d j  d „  |  Dƒ ƒ d S(   Nu   {u   , c         s  s   |  ] } d  | Vq d S(   u   %sN(    (   Rs   t   item(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pys	   <genexpr>S  s    u   }(   t   join(   R#   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __str__R  s    c         C  s   d |  S(   Nu   %s(    (   R#   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __repr__U  s    N(   R   R   R;   R   R"   R0   Rf   R]   Rk   Rn   Ro   R.   Rq   Rv   Ry   R|   R}   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRT   ²   s   	/		&						
	
	c      
   C  s^  | j  d |  | | f ƒ t |  ƒ s4 t | ƒ rM | |  | | | | | ƒ St |  | | | | | | d ƒ } | d |  d g | d f } | t |  d | | | | | | d ƒ 7} yŠ t |  d | d | | ƒ \ }	 }
 } |  d | d | d } | d | d | d } | t | | |	 |
 g  g  f | | d ƒ 7} Wn t k
 rUn X| Sd S(   uF   
    This method facilitates movement through the terms of 'self'
    u   unify(%s,%s) %si   i    N(   t   lineR-   t   _iterate_secondRZ   t   _unify_termst   BindingException(   t   firstt   secondR_   R`   Ra   t   finalize_methodRb   R'   t
   newskippedt   newbindingst   newusedt   unusedt   newfirstt	   newsecond(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRZ   Y  s0    $#	c      
   C  s8  | j  d |  | | f ƒ t |  ƒ s4 t | ƒ rM | |  | | | | | ƒ S| d | d | d g f } t |  | d | | | | | d ƒ } yŠ t |  d | d | | ƒ \ }	 }
 } |  d | d | d } | d | d | d } | t | | |	 |
 g  g  f | | d ƒ 7} Wn t k
 r/n X| Sd S(   uG   
    This method facilitates movement through the terms of 'other'
    u   unify(%s,%s) %si    i   N(   R~   R-   R   R€   R   (   R‚   Rƒ   R_   R`   Ra   R„   Rb   R…   R'   R†   R‡   Rˆ   R‰   RŠ   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   …  s,    ##	c         C  sø  t  |  t ƒ s t ‚ t  | t ƒ s* t ‚ | d k rB t ƒ  } n  | d k r] g  g  f } n  t  |  t ƒ rÁ t  | t ƒ rÁ t |  j | | ƒ } | d |  g | d | g f } g  g  f } n*t  |  t ƒ r%t  | t ƒ r%t |  | j | ƒ } | d |  g | d | g f } g  g  f } nÆ t  |  t	 ƒ rt |  j
 j |  j f g ƒ } | d |  g | d f } g  | g f } nl t  | t	 ƒ rÙt | j
 j | j f g ƒ } | d | d | g f } |  g g  f } n t |  | f ƒ ‚ | | | f S(   uÑ  
    This method attempts to unify two terms.  Two expressions are unifiable
    if there exists a substitution function S such that S(a) == S(-b).

    :param a: ``Expression``
    :param b: ``Expression``
    :param bindings: ``BindingDict`` a starting set of bindings with which
    the unification must be consistent
    :return: ``BindingDict`` A dictionary of the bindings required to unify
    :raise ``BindingException``: If the terms cannot be unified
    i    i   N(   R9   R   R:   R   RW   R	   R   t   most_general_unificationRI   R   R‚   Rw   Rƒ   R   (   R)   Rp   R_   R`   R†   R‡   Rˆ   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR€   ¬  s0    ""c         C  sj   | d s | d rU t  | d | d |  | ƒ } | j d | ƒ | j | ƒ g S| j d ƒ g  Sd  S(   Ni    i   u     -> New Clause: %su     -> End(   RT   R~   Ry   (   R‚   Rƒ   R_   R`   Ra   Rb   R7   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR[   Ú  s     c         C  s-   t  | d ƒ r% t  |  ƒ r% t g Sg  Sd  S(   Ni    (   R-   R2   (   R‚   Rƒ   R_   R`   Ra   Rb   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRg   ä  s    c         C  s~   g  } xq t  t |  ƒ ƒ D]] } xG | j ƒ  D]9 } t | j ƒ r, t t ƒ  ƒ } | j | | ƒ } q, q, W| j | ƒ q W| S(   uC   
    Skolemize, clausify, and standardize the variables apart.
    (	   t	   _clausifyR   Rq   R   t   nameR   R   Rv   R/   (   Rx   t   clause_listRH   Rq   t   newvar(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   ð  s    c         C  s:  t  |  t ƒ r) t |  j ƒ t |  j ƒ St  |  t ƒ r™ t |  j ƒ } t |  j ƒ } t | ƒ d k sn t ‚ t | ƒ d k s† t ‚ | d | d g St  |  t ƒ r¸ t	 |  g ƒ g St  |  t
 ƒ r× t	 |  g ƒ g St  |  t ƒ r-t  |  j t
 ƒ rt	 |  g ƒ g St  |  j t ƒ r-t	 |  g ƒ g Sn  t ƒ  ‚ d S(   u;   
    :param expression: a skolemized expression in CNF
    i   i    N(   R9   R   RŒ   R‚   Rƒ   R   R-   R:   R   RT   R   R	   RI   R   (   Rx   R‚   Rƒ   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRŒ   þ  s$    RW   c           B  sS   e  Z d d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   c         C  s7   i  |  _  | r3 x! | D] \ } } | |  | <q Wn  d S(   u‚   
        :param binding_list: list of (``AbstractVariableExpression``, ``AtomicExpression``) to initialize the dictionary
        N(   t   d(   R#   t   binding_listt   vRp   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR;     s    	c         C  s  t  | t ƒ s t ‚ t  | t ƒ s* t ‚ y |  | } Wn t k
 rQ d } n X| se | | k ru | |  j | <n t  | t ƒ rô y |  | j } Wn t k
 r® d } n Xt	 | ƒ } | sÎ | | k rá | |  j | j <qt
 d | ƒ ‚ n t
 d | ƒ ‚ d S(   u€  
        A binding is consistent with the dict if its variable is not already bound, OR if its
        variable is already bound to its argument.

        :param variable: ``Variable`` The variable to bind
        :param binding: ``Expression`` The atomic to which 'variable' should be bound
        :raise BindingException: If the variable cannot be bound in this dictionary
        u*   Variable %s already bound to another valueN(   R9   R
   R:   R   t   KeyErrorR   R   R   Rw   R   R   (   R#   Rw   t   bindingt   existingt   binding2(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __setitem__"  s(    	

c         C  sY   t  | t ƒ s t ‚ |  j | } x0 | rT y |  j | } Wq% t k
 rP | SXq% Wd S(   uD   
        Return the expression to which 'variable' is bound
        N(   R9   R
   R:   R   R“   (   R#   Rw   t   intermediate(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __getitem__I  s    	c         C  s   | |  j  k S(   N(   R   (   R#   Rz   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __contains__V  s    c         C  s‰   y[ t  ƒ  } x" |  j D] } |  j | | | <q Wx" | j D] } | j | | | <q; W| SWn' t k
 r„ t d |  | f ƒ ‚ n Xd S(   u  
        :param other: ``BindingDict`` The dict with which to combine self
        :return: ``BindingDict`` A new dict containing all the elements of both parameters
        :raise BindingException: If the parameter dictionaries are not consistent with each other
        u?   Attempting to add two contradicting BindingDicts: '%s' and '%s'N(   RW   R   R   (   R#   R^   t   combinedR’   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRo   Y  s    	c         C  s   t  |  j ƒ S(   N(   R-   R   (   R#   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   __len__l  s    c           s:   d j  ‡  f d †  t ˆ  j j ƒ  ƒ Dƒ ƒ } d | d S(   Nu   , c         3  s&   |  ] } d  | ˆ  j  | f Vq d S(   u   %s: %sN(   R   (   Rs   R’   (   R#   (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pys	   <genexpr>p  s    u   {u   }(   R{   t   sortedR   t   keys(   R#   t   data_str(    (   R#   s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR|   o  s    .c         C  s   d |  S(   Nu   %s(    (   R#   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR}   s  s    N(   R   R   R   R;   R—   R™   Rš   Ro   Rœ   R|   R}   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRW     s   
	'					c         C  sÆ   | d k r t ƒ  } n  |  | k r( | St |  t ƒ rG t |  | | ƒ St | t ƒ rf t | |  | ƒ St |  t ƒ r° t | t ƒ r° t |  j | j | ƒ t |  j | j | ƒ St	 |  | f ƒ ‚ d S(   uh  
    Find the most general unification of the two given expressions

    :param a: ``Expression``
    :param b: ``Expression``
    :param bindings: ``BindingDict`` a starting set of bindings with which the
                     unification must be consistent
    :return: a list of bindings
    :raise BindingException: if the Expressions cannot be unified
    N(
   R   RW   R9   R   t   _mgu_varR   R‹   RC   RD   R   (   R)   Rp   R_   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR‹   w  s    c         C  sR   |  j  | j ƒ  | j ƒ  Bk r4 t |  | f ƒ ‚ n t |  j  | f g ƒ | Sd  S(   N(   Rw   Rq   Rr   R   RW   (   t   varRx   R_   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR    ’  s    R   c           B  s   e  Z d  „  Z RS(   c         C  s:   t  | t ƒ r& t j |  d | ƒ n t j |  | ƒ d  S(   Nu   '%s' cannot be bound to '%s'(   R9   t   tuplet	   ExceptionR;   (   R#   t   arg(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR;   š  s    (   R   R   R;   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR   ™  s   t   UnificationExceptionc           B  s   e  Z d  „  Z RS(   c         C  s   t  j |  d | | f ƒ d  S(   Nu   '%s' cannot unify with '%s'(   R£   R;   (   R#   R)   Rp   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR;   ¢  s    (   R   R   R;   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR¥   ¡  s   RY   c           B  s)   e  Z e d  d „ Z d „  Z d „  Z RS(   i    c         C  s   | |  _  | |  _ d  S(   N(   t   enabledt   indent(   R#   R¦   R§   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR;   §  s    	c         C  s   t  |  j |  j | ƒ S(   N(   RY   R¦   R§   (   R#   R4   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRo   «  s    c         C  s%   |  j  r! t d |  j | ƒ n  d  S(   Nu       (   R¦   R   R§   (   R#   R~   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR~   ®  s    	(   R   R   R2   R;   Ro   R~   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyRY   ¦  s   	c       	   C  s  t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d ƒ t  d	 ƒ t  d
 ƒ t j d ƒ }  t j d ƒ } t j d ƒ } t d |  | | t ƒ  j | |  | g ƒ f ƒ t j d ƒ }  t j d ƒ } t j d ƒ } t d |  | | t ƒ  j | |  | g ƒ f ƒ t j d ƒ } t j d ƒ } t d | | t ƒ  j | | g ƒ f ƒ d  S(   Nu   man(x)u   (man(x) -> man(x))u   (man(x) -> --man(x))u   -(man(x) and -man(x))u   (man(x) or -man(x))u   (man(x) iff man(x))u   -(man(x) iff -man(x))u   all x.man(x)u-   -all x.some y.F(x,y) & some x.all y.(-F(x,y))u   some x.all y.sees(x,y)u   all x.(man(x) -> mortal(x))u   man(Socrates)u   mortal(Socrates)u   %s, %s |- %s: %su   all x.(man(x) -> walks(x))u	   man(John)u   some y.walks(y)u5   some e1.some e2.(believe(e1,john,e2) & walk(e2,mary))u   some e0.walk(e0,mary)u   %s |- %s: %s(   t   resolution_testR   t
   fromstringR   R   RA   (   t   p1t   p2t   ct   p(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   testResolutionProver³  s2    













//c         C  s9   t  j |  ƒ } t ƒ  j | ƒ } t d | | f ƒ d  S(   Nu	   |- %s: %s(   R   R©   R   RA   R   (   R*   t   ft   t(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyR¨   Ò  s    c          C  sƒ  t  j }  t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d	 ƒ ƒ ƒ t t |  d
 ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ t t |  d ƒ ƒ ƒ d  S(   Nu   P(x) | Q(x)u   (P(x) & Q(x)) | R(x)u   P(x) | (Q(x) & R(x))u   (P(x) & Q(x)) | (R(x) & S(x))u   P(x) | Q(x) | R(x)u   P(x) | (Q(x) & R(x)) | S(x)u   exists x.P(x) | Q(x)u   -(-P(x) & Q(x))u   P(x) <-> Q(x)u   -(P(x) <-> Q(x))u   -(all x.P(x))u   -(some x.P(x))u   some x.P(x)u   some x.all y.P(x,y)u   all y.some x.P(x,y)u   all z.all y.some x.P(x,y,z)u1   all x.(all y.P(x,y) -> -all y.(Q(x,y) -> R(x,y)))(   R   R©   R   R   (   t   lexpr(    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   test_clausifyØ  s$    	c          C  sK   t  ƒ  t ƒ  t ƒ  t ƒ  t j d ƒ }  t t |  |  g ƒ j ƒ  ƒ d  S(   Nu   man(x)(   R²   R   R®   R   R©   R   RA   (   R­   (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   demoò  s    u   __main__(6   t   __doc__t
   __future__R    R   Rt   t   collectionsR   t	   functoolsR   t   nltk.semR   t   nltk.sem.logicR   R   R   R   R	   R
   R   R   R   R   R   t   nltk.inference.apiR   R   t   nltk.compatR   R£   R   R   R   R,   RT   RZ   R   R   R€   R[   Rg   R   RŒ   t   objectRW   R‹   R    R   R¥   RY   R®   R¨   R²   R³   R   (    (    (    s8   lib/python2.7/site-packages/nltk/inference/resolution.pyt   <module>   sB   RFB¦	,	'.	
			`					
