
`]c           @  s  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 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 m Z m Z m Z m  Z  m! Z! m" Z" m# Z# m$ Z$ m% Z% y: d  d l& m' Z' m( Z( d  d	 l) m* Z* d  d
 l+ m, Z, Wn e- k
 rOn Xd e f d     YZ. d e f d     YZ/ d e0 f d     YZ1 e d e1 e f d     Y Z2 d   Z3 d e1 e f d     YZ4 d e4 e f d     YZ5 d e4 e f d     YZ6 d e5 e f d     YZ7 d e4 e f d     YZ8 e d e1 e f d     Y Z9 d  e1 e f d!     YZ: d" e1 e f d#     YZ; d$ e1 e f d%     YZ< d& e< e f d'     YZ= d( e= e  f d)     YZ> d* e< e f d+     YZ? e d, e= f d-     Y Z@ d. e1 e f d/     YZA d0   ZB e d1 eC e1 e f d2     Y ZD d3 eE f d4     YZF g  d5  ZG d6 e0 f d7     YZH d8   ZI d9   ZJ eK d: k reI   n  d S(;   i(   t   print_functiont   unicode_literalsN(   t   reduce(   t   chain(   t   string_types(   t   python_2_unicode_compatible(   t   APPt   AbstractVariableExpressiont   AllExpressiont   AndExpressiont   ApplicationExpressiont   BinaryExpressiont   BooleanExpressiont   ConstantExpressiont   EqualityExpressiont   EventVariableExpressiont   ExistsExpressiont
   Expressiont   FunctionVariableExpressiont   ImpExpressiont   IndividualVariableExpressiont   LambdaExpressiont   Tokenst   LogicParsert   NegatedExpressiont   OrExpressiont   Variablet   is_eventvart
   is_funcvart	   is_indvart   unique_variable(   t   Canvast   Tk(   t   Font(   t   in_idlet	   DrtTokensc           B  s_   e  Z d  Z d Z d Z d Z d Z d Z e e e e g Z e	 j
 e Z
 e	 j e g e Z RS(   u   DRSu   +u   PROu   [u   ]u   :(   t   __name__t
   __module__t   DRSt   DRS_CONCt   PRONOUNt   OPEN_BRACKETt   CLOSE_BRACKETt   COLONt   PUNCTR   t   SYMBOLSt   TOKENS(    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR#   8   s   t	   DrtParserc           B  s   e  Z d  Z d   Z d   Z d   Z 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(   u$   A lambda calculus expression parser.c         C  s   t  j |   t g  t j D] } | d f ^ q g  t j D] } | d f ^ q9 t d f g g  t j t j	 D] } | d f ^ qm t j
 d f g t j d f g g  t j D] } | d f ^ q g  t j D] } | d f ^ q d
 g  |  _ d  S(   Ni   i   i   i   i   i   i   i   i	   (   Ni	   (   R   t   __init__t   dictR#   t   LAMBDA_LISTt   NOT_LISTR   t   EQ_LISTR   t   NEQ_LISTR+   R'   t   OR_LISTt   IMP_LISTt   Nonet   operator_precedence(   t   selft   x(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR0   J   s    	c         C  s   t  j S(   u#   This method exists to be overridden(   R#   R-   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   get_all_symbolsY   s    c         C  s   | t  j k S(   N(   R#   R.   (   R:   t   tok(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt
   isvariable]   s    c         C  s)  | t  j k r |  j | |  S| t  j k r> |  j | |  S| t  j k r |  j d  r |  j d  t  j k r |  j	 | |  S|  j
 | |  Sn | j   t  j k r |  j t  j  |  j	 | |  S|  j |  r%|  j d  r|  j d  t  j k r|  j | |  S|  j | |  Sn  d S(   ug   This method is intended to be overridden for logics that
        use different operators or expressionsi    N(   R#   R3   t   handle_negationR2   t   handle_lambdat   OPENt   inRanget   tokenR)   t
   handle_DRSt   handle_opent   upperR&   t   assertNextTokenR>   R+   t   handle_propt   handle_variable(   R:   R=   t   context(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   handle`   s    ''c         C  s
   t  |  S(   N(   t   DrtNegatedExpression(   R:   t
   expression(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   make_NegatedExpressiony   s    c         C  so   |  j    } |  j d  r@ |  j d  t j k r@ |  j   n  |  j |  } |  j t j  t | | d   S(   Ni    (
   t   handle_refsRB   RC   R#   t   COMMAt   handle_condsRG   t   CLOSER&   R8   (   R:   R=   RJ   t   refst   conds(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRD   |   s    'c         C  s   |  j  t j  g  } xl |  j d  r |  j d  t j k r | rk |  j d  t j k rk |  j   n  | j |  j d   q W|  j  t j  | S(   Ni    u
   quantified(	   RG   R#   R)   RB   RC   R*   RP   t   appendt   get_next_token_variable(   R:   RS   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRO      s    *c         C  s   |  j  t j  g  } xl |  j d  r |  j d  t j k r | rk |  j d  t j k rk |  j   n  | j |  j |   q W|  j  t j  | S(   Ni    (	   RG   R#   R)   RB   RC   R*   RP   RU   t   process_next_expression(   R:   RJ   RT   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRQ      s    *c         C  s;   |  j  |  } |  j d  |  j t j  } t | |  S(   Nu   :(   t   make_VariableExpressionRG   RW   R#   R+   t   DrtProposition(   R:   R=   RJ   t   variablet   drs(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRH      s    c         C  s   t  | |  S(   ul   This method serves as a hook for other logic parsers that
        have different equality expression classes(   t   DrtEqualityExpression(   R:   t   firstt   second(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   make_EqualityExpression   s    c         C  sM   | t  j k r d   S| t  j k r) t S| t  j k rE d   } | Sd Sd S(   ub   This method serves as a hook for other logic parsers that
        have different boolean operatorsc         S  s   t  |  | d   S(   N(   t   DrtConcatenationR8   (   R]   R^   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   <lambda>   t    c         S  sZ   t  |  t  r% t |  j |  j |  St  |  t  rJ t |  j |  j |  St d   d  S(   Nu'   Antecedent of implication must be a DRS(   t
   isinstanceR&   RS   RT   R`   R]   R^   t	   Exception(   R]   R^   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   make_imp_expression   s
    N(   R#   R'   R6   t   DrtOrExpressionR7   R8   (   R:   R=   Re   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   get_BooleanExpression_factory   s    	c         C  s   | | |  S(   N(    (   R:   t   factoryR]   R^   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   make_BooleanExpression   s    c         C  s   t  | |  S(   N(   t   DrtApplicationExpression(   R:   t   functiont   argument(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   make_ApplicationExpression   s    c         C  s   t  t |   S(   N(   t   DrtVariableExpressionR   (   R:   t   name(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRX      s    c         C  s   t  | |  S(   N(   t   DrtLambdaExpression(   R:   t	   variablest   term(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   make_LambdaExpression   s    (   R$   R%   t   __doc__R0   R<   R>   RK   RN   RD   RO   RQ   RH   R_   Rg   Ri   Rm   RX   Rs   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR/   G   s    														t   DrtExpressionc           B  s   e  Z d  Z e   Z e d    Z d   Z d   Z d   Z	 d   Z
 d   Z d d  Z e d    Z d d	  Z d
   Z e d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   u_   
    This is the base abstract DRT Expression from which every DRT
    Expression extends.
    c         C  s   |  j  j |  S(   N(   t   _drt_parsert   parse(   t   clst   s(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt
   fromstring   s    c         C  s   t  |  |  S(   N(   Rj   (   R:   t   other(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   applyto   s    c         C  s
   t  |   S(   N(   RL   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __neg__   s    c         C  s   t     d  S(   N(   t   NotImplementedError(   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __and__   s    c         C  s"   t  | t  s t  t |  |  S(   N(   Rc   Ru   t   AssertionErrorRf   (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __or__   s    c         C  so   t  | t  s t  t  |  t  r: t |  j |  j |  St  |  t  r_ t |  j |  j |  St	 d   d  S(   Nu'   Antecedent of implication must be a DRS(
   Rc   Ru   R   R&   RS   RT   R`   R]   R^   Rd   (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __gt__   s    c         C  sI   t  | t  s t  |  j   j   } | j   j   } | j | |  S(   u<  
        Check for logical equivalence.
        Pass the expression (self <-> other) to the theorem prover.
        If the prover says it is valid, then the self and other are equal.

        :param other: an ``DrtExpression`` to check equality against
        :param prover: a ``nltk.inference.api.Prover``
        (   Rc   Ru   R   t   simplifyt   folt   equiv(   R:   R{   t   provert   f1t   f2(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR      s    	c         C  s   t  d |  j j   d  S(   Nu#   '%s' object has no attribute 'type'(   t   AttributeErrort	   __class__R$   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   type   s    c         C  s   t     d  S(   N(   R~   (   R:   t	   signature(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt	   typecheck   s    c         C  s   t  |  | d   S(   N(   R`   R8   (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __add__  s    c         C  s   t     d S(   u   
        Return the set of discourse referents in this DRS.
        :param recursive: bool Also find discourse referents in subterms?
        :return: list of ``Variable`` objects
        N(   R~   (   R:   t	   recursive(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   get_refs  s    c         C  sI   t  |  t  oH t  |  j t  oH |  j j j t j k oH t  |  j t	  S(   u    Is self of the form "PRO(x)"? (
   Rc   Rj   Rk   t   DrtAbstractVariableExpressionRZ   Ro   R#   R(   Rl   t   DrtIndividualVariableExpression(   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   is_pronoun_function  s    c         C  s   t  | |  S(   N(   R\   (   R:   R]   R^   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR_     s    c         C  s
   t  |  S(   N(   Rn   (   R:   RZ   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRX     s    c         C  s
   t  |   S(   N(   t   resolve_anaphora(   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   |  j  d   |  j  S(   Nc         S  s
   |  j    S(   N(   t   eliminate_equality(   t   e(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRa      Rb   (   t   visit_structuredR   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   d j  |  j    S(   uG   
        Draw the DRS
        :return: the pretty print string
        u   
(   t   joint   _pretty(   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   pretty_format"  s    c         C  s   t  |  j    d  S(   N(   t   printR   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   pretty_print)  s    c         C  s   t  |   j   d  S(   N(   t	   DrsDrawert   draw(   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   ,  s    N(   R$   R%   Rt   R/   Rv   t   classmethodRz   R|   R}   R   R   R   R8   R   t   propertyR   R   R   t   FalseR   R   R_   RX   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRu      s*   															R&   c           B  s   e  Z d  Z d d  Z e e d  Z d   Z e d  Z	 d   Z
 d   Z d   Z d   Z d	   Z d
   Z d   Z d   Z e j Z d   Z RS(   u%   A Discourse Representation Structure.c         C  s   | |  _  | |  _ | |  _ d S(   u   
        :param refs: list of ``DrtIndividualVariableExpression`` for the
        discourse referents
        :param conds: list of ``Expression`` for the conditions
        N(   RS   RT   t
   consequent(   R:   RS   RT   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR0   4  s    		c      
   C  s  | |  j  k r | s |  S|  j  j |  } |  j rR |  j j | | t |  } n d } t |  j  |  | j g |  j  | d g  |  j D] } | j | | t |  ^ q |  SnC| rx t	 |  j   | j
   @D] } t |  }	 t |	  }
 |  j  j |  } |  j r*|  j j | |
 t |  } n d } t |  j  |  |	 g |  j  | d g  |  j D] } | j | |
 t |  ^ q]|  }  q Wn  |  j r|  j j | | | |  } n d } t |  j  g  |  j D] } | j | | | |  ^ q|  Sd S(   u_   Replace all instances of variable v with expression E in self,
        where v is free in self.i   N(   RS   t   indexR   t   replacet   TrueR8   R&   RZ   RT   t   sett   freeR   Rn   (   R:   RZ   RM   t   replace_boundt   alpha_convertt   iR   t   condt   reft   newvart   newvarex(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   >  sH    		#(
 		 (		(c         C  sg   t  t j g  |  j D] } | j   ^ q t    } |  j rV | j |  j j    n  | t |  j  S(   u   :see: Expression.free()(	   R   t   operatort   or_RT   R   R   R   t   updateRS   (   R:   t   ct
   conds_free(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   |  s    4	c         C  s`   | rU |  j  t t d   |  j D    } |  j rQ | j |  j j t   n  | S|  j  Sd S(   u#   :see: AbstractExpression.get_refs()c         s  s   |  ] } | j  t  Vq d  S(   N(   R   R   (   t   .0R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pys	   <genexpr>  s    N(   RS   t   listR   RT   R   t   extendR   R   (   R:   R   t
   conds_refs(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    		c         C  sD   t  t | |  j   } |  j r: | j | |  j   n  | |  S(   u   :see: Expression.visit()(   R   t   mapRT   R   RU   (   R:   Rk   t
   combinatort   parts(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   visit  s    	c         C  sC   |  j  r | |  j   n d } | |  j t t | |  j   |  S(   u#   :see: Expression.visit_structured()N(   R   R8   RS   R   R   RT   (   R:   Rk   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s  |  } d } x | t  | j  k  r| j | } t | t  r t | j t  r t | j t  r t t t	 | j
  t	 | j j g   | j |  | j | d | j  } | j j | j j k r | j | j j | j t t  } d } n  | d 8} n  | d 7} q Wg  } xd | j D]Y } | j   } | j   } t | t  sg| j
 sg| j sg| j r| j |  qqW| j r| j j   n d  } t | j
 | |  S(   Ni    i   (   t   lenRT   Rc   R   R]   R   R^   R&   R   R   RS   RZ   R   R   R   R   R   RU   R8   (   R:   R[   R   R   RT   t   new_condt   new_cond_simpR   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s6    %!				c         C  s7  |  j  r d  } |  j rF t t g  |  j D] } | j   ^ q(  } n  | rg t | |  j  j    } n |  j  j   } x- |  j d  d  d  D] } t | |  } q W| S|  j s t	 d   n  t t g  |  j D] } | j   ^ q  } x? t
 t |  j |  j  d  d  d   D] } t | |  } qW| Sd  S(   Niu-   Cannot convert DRS with no conditions to FOL.(   R   R8   RT   R   R	   R   R   RS   R   Rd   R   R   t   _order_ref_stringsR   (   R:   t   accumR   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s     		.	+/c         C  s0  d j  |  j |  j   } g  g  |  j D] } t d   | j    ^ q( D] } | D] } | ^ qT qJ } t t |  g t t	 t |    } d d | d d | j
 |  d d d	 | d
 g g  | D] } d | j
 |  d ^ q d d | d g } |  j r,t j | t j |  j j    S| S(   Nu    c         S  s
   |  j    S(   N(   t   strip(   Ry   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRa     Rb   u    _u   _u   _ u   | u    |u   |-u   -u   -|u   |_u   _|(   R   R   RS   RT   t   filterR   t   maxR   R   R   t   ljustR   t   DrtBinaryExpressiont   _assemble_prettyR#   t   IMP(   R:   t	   refs_lineR   t	   cond_linet
   cond_linest   lengtht   lineR[   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    2(s	c   	      C  s   g  | D] } d | ^ q } g  } g  } g  } g  } xo | D]g } t  |  r^ | j |  q< t |  rz | j |  q< t |  r | j |  q< | j |  q< Wt |  t | d d   t | d d   t | d d   S(   Nu   %st   keyc         S  s(   t  |  d d g t |  d  d k  S(   Ni   ii    (   t   intR   (   t   v(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRa     Rb   c         S  s2   |  d t  |  d d g t |  d  d k  f S(   Ni    i   i(   R   R   (   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRa     Rb   c         S  s2   |  d t  |  d d g t |  d  d k  f S(   Ni    i   i(   R   R   (   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRa     Rb   (   R   RU   R   R   t   sorted(	   R:   RS   R   t   stringst   ind_varst	   func_varst
   event_varst
   other_varsRy   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   t  | t  r t |  j  t | j  k r | } xG t |  j | j  D]0 \ } } |  j |  } | j | | t  } qI W|  j | j k r t |  j	  t | j	  k r x3 t |  j	 | j	  D] \ } } | | k s t
 Sq Wt Sq n  t
 S(   u}   Defines equality modulo alphabetic variance.
        If we are comparing \x.M  and \y.N, then check equality of M and N[x/y].(   Rc   R&   R   RS   t   zipRX   R   R   R   RT   R   (   R:   R{   t   converted_othert   r1t   r2t   varext   c1t   c2(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __eq__  s    "	"
c         C  s   |  | k S(   N(    (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __ne__  s    c         C  st   d d j  |  j |  j   d j  d   |  j D  f } |  j rp t j | d t j d d |  j t j S| S(   Nu   ([%s],[%s])u   ,u   , c         s  s   |  ] } d  | Vq d S(   u   %sN(    (   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pys	   <genexpr>!  s    u    u   %s(	   R   R   RS   RT   R   R#   RA   R   RR   (   R:   R[   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   __str__  s     	,N(   R$   R%   Rt   R8   R0   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   __hash__R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR&   0  s   
>				$						c         C  sY   t  |  j  r t |   St |  j  r2 t |   St |  j  rK t |   St |   Sd S(   u   
    This is a factory method that instantiates and returns a subtype of
    ``DrtAbstractVariableExpression`` appropriate for the given variable.
    N(   R   Ro   R   R   t   DrtFunctionVariableExpressionR   t   DrtEventVariableExpressiont   DrtConstantExpression(   RZ   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRn   0  s    


R   c           B  s/   e  Z d    Z e d  Z d   Z d   Z RS(   c         C  s   |  S(   N(    (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   @  s    c         C  s   g  S(   u#   :see: AbstractExpression.get_refs()(    (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   C  s    c         C  s*   d |  } d t  |  } | | | | g S(   Nu   %su    (   R   (   R:   Ry   t   blank(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   G  s    
c         C  s   |  S(   N(    (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   L  s    (   R$   R%   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   ?  s   		R   c           B  s   e  Z RS(    (   R$   R%   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   P  s   R   c           B  s   e  Z RS(    (   R$   R%   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   V  s   R   c           B  s   e  Z RS(    (   R$   R%   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   \  s   R   c           B  s   e  Z RS(    (   R$   R%   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   b  s   RY   c           B  s}   e  Z d    Z e e d  Z d   Z e d  Z d   Z d   Z	 e
 j Z d   Z d   Z d   Z d	   Z d
   Z RS(   c         C  s   | |  _  | |  _ d  S(   N(   RZ   R[   (   R:   RZ   R[   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR0   h  s    	c         C  sx   |  j  | k rO t | t  s* t d   t | j  |  j j | | | |   St |  j  |  j j | | | |   Sd  S(   Nu4   Can only replace a proposition label with a variable(   RZ   Rc   R   R   RY   R[   R   (   R:   RZ   RM   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   l  s    	c         C  s   t  |  j |  j j    S(   N(   RY   RZ   R[   R   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   {  s    c         C  s   | r |  j  j t  Sg  S(   N(   R[   R   R   (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   ~  s    c         C  s4   |  j  | j  k o3 |  j | j k o3 |  j | j k S(   N(   R   RZ   R[   (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   |  | k S(   N(    (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   |  j  j   S(   N(   R[   R   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   |  j  j   } d t d |  j  } g  | d  D] } | d | ^ q1 g  | d d !D] } d |  j d | ^ qV g  | d D] } | d | ^ q S(   Nu    u   %si   i   u   :(   R[   R   R   RZ   (   R:   t   drs_sR   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   | | |  j   g  S(   u   :see: Expression.visit()(   R[   (   R:   Rk   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   | |  j  | |  j   S(   u#   :see: Expression.visit_structured()(   RZ   R[   (   R:   Rk   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   d |  j  |  j f S(   Nu   prop(%s, %s)(   RZ   R[   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    (   R$   R%   R0   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRY   f  s   										RL   c           B  s&   e  Z d    Z e d  Z d   Z RS(   c         C  s   t  |  j j    S(   N(   R   Rr   R   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   |  j  j |  S(   u#   :see: AbstractExpression.get_refs()(   Rr   R   (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   |  j  j   } g  | d  D] } d | ^ q g  | d d !D] } d | ^ q; g  | d d !D] } d | ^ q] g  | d D] } d | ^ q| S(   Ni   u       i   u   __  i   u     | (   Rr   R   (   R:   t
   term_linesR   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    (   R$   R%   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRL     s   	Rp   c           B  s#   e  Z d    Z d   Z d   Z RS(   c         C  s+   |  j  | |  j j |  j t |  t   S(   u   Rename all occurrences of the variable introduced by this variable
        binder in the expression to ``newvar``.
        :param newvar: ``Variable``, for the new variable
        (   R   Rr   R   RZ   Rn   R   (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s   t  |  j |  j j    S(   N(   R   RZ   Rr   R   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s  |  j  g } |  j } x/ | j |  j k rF | j | j   | j } q Wd j d   | D  t j } | j   } d t |  } g  | d  D] } d | | ^ q g  | d d !D] } d | | ^ q g  | d d !D] } d | | ^ q g  | d D] } d | | ^ q S(	   Nu    c         s  s   |  ] } d  | Vq d S(   u   %sN(    (   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pys	   <genexpr>  s    i   u       i   u    \  i   u    /\ (	   RZ   Rr   R   RU   R   R#   t   DOTR   R   (   R:   Rq   Rr   t
   var_stringR   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    	 (   R$   R%   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRp     s   	
	R   c           B  s5   e  Z e d   Z d   Z e d    Z d   Z RS(   c         C  s*   | r& |  j  j t  |  j j t  Sg  S(   u#   :see: AbstractExpression.get_refs()(   R]   R   R   R^   (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s1   t  j |  j |  j  |  j   |  j |  j   S(   N(   R   R   t   _pretty_subexR]   t   getOpR^   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    	c         C  s  t  t |   t |   } t |  |  }  t | |  } d t |  } t t |  |   } g  | d  D]* \ } } d | d | d | d ^ qi g  | d d !D]* \ } } d | d | d | d ^ q g  | d D]* \ } } d | d | d | d ^ q S(   Nu    i   i   u   (u   )(   R   R   t   _pad_verticallyR   R   (   t   first_linest   opt   second_linest	   max_linesR   t   first_second_linest
   first_linet   second_line(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    
tc         C  s
   | j    S(   N(   R   (   R:   t   subex(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    (   R$   R%   R   R   R   t   staticmethodR   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s   	t   DrtBooleanExpressionc           B  s   e  Z RS(    (   R$   R%   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s   Rf   c           B  s   e  Z d    Z d   Z RS(   c         C  s   t  |  j j   |  j j    S(   N(   R   R]   R   R^   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  sC   t  | t  r3 g  | j   D] } | d d !^ q St j |  |  S(   Ni   i(   Rc   Rf   R   R   R   (   R:   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    $(   R$   R%   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRf     s   	R\   c           B  s   e  Z d    Z RS(   c         C  s   t  |  j j   |  j j    S(   N(   R   R]   R   R^   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    (   R$   R%   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR\     s   R`   c           B  s   e  Z d  Z d d  Z e e d  Z d   Z d   Z	 e d  Z
 d   Z d   Z d   Z e j Z d	   Z d
   Z d   Z d   Z d   Z d   Z RS(   u   DRS of the form '(DRS + DRS)'c         C  s    t  j |  | |  | |  _ d  S(   N(   R   R0   R   (   R:   R]   R^   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR0     s    c   
      C  s  |  j  } |  j } |  j } | |  j   k r | rq| j | | | |  } | j | | | |  } | r | j | | | |  } q qqn | r x t |  j t   | j   @D]i } t t	 |   }	 | j | |	 t |  } | j | |	 t |  } | r | j | |	 t |  } q q Wn  | j | | | |  } | j | | | |  } | rq| j | | | |  } n  |  j
 | | |  S(   u_   Replace all instances of variable v with expression E in self,
        where v is free in self.(   R]   R^   R   R   R   R   R   R   Rn   R   R   (
   R:   RZ   RM   R   R   R]   R^   R   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s2    			&"c         C  s,   |  j    } t | t  s" t  | j   S(   N(   R   Rc   R`   R   R   (   R:   R[   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   @  s    c         C  s   |  j  j   } |  j j   } |  j r6 |  j j   n d  } t | t  r t | t  r xW t | j t	   t | j t	   @D]- } t
 t |   } | j | | t	  } q Wt | j | j | j | j |  S|  j | | |  Sd  S(   N(   R]   R   R^   R   R8   Rc   R&   R   R   R   Rn   R   R   RS   RT   R   (   R:   R]   R^   R   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   F  s    /$c         C  sQ   |  j  j |  |  j j |  } |  j rM | rM | j |  j j t   n  | S(   u#   :see: AbstractExpression.get_refs()(   R]   R   R^   R   R   R   (   R:   R   RS   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   V  s    "c         C  s   t  j S(   N(   R#   R'   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   ]  s    c         C  s   t  | t  r |  j   } | j   } t |  t |  k r | } xA t | |  D]0 \ } } |  j |  } | j | | t  } qU W|  j | j k o |  j	 | j	 k o |  j
 | j
 k Sn  t S(   u}   Defines equality modulo alphabetic variance.
        If we are comparing \x.M  and \y.N, then check equality of M and N[x/y].(   Rc   R`   R   R   R   RX   R   R   R]   R^   R   R   (   R:   R{   t	   self_refst
   other_refsR   R   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   `  s    c         C  s   |  | k S(   N(    (   R:   R{   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   r  s    c         C  sI   t  |  j j   |  j j    } |  j rE t | |  j j    } n  | S(   N(   R	   R]   R   R^   R   R   (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   w  s    !	c         C  sg   t  j |  j |  j  |  j   |  j |  j   } |  j rc t  j | t j |  j	 |  j   } n  | S(   N(
   R   R   R   R]   R   R^   R   R#   R   R   (   R:   R[   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   }  s    		!c         C  sC   t  | t  r3 g  | j   D] } | d d !^ q St j |  |  S(   Ni   i(   Rc   R`   R   R   R   (   R:   R   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    $c         C  s]   |  j  r7 | | |  j  | |  j  | |  j   g  S| | |  j  | |  j  g  Sd S(   u   :see: Expression.visit()N(   R   R]   R^   (   R:   Rk   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    	+c         C  s   |  j  |  j  } |  j  |  j  } t j | d |  j   d | t j } |  j r t j | d t j	 d d |  j t j S| S(   Nu    u   %s(
   t
   _str_subexR]   R^   R   RA   R   RR   R   R#   R   (   R:   R]   R^   R[   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    *	,c         C  s7   d | } t  | t  r3 | j d  k r3 | d d !S| S(   Nu   %si   i(   Rc   R`   R   R8   (   R:   R   Ry   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    
N(   R$   R%   Rt   R8   R0   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR`     s    '												Rj   c           B  s&   e  Z d    Z e d  Z d   Z RS(   c         C  s   t  |  j j   |  j j    S(   N(   R
   Rk   R   Rl   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  s*   | r& |  j  j t  |  j j t  Sg  S(   u#   :see: AbstractExpression.get_refs()(   Rk   R   R   Rl   (   R:   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    &c         C  sP  |  j    \ } } | j   } g  | D] } | j   ^ q% } t t t | g |   } t | |  } g  | D] } t | |  ^ qo } t t | t t |      } g  | d  D]' \ }	 }
 |	 d d j |
  d ^ q g  | d d !D]' \ }	 }
 |	 d d j |
  d ^ q g  | d D]' \ }	 }
 |	 d d j |
  d ^ q$S(   Ni   u    i   u   (u   ,u   )(	   t   uncurryR   R   R   R   R   R   R   R   (   R:   Rk   t   argst   function_linest   argt
   args_linesR   t	   arg_linest   func_args_linest	   func_linet	   args_line(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    "!
n(   R$   R%   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyRj     s   	c         C  s-   d t  |  d  g } |  | | t  |   S(   Nu    i    (   R   (   t   linesR   t   pad_line(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    t   PossibleAntecedentsc           B  s2   e  Z d    Z e e d  Z d   Z d   Z RS(   c         C  s
   t  |   S(   u   Set of free variables.(   R   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    c         C  sG   t    } x7 |  D]/ } | | k r2 |  j |  q |  j |  q W| S(   u_   Replace all instances of variable v with expression E in self,
        where v is free in self.(   R  RU   (   R:   RZ   RM   R   R   t   resultt   item(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    	c         C  s'   d |  } d t  |  } | | | g S(   Nu   %su    (   R   (   R:   Ry   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    
c         C  s   d d j  d   |  D  d S(   Nu   [u   ,c         s  s   |  ] } d  | Vq d S(   u   %sN(    (   R   t   it(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pys	   <genexpr>  s    u   ](   R   (   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     s    (   R$   R%   R   R   R   R   R   R   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR    s   		t   AnaphoraResolutionExceptionc           B  s   e  Z RS(    (   R$   R%   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR    s   c         C  sF  t  |  t  r|  j   r t   } xi | D]a } xX | j   D]J } |  j |  } | j |  j j k r> | |  j k r> | j |  q> q> Wq+ Wt	 |  d k r | d } n | } |  j
 |  j |  St |  j | |  g  } t |  j | |  g  } |  j | |  Sn5t  |  t  rg  }	 x |  j D] }
 t |
 | |  g  } t  | t  rt  | j t  r| j } | j | _ | | _ n  t  | j t  r| j st d | j   qqn  |	 j |  q,W|  j rt |  j | |  g  } n d  } |  j |  j |	 |  St  |  t  r&|  St  |  t  rU|  j t |  j | |  g   St  |  t  r|  j rt |  j | |  g  } n d  } |  j t |  j | |  g  t |  j | |  g  |  St  |  t  r|  j t |  j | |  g  t |  j | |  g   St  |  t  rB|  j |  j t |  j | |  g   Sd  S(   Ni   i    u+   Variable '%s' does not resolve to anything.(   Rc   R
   R   R  R   RX   R   Rl   RU   R   R_   R   Rk   R&   RT   R   R]   R^   R  R   R8   RS   R   R   Rr   R`   R   R   RZ   (   RM   t   trailt   possible_antecedentst   ancestorR   t   refext
   resolutiont
   r_functiont
   r_argumentt   r_condsR   t   r_condt   tempR   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR     sn    					R   c           B  s   e  Z d  Z d Z d Z e d d  Z d   Z e e d  Z	 d   Z
 d   Z d   Z d	 d	 d
  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   i   i
   i   c   
      C  s  d } | s t   } | j d  t d d d d  } | r t | d d d d } | | _ | |  _ |  j | |  j |  j	  \ } } t
 | |  j d	  } | |  j }	 t | d | d |	 } n t | d d
 d d
 } | j   | | _ n  | |  _ | |  _ | |  _ d S(   u  
        :param drs: ``DrtExpression``, The DRS to be drawn
        :param size_canvas: bool, True if the canvas size should be the exact size of the DRS
        :param canvas: ``Canvas`` The canvas on which to draw the DRS.  If none is given, create a new canvas.
        u   DRTt   familyu	   helveticat   sizei   t   widthi    t   heightid   i,  N(   R8   R    t   titleR!   R   t   fontt   canvast   _visitt
   OUTERSPACEt   TOPSPACER   t   packR[   t   master(
   R:   R[   t   size_canvasR  R  R  t   rightt   bottomR  R  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR0   M  s&    			!
		c         C  s   |  j  j j d  S(   u    Get the height of a line of textu	   linespace(   R  R  t   metrics(   R:   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   _get_text_heightm  s    c         C  sY   |  j  |  j |  j | |  |  j r? t   r? |  j j   n |  j |  j | |  Sd S(   u   Draw the DRSN(   t   _handleR[   t   _draw_commandR  R"   t   mainloopR  (   R:   R;   t   y(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   q  s    c         C  s   |  j  | |  j | |  S(   u!  
        Return the bottom-rightmost point without actually drawing the item

        :param expression: the item to visit
        :param x: the top of the current drawing area
        :param y: the left side of the current drawing area
        :return: the bottom-rightmost point
        (   R$  t   _visit_command(   R:   RM   R;   R'  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR  z  s    	c      	   C  s   t  | t  r= |  j j | | d d d |  j j d | nk t  | t  r | \ } } |  j j | | | |  | |  j   |  j d } |  j j	 | | | |  n  |  j
 | | |  S(   u   
        Draw the given item at the given location

        :param item: the item to draw
        :param x: the top of the current drawing area
        :param y: the left side of the current drawing area
        :return: the bottom-rightmost point
        t   anchoru   nwR  t   texti   (   Rc   R   R  t   create_textR  t   tuplet   create_rectangleR#  t   BUFFERt   create_lineR(  (   R:   R  R;   R'  R   R!  t   horiz_line_y(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR%    s    	.c         C  sM   t  | t  r6 | |  j j j |  | |  j   f St  | t  rI | Sd S(   u  
        Return the bottom-rightmost point without actually drawing the item

        :param item: the item to visit
        :param x: the top of the current drawing area
        :param y: the left side of the current drawing area
        :return: the bottom-rightmost point
        N(   Rc   R   R  R  t   measureR#  R,  (   R:   R  R;   R'  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR(    s    	'i    c         C  sw  | |  j  k rN y( | j | } | j | } | | f SWqN t k
 rJ qN Xn  t | t  ri |  j } n t | t  r |  j } n t | t	  r |  j
 } n t | t  r |  j } n~ t | t  r |  j } nc t | t  r |  j } nH t | t  r|  j } n- t | t  r&|  j } n t | j j   | | | | |  \ } } | | | _ | | | _ | | f S(   u1  
        :param expression: the expression to handle
        :param command: the function to apply, either _draw_command or _visit_command
        :param x: the top of the current drawing area
        :param y: the left side of the current drawing area
        :return: the bottom-rightmost point
        (   R(  t   _drawing_widtht   _drawing_heightR   Rc   R   t   _handle_VariableExpressionR&   t   _handle_DRSRL   t   _handle_NegatedExpressionRp   t   _handle_LambdaExpressionR   t   _handle_BinaryExpressionRj   t   _handle_ApplicationExpressionR  RY   t   _handle_DrtPropositionRd   R   R$   (   R:   RM   t   commandR;   R'  R   R!  Rh   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR$    s8    c         C  s   | d | | |  S(   Nu   %s(    (   R:   RM   R;  R;   R'  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR4    s    c         C  ss   |  j  t j | |  d } |  j | j | | |  \ } } | t j | |  j | | | |  j     | | f S(   Ni    (   R(  R#   t   NOTR$  Rr   t   _get_centered_topR#  (   R:   RM   R;  R;   R'  R   R!  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR6    s    ! c         C  s  | |  j  } | |  j  } | j rB d j d   | j D  } n d } | | | |  \ } } | |  j  d 7} | j r xe | j D]@ }	 |  j |	 | | |  \ }
 } t | |
  } | |  j  7} q Wn | |  j   |  j  7} | |  j  7} | | | f | |  S(   Nu    c         s  s   |  ] } d  | Vq d S(   u   %sN(    (   R   t   r(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pys	   <genexpr>  s    u        i   (   R.  RS   R   RT   R$  R   R#  (   R:   RM   R;  R;   R'  t   leftR!  RS   t	   max_rightR   R   (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR5    s    		c         C  s  | j    \ } } t | t  s9 | j } | j g } n  |  j | | |  d } t | g g  | D] } |  j | | |  d ^ qb  }	 |	 | }
 |  j | |
 | j  } |  j	 | | | |  d } |  j | |
 |  j
    } | t j | |  d } x t |  D]v \ } } |  j | |
 | j  } |  j	 | | | |  d } | d t |  k  r
| t j d | |  d } q
q
W| t j | |  d } | |	 f S(   Ni   i    u    (   R   Rc   R   Rk   Rl   R  R   R=  R3  R$  R#  R#   RA   t	   enumerateR   RP   RR   (   R:   RM   R;  R;   R'  Rk   R   t   function_bottomR   t
   max_bottomt   line_heightt   function_drawing_topR   t   centred_string_topR   t   arg_drawing_top(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR9    s,    	6
$c         C  s   t  j d | j t  j } |  j | | |  d } |  j | j | | |  \ } } | | | |  j | | | |  j     | | f S(   Nu   %si    (	   R#   t   LAMBDARZ   R   R(  R$  Rr   R=  R#  (   R:   RM   R;  R;   R'  Rq   R   R!  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR7  .  s    !&c         C  s?  |  j  | j d d  d } |  j  | j d d  d } t | |  } |  j | | |  j    } | t j | |  d }	 | j j } |  j	 | j | |	 |  j | | |   \ }	 }
 | d | j
   |	 |  d }	 | j j } |  j	 | j | |	 |  j | | |   \ }	 } | t j |	 |  d }	 |	 t |
 |  f S(   Ni    i   u    %s (   R  R]   R^   R   R=  R#  R#   RA   R3  R$  R   RR   (   R:   RM   R;  R;   R'  t   first_heightt   second_heightRD  RF  R   t   first_bottomt   second_bottom(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR8  =  s*     c         C  sD   | | j  | |  d } |  j | j | | |  \ } } | | f S(   Ni    (   RZ   R$  Rr   (   R:   RM   R;  R;   R'  R   R!  (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR:  c  s    !c         C  s   | | | d S(   u   Get the y-coordinate of the point that a figure should start at if
        its height is 'item_height' and it needs to be centered in an area that
        starts at 'top' and is 'full_height' tall.i   (    (   R:   t   topt   full_heightt   item_height(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR=  l  s    N(   R$   R%   R.  R  R  R   R8   R0   R#  R   R  R%  R(  R$  R4  R6  R5  R9  R7  R8  R:  R=  (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyR   H  s$    					.				+		&		c          C  s  t  d d d  t j }  t  |  d   t  |  d   t  |  d   t  |  d   t  |  d   t  |  d	   t  |  d
   t  |  d   t  |  d   t  d d d  t  |  d  j    t  d d d   |  d  } t  |  | j t d   } t  |  t  | | k  t  d! d d"  t  t |  d    t  t |  d    t  t |  d    t  d# d d$  |  d  j   |  d  j   |  d  j   |  d  j   |  d  j   d  S(%   Nu   =i   u
   TEST PARSEu   ([x,y],[sees(x,y)])u   ([x],[man(x), walks(x)])u   \x.\y.([],[sees(x,y)])u   \x.([],[walks(x)])(john)u$   (([x],[walks(x)]) + ([y],[runs(y)]))u#   (([],[walks(x)]) -> ([],[runs(x)]))u   ([x],[PRO(x), sees(John,x)])u    ([x],[man(x), -([],[walks(x)])])u*   ([],[(([x],[man(x)]) -> ([],[walks(x)]))])u
   Test fol()u4   Test alpha conversion and lambda expression equalityu   \x.([],[P(x)])u   zu   Test resolve_anaphora()u,   ([x,y,z],[dog(x), cat(y), walks(z), PRO(z)])u3   ([],[(([x],[dog(x)]) -> ([y],[walks(y), PRO(y)]))])u   (([x,y],[]) + ([],[PRO(x)]))u   Test pretty_print()u   ([],[])u@   ([],[([x],[big(x), dog(x)]) -> ([],[bark(x)]) -([x],[walk(x)])])u'   ([x,y],[x=y]) + ([z],[dog(z), walk(z)])u4   ([],[([x],[]) | ([y],[]) | ([z],[dog(z), walk(z)])])u0   \P.\Q.(([x],[]) + P(x) + Q(x))(\x.([],[dog(x)]))u   ====================u   ====================u   ====================u   ====================u   ====================u   ====================u   ====================u   ====================u   ====================u   ====================(   R   Ru   Rz   R   R   R   R   R   (   t   dexprt   e1t   e2(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   demos  s>    	

c          C  s   y d d l  m }  Wn- t k
 rC d d l m } | d   n Xd d d d d	 d
 d d d d d g } x' | D] } t j |  } | j   qr Wd  S(   Ni(   R    (   t   SkipTestu,   tkinter is required, but it's not available.u   xu   ([],[])u   ([x],[])u   ([x],[man(x)])u   ([x,y],[sees(x,y)])u   ([x],[man(x), walks(x)])u   \x.([],[man(x), walks(x)])u   \x y.([],[sees(x,y)])u)   ([],[(([],[walks(x)]) + ([],[runs(x)]))])u    ([x],[man(x), -([],[walks(x)])])u*   ([],[(([x],[man(x)]) -> ([],[walks(x)]))])(   t   six.moves.tkinterR    t   ImportErrort   noseRT  Ru   Rz   R   (   R    RT  t   expressionsR   t   d(    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt	   test_draw  s&    	u   __main__(L   t
   __future__R    R   R   t	   functoolsR   t	   itertoolsR   t   sixR   t   nltk.compatR   t   nltk.sem.logicR   R   R   R	   R
   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   RU  R   R    t   six.moves.tkinter_fontR!   t	   nltk.utilR"   RV  R#   R/   t   objectRu   R&   Rn   R   R   R   R   R   RY   RL   Rp   R   R   Rf   R\   R`   Rj   R   R   R  Rd   R  R   R   RS  RZ  R$   (    (    (    s+   lib/python2.7/site-packages/nltk/sem/drt.pyt   <module>   s`   g	>(
$	S ,	(	