³ò
ôçAc           @   s}   d  d k  l Z d Z d Z d  d k Z d  d k Z d  d k Z d  d k Z d d d „  ƒ  YZ e	 d j o e ƒ  Z
 n d S(	   iÿÿÿÿ(   t   nested_scopess   Hugo Liu <hugo@media.mit.edu>s   2.0Nt   MontyCommonsensec           B   sA   e  Z d  Z e e d „ Z d „  Z d „  Z d „  Z d „  Z RS(   s	   CSSDB.MDFc      	      s  | p t  i  ƒ  } n | |  _ | p t i ƒ  } n | |  _ |  i i |  _ |  i i |  _ h  ‰ t i ƒ  i |  i ƒ } | p& |  i	 ƒ  t i ƒ  i |  i ƒ } n t
 | d ƒ } |  i ‰  t ‡ ‡  f d †  t d „  t d „  t i | i ƒ  ƒ i d ƒ ƒ ƒ ƒ ˆ |  _ d GHd  S(   Nt   rbc            s.   ˆ ˆ  |  d  |  d i  ƒ  |  d i  ƒ  f ƒ S(   i    i   i   (   t   split(   t   stripped(   t   ps1t   cat_p(    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyt   <lambda>   s    c         S   s   |  i  d  ƒ S(   t   |(   R   (   t   tmps(    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR      s    c         S   s   |  i  ƒ  d  j S(   t    (   t   strip(   t   tagged_cleaned(    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR      s    s   
s   Commonsense OK!(   t   MontyLemmatisert   theMontyLemmatisert   MontyTaggert   theMontyTaggert   tag_tokenizedt   lemmatise_wordt
   MontyUtilst	   find_filet   cssdb_filenamet   build_cs_selection_dbt   opent   setitemt   mapt   filtert   zlibt
   decompresst   readR   t   cssdb(   t   selft   MontyLemmatiser_handlet   MontyTagger_handlet   _montylingua_cleanedt   hash1(    (   R   R   sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyt   __init__
   s&    		
	I	c            sà  |  i  } |  i } | i ƒ  } d d d d d d g ‰  t d „  | ƒ } t t ‡  f d †  | ƒ ƒ d	 j o | Sn d
 i t d „  | ƒ ƒ } |  i | d d d d	 ƒ} | i ƒ  } t | ƒ } d	 }	 xÓt t | ƒ ƒ D]¿}
 |	 o Pn | |
 i d ƒ } | d	 } | d } xƒ| D]{} | ˆ  j oh| | d ƒ i	 ƒ  } | i
 | ƒ o!| | \ } } |
 d d	 j oR | oK | |
 d i d ƒ d	 } | | d ƒ i	 ƒ  } | | j o
 d }	 qÇn |
 d | j  o™ | o’ | |
 d i d ƒ d	 } | i	 ƒ  d j o4 |
 d | j  o | |
 d i d ƒ d	 } qAn | | d ƒ i	 ƒ  } | | j o
 d }	 qqqun |	 o | d | | |
 <Pq—qqWqÜ Wd
 i t d „  t d „  | ƒ ƒ ƒ } | | j o	 d GHn | S(   Nt   VBDt   VBGt   VBNt   VBZt   VBt   VBPc         S   s   |  i  d  ƒ d S(   t   /i   (   R   (   R   (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   '   s    c            s
   |  ˆ  j S(    (    (   R   (   t   hostnames_dict(    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   )   s    i    t    c         S   s   |  i  d  ƒ d S(   R+   i    (   R   (   R   (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   +   s    t	   all_pos_pi   t   commonsense_pR+   t   verbt   nount   thet   at   ant   somet   everyt   eacht   mosti   c         S   s   |  d  d |  d S(   i    R+   i   (    (   R   (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   W   s    c         S   s   |  i  d  ƒ S(   R+   (   R   (   R	   (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   W   s    s$   Common sense violated! Correcting...(   R2   R3   R4   R5   R6   R7   R8   (   R   R   R   R   t   lenR   t   joinR   t   ranget   lowert   has_key(   R   t   taggedt   pathnameR   t   cmp1t	   table_arrt   groupnames_cleanedt   id_pt   argsst   csplit_cleanedt   input_pt   hostnames_pt	   chmod_strt   buffer_dictt   cront
   buffer_arrt   resst   line_pt   c_arrt   nice1mt   b_dictt   info1(    (   R,   sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyt   cs_verify_tagged"   sZ    		% 

 #'	c         C   sˆ   | i  d ƒ i ƒ  } | d } d i | d ƒ d d !i d ƒ } t d „  | i ƒ  i d ƒ d	  ƒ \ } } | | d | d | | f S(
   Ns    ()
i    R-   i   iÿÿÿÿs   " "c         S   s   t  |  i d  ƒ d ƒ S(   t   =i   (   t   intR   (   R   (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   a   s    t   ;i   (   R   R   R:   R   t   pop(   R   t   ppR@   t   args_pt   chgrp_pR#   RF   (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyt   unpp]   s
    
#+c            sB  |  i  } h  } d } t | d ƒ } | i ƒ  } d } x¢| oš| d 7} | d d j o	 | GHn | t d ƒ  d j o* | t d ƒ  d j o | i ƒ  } q9 n | | ƒ \ } } }	 }
 } | d j o“ |	 i ƒ  d } | i ƒ  d	 } t | i ƒ  ƒ d j oV t | i ƒ  ƒ d j o= | i | ƒ p g  g  f | | <n | | d i | ƒ qÊnk | d
 j o] |	 i ƒ  d } | i ƒ  d	 } | i | ƒ p g  g  f | | <n | | d i | ƒ n | i ƒ  } q9 W| i ƒ  |  i ‰ x‹ | i	 ƒ  D]} } | | \ } } h  h  ‰  ‰ t
 ‡  ‡ f d †  | ƒ t
 ‡ ‡ f d †  | ƒ ˆ  i	 ƒ  } ˆ i	 ƒ  } | | f | | <qûWt |  i d ƒ } g  } xo | i ƒ  D]a } | \ } } | \ } } d i | ƒ } d i | ƒ } d i | | | f ƒ } | i | ƒ q¡Wd i | ƒ } t i | d ƒ } | i | ƒ | i ƒ  d  S(   Ns   generalised_predicates.huge.txtt   ri    i   i † s
   (CapableOfs   (CapableOfReceivingActiont	   CapableOfiÿÿÿÿt   CapableOfReceivingActionc            s   ˆ ˆ  |  d  ƒ S(   i   (    (   R   (   t   groups_cleanedR   (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   Ž   s    c            s   ˆ ˆ  |  d  ƒ S(   i   (    (   R   (   t   built_in_arrR   (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR      s    t   wbR-   R   s   
(   RZ   R   t   readlineR9   R   R=   t   appendt   closeR   t   keysR   R   t   itemsR:   R   t   compresst   write(   R   t   history1R   t   inputR#   t	   more_dictt   aliassRX   t   pathname_strt   alias1t	   input_arrt   hashst   pairs_cleanedt   cron_arrt   hostnames_pqt   buf_cleanedRK   RL   t   cp_dictt   buf_arrt   moret   cronsRQ   t   mounts(    (   R^   R_   R   sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   d   sl    	

	.2
	  
c         C   s   | | | <d  S(   N(    (   R   t   dictt   keyt   value(    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR   £   s    (	   t   __name__t
   __module__R   t   NoneR$   RR   RZ   R   R   (    (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pyR      s   	;		?t   __main__(    (   t
   __future__R    t
   __author__t   __version__R   R   R   R   R   R|   t   m(    (    (    sH   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyCommonsense.pys   <module>   s   $Ÿ