³ò
ŽB_Kc           @   sŠ  d  d k  l Z d  d k Td  d k l Z d  d k l Z l Z d e f d „  ƒ  YZ	 d e f d „  ƒ  YZ
 d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d# d# d „ Z d „  Z d „  Z d „  Z d „  Z d e f d „  ƒ  YZ d# d „ Z d „  Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d  „  Z d! „  Z  e! d" j o e  ƒ  n d# S($   iÿÿÿÿ(   t   defaultdict(   t   *(   t	   skolemize(   t   Provert   BaseProverCommandt   ProverParseErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR      s    t   ResolutionProverc           B   s/   e  Z d  Z e Z e e e d „ Z d „  Z RS(   t   ANSWERc         C   sú   | p
 g  } n t  } y{ g  } | o | i t | ƒ ƒ n x! | D] } | i t | ƒ ƒ qF W|  i | ƒ \ } } | o t i | ƒ GHn Wn[ t j
 oO } |  i o& t | ƒ i	 d ƒ o t
 } g  } qð | o	 | GHqð | ‚ n X| | f S(   sð   
        @param goal: Input expression to prove
        @type goal: L{logic.Expression}
        @param assumptions: Input expressions to use as assumptions in the proof
        @type assumptions: L{list} of logic.Expression objects
        s    maximum recursion depth exceeded(   t   Nonet   extendt   clausifyt   _attempt_prooft   ResolutionProverCommandt   _decorate_clausest   RuntimeErrort   _assume_falset   strt
   startswitht   False(   t   selft   goalt   assumptionst   verboset   resultt   clausest   at   e(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   _prove   s*    
  
	c         C   sZ  t  t ƒ } d } x;| t | ƒ j  o'| | i ƒ  p| | o | | d d } n | d } xÚ | t | ƒ j  oÂ | | j o§ | o  | | i ƒ  oŽ | | i | ƒ | | i | | ƒ } | o[ xM | D]E } | d | d f | _ | i | ƒ t | ƒ p t | f SqÖ qÖ Wd } Pq.n | d 7} qg 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(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR   7   s.    
& 	(	   R   R   t
   ANSWER_KEYR$   R   R
   R   R   R   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR      s   R   c           B   sA   e  Z e e e d  „ Z e d „ Z e d „ Z e d „  ƒ Z RS(   c         C   sT   | d j	 o t | t ƒ p t ‚ n
 t ƒ  } t i |  | | | ƒ d |  _ d S(   sø   
        @param goal: Input expression to prove
        @type goal: L{logic.Expression}
        @param assumptions: Input expressions to use as assumptions in
            the proof.
        @type assumptions: C{list} of L{logic.Expression}
        N(   R
   t
   isinstanceR   t   AssertionErrorR   t   __init__t   _clauses(   R   R   R   t   prover(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR-   X   s
    	c         C   sc   |  i  t j oL |  i i |  i ƒ  |  i ƒ  | ƒ \ |  _  } | |  _ t i | ƒ |  _	 n |  i  S(   sh   
        Perform the actual proof.  Store the result to prevent unnecessary
        re-proving.
        (
   t   _resultR
   t   _proverR   R   R   R.   R   R   t   _proof(   R   R   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   proveh   s    		c         C   sœ   |  i  | ƒ t ƒ  } t t t i ƒ ƒ } xj |  i D]_ } xV | D]N } t | t ƒ o8 | i	 | j o( t | i
 t ƒ o | i | i
 ƒ qB qB Wq5 W| S(   N(   R3   t   sett   VariableExpressiont   VariableR   R*   R.   R+   t   ApplicationExpressiont   functiont   argumentt   IndividualVariableExpressiont   add(   R   R   t   answerst	   answer_ext   clauset   term(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   find_answersu   s    	
  c   
   	   C   s.  d } t  g  } |  D] } | t t | ƒ ƒ q ~ ƒ } t t t |  ƒ ƒ ƒ } xÖ t t |  ƒ ƒ D]Â } d } d } |  | i ƒ  o
 d } n |  | i o t |  | i ƒ } n d | t t |  | ƒ ƒ d | } d | t t | d ƒ ƒ t | d ƒ }	 | d |	 |  | | | f 7} qd W| S(   s,   
        Decorate the proof output.
        t    t   At	   Tautologyt    i   s   [%s] %s %s %s
(   t   maxR   R   t   rangeR    R#   (
   R   t   outt   _[1]R>   t   max_clause_lent   max_seq_lenR&   t   parentst   tautt   seq(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR   ‚   s    3 
&,"(	   R   R   R
   R-   R   R3   R@   t   staticmethodR   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR   W   s   t   Clausec           B   s‰   e  Z d  „  Z e e e 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  i |  | ƒ d  |  _ d  |  _ d  S(   N(   R   R-   R
   t   _is_tautologyR#   (   R   t   data(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR-   —   s    	c         C   sg  | t  j o t ƒ  } n | t  j o g  g  f } n | t  j o g  g  f } n t | t ƒ o t | ƒ } n t |  | | | | t | ƒ } g  } xƒ t | ƒ D]u \ } }	 | | j o\ xY t | ƒ D]G \ }
 } | |
 j o. |
 | j o! |	 i | ƒ o | i	 |
 ƒ qË qË Wq¥ q¥ Wg  } x< t
 t | ƒ ƒ D]( } | | j o | i	 | | ƒ q7q7W| S(   sÝ  
        Attempt to unify this Clause with the other, returning a list of 
        resulting, unified, Clauses.
        
        @param other: C{Clause} with which to unify
        @param bindings: C{BindingDict} containing bindings that should be used
        during the unification
        @param used: C{tuple} of two C{list}s 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: C{tuple} of two C{Clause}s.  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: C{bool} indicating whether debug statements should print
        @return: C{list} containing all the resulting C{Clause}s that could be
        obtained by unification
        (   R
   t   BindingDictR+   t   boolt   DebugObjectt   _iterate_firstt   _complete_unify_patht	   enumeratet   subsumesR!   RF   R   (   R   t   othert   bindingst   usedt   skippedt   debugR(   t   subsumedR&   t   c1R'   t   c2R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR"   œ   s&       * c         C   s*   x# |  D] } | | j o t  Sq q Wt S(   sŽ   
        Return True iff every term in 'self' is a term in 'other'.
        
        @param other: C{Clause}
        @return: C{bool}
        (   R   R$   (   R   RY   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt
   isSubsetOfÅ   s
     c   	      C   sª   g  } x@ | D]8 } t  | t ƒ o | i | i ƒ q | i | ƒ q Wt | ƒ } t ƒ  } g  g  f } g  g  f } t t ƒ } t t	 |  | | | | t
 | ƒ ƒ d j S(   s÷   
        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: C{Clause}
        @return: C{bool}
        i    (   R+   t   NegatedExpressionR!   R?   RO   RR   RT   R   R   RU   t   _subsumes_finalize(	   R   RY   t   negatedothert   atomt   negatedotherClauseRZ   R[   R\   R]   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRX   Ñ   s    	 	c         C   s   t  t i |  | | ƒ ƒ S(   N(   RO   R   t   __getslice__(   R   t   startt   end(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRg   ì   s    c         C   s6   t  g  } |  D] } | | j o | | q q ~ ƒ S(   N(   RO   (   R   RY   RH   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __sub__ï   s    c         C   s   t  t i |  | ƒ ƒ S(   N(   RO   R   t   __add__(   R   RY   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRk   ò   s    c         C   sü   |  i  t j	 o |  i  Sn xÑ t |  ƒ D]Ã \ } } t | t ƒ p§ t |  ƒ d } x” | | j o‚ |  | } t | t ƒ o% | i | j o t |  _  t SqØ n6 t | t ƒ o% | | i j o t |  _  t SqØ n | d 8} qW Wq( q( Wt	 |  _  t	 S(   s   
        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   (
   RP   R
   RW   R+   t   EqualityExpressionR   Rb   R?   R$   R   (   R   R&   R   R'   t   b(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR    õ   s&     
			c         C   s1   t  ƒ  } x! |  D] } | | i t ƒ O} q W| S(   N(   R4   t   freeR   (   R   t   sRe   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRn     s
    	 c         C   s1   t  g  } |  D] } | | i | | ƒ q ~ ƒ S(   sÃ   
        Replace every instance of variable with expression across every atom
        in the clause
        
        @param variable: C{Variable}
        @param expression: C{Expression}
        (   RO   t   replace(   R   t   variablet
   expressionRH   Re   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRp     s    c         C   s.   t  g  } |  D] } | | i | ƒ q ~ ƒ S(   sÉ   
        Replace every binding 
        
        @param bindings: A C{list} of tuples mapping Variable Expressions to the
        Expressions to which they are bound
        @return: C{Clause}
        (   RO   t   substitute_bindings(   R   RZ   RH   Re   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRs     s    c         C   s6   d d i  g  } |  D] } | t | ƒ q ~ ƒ d S(   Nt   {s   , t   }(   t   joinR   (   R   RH   t   item(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __str__'  s    c         C   s
   t  |  ƒ S(   N(   R   (   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __repr__*  s    (   R   R   R-   R
   R   R"   Ra   RX   Rg   Rj   Rk   R    Rn   Rp   Rs   Rx   Ry   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRO   –   s   	)								
	
	c         C   sf  | i  d |  | | f ƒ t |  ƒ p t | ƒ o | |  | | | | | ƒ Snt |  | | | | | | 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 j
 o n X| Sd S(   sF   
    This method facilitates movement through the terms of 'self'
    s   unify(%s,%s) %si   i    N(   t   lineR   t   _iterate_secondRU   t   _unify_termst   BindingException(   t   firstt   secondRZ   R[   R\   t   finalize_methodR]   R   t
   newskippedt   newbindingst   newusedt   unusedt   newfirstt	   newsecond(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRU   -  s    "*&0c         C   s@  | i  d |  | | f ƒ t |  ƒ p t | ƒ o | |  | | | | | ƒ Snê | 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 j
 o n X| Sd S(   sG   
    This method facilitates movement through the terms of 'other'
    s   unify(%s,%s) %si    i   N(   Rz   R   R{   R|   R}   (   R~   R   RZ   R[   R\   R€   R]   R   R   R‚   Rƒ   R„   R…   R†   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR{   J  s    &&0c         C   s
  t  |  t ƒ p t ‚ t  | t ƒ p t ‚ | t j o t ƒ  } n | t j o g  g  f } n t  |  t ƒ oW t  | t ƒ oG t |  i | | ƒ } | d |  g | d | g f } g  g  f } n2t  |  t ƒ oW t  | t ƒ oG t |  | i | ƒ } | d |  g | d | g f } g  g  f } nË t  |  t	 ƒ oL t |  i
 i |  i f g ƒ } | d |  g | d f } g  | g f } no t  | t	 ƒ oL t | i
 i | i f g ƒ } | d | d | g f } |  g g  f } n t |  | f ƒ ‚ | | | f S(   sÐ  
    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: C{Expression} 
    @param b: C{Expression} 
    @param bindings: C{BindingDict} a starting set of bindings with which 
    the unification must be consistent
    @return: C{BindingDict} A dictionary of the bindings required to unify
    @raise C{BindingException}: If the terms cannot be unified
    i    i   (   R+   t
   ExpressionR,   R
   RR   Rb   R7   t   most_general_unificationR?   Rl   R~   Rq   R   R}   (   R   Rm   RZ   R[   R‚   Rƒ   R„   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR|   d  s,     " "c         C   sp   | d p | d oE t  | d | d |  | ƒ } | i d | ƒ | i | ƒ g Sn | i d ƒ g  Sd  S(   Ni    i   s     -> New Clause: %ss     -> End(   RO   Rz   Rs   (   R~   R   RZ   R[   R\   R]   R)   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRV     s     c         C   s3   t  | d ƒ o t  |  ƒ o t g Sn g  Sd  S(   Ni    (   R   R$   (   R~   R   RZ   R[   R\   R]   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRc   ˜  s     c         C   s€   g  } xs t  t |  ƒ ƒ D]_ } xI | i ƒ  D]; } t | i ƒ o% t t ƒ  ƒ } | i | | ƒ } q, q, W| i | ƒ q W| S(   sC   
    Skolemize, clausify, and standardize the variables apart.
    (	   t	   _clausifyR   Rn   t	   is_indvart   nameR5   t   unique_variableRp   R!   (   Rr   t   clause_listR>   Rn   t   newvar(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR   £  s      c         C   s^  t  |  t ƒ o t |  i ƒ t |  i ƒ Sn$t  |  t ƒ oi t |  i ƒ } t |  i ƒ } t | ƒ d j p t ‚ t | ƒ d j p t ‚ | d | d g Sn« t  |  t ƒ o t	 |  g ƒ g Sn‡ t  |  t
 ƒ o t	 |  g ƒ g Snc t  |  t ƒ oR t  |  i t
 ƒ o t	 |  g ƒ g SqQt  |  i t ƒ o t	 |  g ƒ g SqQn t ƒ  ‚ d S(   s;   
    @param expression: a skolemized expression in CNF
    i   i    N(   R+   t   AndExpressionR‰   R~   R   t   OrExpressionR   R,   Rl   RO   R7   Rb   R?   R   (   Rr   R~   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR‰   °  s$    RR   c           B   sS   e  Z e d  „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(   c         C   s9   h  |  _  | o% x" | D] \ } } | |  | <q Wn d S(   sƒ   
        @param binding_list: C{list} of (C{AbstractVariableExpression}, C{AtomicExpression}) to initialize the dictionary
        N(   t   d(   R   t   binding_listt   vRm   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR-   É  s
    	 c      	   C   s  t  | t ƒ p t ‚ t  | t ƒ p t ‚ y |  | } Wn t j
 o d } n X| p | | j o | |  i | <n— t  | t ƒ ov y |  | i } Wn t j
 o d } n Xt	 | ƒ } | p | | j o | |  i | i <qt
 d | ƒ ‚ n t
 d | ƒ ‚ d S(   s‡  
        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: C{Variable} The variable to bind
        @param binding: C{Expression} The atomic to which 'variable' should be bound
        @raise BindingException: If the variable cannot be bound in this dictionary
        s*   Variable %s already bound to another valueN(   R+   R6   R,   R‡   t   KeyErrorR
   R‘   R:   Rq   R5   R}   (   R   Rq   t   bindingt   existingt   binding2(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __setitem__Ó  s(    	c         C   sb   t  | t ƒ p t ‚ |  i | } x7 | o/ y |  i | } Wq' t j
 o | Sq' Xq' Wd S(   sD   
        Return the expression to which 'variable' is bound
        N(   R+   R6   R,   R‘   R”   (   R   Rq   t   intermediate(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __getitem__ø  s    
c         C   s   | |  i  j S(   N(   R‘   (   R   Rw   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __contains__  s    c      	   C   s‹   y[ t  ƒ  } x" |  i D] } |  i | | | <q Wx" | i D] } | i | | | <q; W| SWn) t j
 o t d |  | f ƒ ‚ n Xd S(   s  
        @param other: C{BindingDict} The dict with which to combine self
        @return: C{BindingDict} A new dict containing all the elements of both parameters
        @raise BindingException: If the parameter dictionaries are not consistent with each other
        s?   Attempting to add two contradicting BindingDicts: '%s' and '%s'N(   RR   R‘   R}   (   R   RY   t   combinedR“   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRk     s    	
 
 c         C   s   t  |  i ƒ S(   N(   R   R‘   (   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   __len__  s    c      	   C   sD   d d i  g  } |  i D] } | d | |  i | f q ~ ƒ d S(   NRt   s   , s   %s: %sRu   (   Rv   R‘   (   R   RH   R“   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRx     s    c         C   s
   t  |  ƒ S(   N(   R   (   R   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRy      s    (   R   R   R
   R-   R˜   Rš   R›   Rk   R   Rx   Ry   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRR   È  s   
	%					c         C   sÝ   | d j o t ƒ  } n |  | j o | Sn™ t |  t ƒ o t |  | | ƒ Snu t | t ƒ o t | |  | ƒ SnQ t |  t ƒ o@ t | t ƒ o0 t |  i | i | ƒ t |  i | i | ƒ Sn t	 |  | f ƒ ‚ d S(   si  
    Find the most general unification of the two given expressions
    
    @param a: C{Expression}
    @param b: C{Expression}
    @param bindings: C{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
   RR   R+   R:   t   _mgu_varR7   Rˆ   R8   R9   R}   (   R   Rm   RZ   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRˆ   $  s    c         C   sM   |  i  | i t ƒ j o t |  | f ƒ ‚ n t |  i  | f g ƒ | Sd  S(   N(   Rq   Rn   R   R}   RR   (   t   varRr   RZ   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRž   >  s    R}   c           B   s   e  Z d  „  Z RS(   c         C   s<   t  | t ƒ o t i |  d | ƒ n t i |  | ƒ d  S(   Ns   '%s' cannot be bound to '%s'(   R+   t   tuplet	   ExceptionR-   (   R   t   arg(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR-   F  s    (   R   R   R-   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR}   E  s   t   UnificationExceptionc           B   s   e  Z d  „  Z RS(   c         C   s   t  i |  d | | f ƒ d  S(   Ns   '%s' cannot unify with '%s'(   R¡   R-   (   R   R   Rm   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR-   M  s    (   R   R   R-   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR£   L  s   RT   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¥   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR-   R  s    	c         C   s   t  |  i |  i | ƒ S(   N(   RT   R¤   R¥   (   R   R&   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRk   V  s    c         C   s"   |  i  o d |  i | GHn d  S(   Ns       (   R¤   R¥   (   R   Rz   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRz   Y  s    
(   R   R   R$   R-   Rk   Rz   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyRT   Q  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 ƒ  i d ƒ }  t ƒ  i d ƒ } t ƒ  i d ƒ } d |  | | t ƒ  i | |  | g ƒ f GHt ƒ  i d ƒ }  t ƒ  i d ƒ } t ƒ  i d ƒ } d |  | | t ƒ  i | |  | g ƒ f GHt ƒ  i d ƒ } t ƒ  i d ƒ } d | | t ƒ  i | | g ƒ f GHd  S(   Ns   man(x)s   (man(x) -> man(x))s   (man(x) -> --man(x))s   -(man(x) and -man(x))s   (man(x) or -man(x))s   (man(x) iff man(x))s   -(man(x) iff -man(x))s   all x.man(x)s-   -all x.some y.F(x,y) & some x.all y.(-F(x,y))s   some x.all y.sees(x,y)s   all x.(man(x) -> mortal(x))s   man(Socrates)s   mortal(Socrates)s   %s, %s |- %s: %ss   all x.(man(x) -> walks(x))s	   man(John)s   some y.walks(y)s5   some e1.some e2.(believe(e1,john,e2) & walk(e2,mary))s   some e0.walk(e0,mary)s   %s |- %s: %s(   t   resolution_testt   LogicParsert   parseR   R3   (   t   p1t   p2t   ct   p(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   testResolutionProver^  s2    













**c         C   s7   t  ƒ  i |  ƒ } t ƒ  i | ƒ } d | | f GHd  S(   Ns	   |- %s: %s(   R§   R¨   R   R3   (   R   t   ft   t(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyR¦   |  s    c          C   sa  t  ƒ  }  t |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d	 ƒ ƒ GHt |  i d
 ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHt |  i d ƒ ƒ GHd  S(   Ns   P(x) | Q(x)s   (P(x) & Q(x)) | R(x)s   P(x) | (Q(x) & R(x))s   (P(x) & Q(x)) | (R(x) & S(x))s   P(x) | Q(x) | R(x)s   P(x) | (Q(x) & R(x)) | S(x)s   exists x.P(x) | Q(x)s   -(-P(x) & Q(x))s   P(x) <-> Q(x)s   -(P(x) <-> Q(x))s   -(all x.P(x))s   -(some x.P(x))s   some x.P(x)s   some x.all y.P(x,y)s   all y.some x.P(x,y)s   all z.all y.some x.P(x,y,z)s1   all x.(all y.P(x,y) -> -all y.(Q(x,y) -> R(x,y)))(   R§   R   R¨   (   t   lp(    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   test_clausify  s$    	c          C   s=   t  ƒ  Ht ƒ  Ht ƒ  i d ƒ }  t |  |  g ƒ i ƒ  GHd  S(   Ns   man(x)(   R±   R­   R§   R¨   R   R3   (   R¬   (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pyt   demo›  s    t   __main__N("   t   nltk.compatR    t   nltk.sem.logict   nltk.sem.utilR   t   apiR   R   R¡   R   R   R   R   RO   RU   R{   R
   R|   RV   Rc   R   R‰   t   objectRR   Rˆ   Rž   R}   R£   RT   R­   R¦   R±   R²   R   (    (    (    s/   /p/zhu/06/nlp/nltk/nltk/inference/resolution.pys   <module>	   s4   
C?—		+					\						