³ò
4ÒÇIc           @   sP  d  Z  d d k Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ	 d e	 f d „  ƒ  YZ
 d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e	 f d „  ƒ  YZ d e
 f d „  ƒ  YZ d e f d „  ƒ  YZ d e e i f d „  ƒ  YZ d S(   s•   
This module performs the anaphora resolution functionality for DRT.py.  It may be 
modified or swapped out to test different resolution techniques.
iÿÿÿÿNt   AnaphoraResolutionExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR       s   t   DRSc           B   s   e  Z g  d  „ Z RS(   c         C   s‰   g  } xm |  i  D]b } | i | |  g ƒ } t | t ƒ p | i ƒ  o | i | ƒ q t d | i ƒ  ƒ ‚ q W|  i |  i	 | ƒ S(   Ns+   Variable '%s' does not resolve to anything.(
   t   condst   resolve_anaphorat
   isinstancet   EqualityExpressiont   isNullResolutiont   appendR    t   get_assigned_variablet	   __class__t   refs(   t   selft   trailt   r_condst   condt   r_cond(    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR      s    
 (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR      s   t   AbstractVariableExpressionc           B   s   e  Z g  d  „ Z RS(   c         C   s   |  S(   N(    (   R   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   %   s    (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   $   s   t   NegatedExpressionc           B   s   e  Z g  d  „ Z RS(   c         C   s    |  i  |  i i | |  g ƒ ƒ S(   N(   R   t   termR   (   R   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   )   s    (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   (   s   t   LambdaExpressionc           B   s   e  Z g  d  „ Z RS(   c         C   s&   |  i  |  i |  i i | |  g ƒ ƒ S(   N(   R   t   variableR   R   (   R   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   -   s    (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   ,   s   t   BinaryExpressionc           B   s   e  Z g  d  „ Z RS(   c         C   s6   |  i  |  i i | |  g ƒ |  i i | |  g ƒ ƒ S(   N(   R   t   firstR   t   second(   R   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   1   s    (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   0   s   t   BooleanExpressionc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   5   s   t   OrExpressionc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   8   s   t   ImpExpressionc           B   s   e  Z g  d  „ Z RS(   c         C   s?   |  |  i  g } |  i |  i  i | | ƒ |  i i | | ƒ ƒ S(   N(   R   R   R   R   (   R   R   t   trail_addition(    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   <   s    (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   ;   s   t   IffExpressionc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   A   s   R   c           B   s   e  Z d  „  Z d „  Z RS(   c         C   s9   t  |  i t ƒ o |  i p t  |  i t ƒ o |  i S(   N(   R   R   t   PossibleAntecedentsR   (   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   E   s    c         C   s)   t  |  i t ƒ o |  i Sn |  i Sd S(   sÔ   
        Since an equality expression will assign a variable to something, but
        that variable may be on either side of the equality sign, return the
        variable no matter which side it is on.
        N(   R   R   R   R   (   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR
   I   s    (   R   R   R   R
   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   D   s   	t   ConcatenationDRSc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR    T   s   t   ApplicationExpressionc           B   s   e  Z g  d  „ Z RS(   c   	      C   s	  |  i  ƒ  o¶ t ƒ  } xl | D]d } x[ | i ƒ  D]M } |  i | ƒ } | i |  i i j o" | |  i j o | i | ƒ q0 q0 Wq Wt | ƒ d j o | d } n | } |  i |  i | ƒ SnC |  i	 i
 | |  g ƒ } |  i i
 | |  g ƒ } |  i | | ƒ Sd  S(   Ni   i    (   t   is_pronoun_functionR   t   get_refst   make_VariableExpressionR   t   argumentR	   t   lent   make_EqualityExpressiont   functionR   (	   R   R   t   possible_antecedentst   ancestort   reft   refext
   resolutiont
   r_functiont
   r_argument(    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   X   s"    	  (   R   R   R   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR!   W   s   R   c           B   s;   e  Z e d  „ Z e d „ Z d „  Z e i i	 d „ Z
 RS(   c         C   s
   t  |  ƒ S(   s   Set of free variables.(   t   set(   R   t   indvar_only(    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyt   freeq   s    c         C   sI   t  ƒ  } x9 |  D]1 } | | j o |  i | ƒ q |  i | ƒ q W| S(   s_   Replace all instances of variable v with expression E in self,
        where v is free in self.(   R   R	   (   R   R   t
   expressiont   replace_boundt   resultt   item(    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyt   replaceu   s    	 c         C   s   |  S(   N(    (   R   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyt   simplify€   s    c         C   s6   d d i  g  } |  D] } | t | ƒ q ~ ƒ d S(   Nt   [t   ,t   ](   t   joint   str(   R   t   syntaxt   _[1]R6   (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR=   ƒ   s    (   R   R   t   TrueR2   t   FalseR7   R8   t   logict   Tokenst   NLTKR=   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pyR   p   s   	(   t   __doc__RB   t	   ExceptionR    t   objectR   R   R   R   R   R   R   R   R   R   R    R!   t   listt
   ExpressionR   (    (    (    s3   /p/zhu/06/nlp/nltk/nltk/sem/drt_resolve_anaphora.pys   <module>   s   