³ò
öçAc           @   s;   d  Z  d Z d d k Z d d k Z d d d „  ƒ  YZ d S(   s   Hugo Liu <hugo@media.mit.edu>s   2.0iÿÿÿÿNt   MontyContextualRuleParserc           B   sw   e  Z d  Z g  Z d d d d d d d d d	 d
 d g Z d „  Z d „  Z d d „ Z d d „ Z d „  Z	 d „  Z
 RS(   s   CONTEXTUALRULEFILE.MDFt   PREVTAGt   NEXTTAGt   PREV1OR2TAGt   NEXT1OR2TAGt   PREV1OR2OR3TAGt   NEXT1OR2OR3TAGt   SURROUNDTAGt
   PREVBIGRAMt
   NEXTBIGRAMt   PREV2TAGt   NEXT2TAGc         C   sY   t  i  ƒ  i |  i ƒ |  _ |  i d j o d |  i GHd GHn |  i |  i ƒ d GHd  S(   Nt    s   ERROR: could not find %ss'   in current dir, %MONTYLINGUA% or %PATH%s   ContextualRuleParser OK!(   t
   MontyUtilst	   find_filet   contextualrules_filenamet   populate_from_file(   t   self(    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyt   __init__   s    	c         C   sj   |  i  } |  i } xQ t t | ƒ ƒ D]= } | | } x* t t | ƒ ƒ D] } | | | | ƒ qH Wq% Wd  S(   N(   t   rulest
   apply_rulet   ranget   len(   R   t   text_arrt	   user_dictt   a_arrt   the_parser_strt   namesst
   chroot_arr(    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyt   apply_rules_to_all_words_brill   s    		 
 t   depthc         C   s…   |  i  } | d j o
 d } n d } d } xR | oJ d } x= t t | ƒ ƒ D]) } | | | | ƒ } | o
 d } qO qO Wq/ Wd  S(   Nt   breadthi    i   (   t   apply_rules_to_one_wordR   R   (   R   R   t   depth_or_breadth_first_firingt   hostnames_arrt   _montylingua_arrt   inputsR   t   b_arr(    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyt   apply_rules_to_all_words    s    	

 i    c         C   sÍ   |  i  } |  i } d } d } x¨ | o  d } x“ t t | ƒ ƒ D] } | | }	 | | d }
 | |	 | | ƒ } | oH d } d } d G| | d Gd G|
 Gd G| | d GH| p | SqÀ qA qA Wq! W| S(   Ni    i   t   poss   DEBUG: POS of wordt   words   changed fromt   to(   R   R   R   R   (   R   R   t
   word_indext   exhaustive_pR   R   t   b_arruR$   R   R   t   ps1R%   (    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyR    3   s$    		
 
)c         C   s|  d } | | d } | | d } | d } | d } | d }	 | d }
 | d } |	 | j o | Sn d | j o |
 | j o | Sn d } d } d } d } d } d } | d j o | | d d } n | d j o | | d d } n | d j o | | d d } n | t  | ƒ d j  o | | d d } n | t  | ƒ d j  o | | d d } n | t  | ƒ d j  o | | d d } n | d	 j o0 | d | g j o |
 | | d <d } qxn| d
 j o0 | d | g j o |
 | | d <d } qxn`| d j o3 | d | | g j o |
 | | d <d } qxn | d j o3 | d | | g j o |
 | | d <d } qxnà| d j o6 | d | | | g j o |
 | | d <d } qxn| d j o6 | d | | | g j o |
 | | d <d } qxnZ| d j o> | d | j o) | d | j o |
 | | d <d } qxn| d j o= | d | d g | | g j o |
 | | d <d } qxnÅ | d j o= | d | d g | | g j o |
 | | d <d } qxn{ | d j o0 | d | g j o |
 | | d <d } qxn> | d j o0 | d | g j o |
 | | d <d } qxn | S(   Ni    R'   t   all_posi   i   t   UNKR   i   R   R   R   R   R   R   R   R   R	   R
   R   (   R   (   R   t   ruleR   R*   R$   t   awk_dictt   hostname_arrt	   dirname_pt
   cksum_arrzt   arg_cleanedt	   a_cleanedt   bst   buf_dictt   aliasst   filenamet   values_dictt	   built_inst   j_arr(    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyR   J   s–    




"!!c   	      C   s¢   |  i  } yy t | d ƒ } | i ƒ  } xM | oE | i ƒ  } | d } | } | | g } | i | ƒ | i ƒ  } q* W| i ƒ  Wn d GHt i d ƒ n Xd  S(   Nt   ri   s#   Error parsing contextual rule file!iÿÿÿÿ(   R   t   opent   readlinet   splitt   appendt   closet   syst   exit(	   R   R:   R   t	   input_strt   chgrp_dictct	   chown_arrR3   R4   R   (    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyR   «   s     	

(   t   __name__t
   __module__R   R   t
   rule_namesR   R   R&   R    R   R   (    (    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pyR       s   '	
		a(    (   t
   __author__t   __version__RD   R   R    (    (    (    sQ   /afs/cs.wisc.edu/p/zhu/06/nlp/montylingua-2.1/python/MontyContextualRuleParser.pys   <module>   s   