;ò
v$„@c           @   sE   d  Z  d Z d k Z d k Z d k Z d k Td f  d „  ƒ  YZ d S(   s   Hugo Liu <hugo@media.mit.edu>s   1.3.1N(   s   *s   ContextualRuleParserc           B   sw   t  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(   Ns   CONTEXTUALRULEFILEs   PREVTAGs   NEXTTAGs   PREV1OR2TAGs   NEXT1OR2TAGs   PREV1OR2OR3TAGs   NEXT1OR2OR3TAGs   SURROUNDTAGs
   PREVBIGRAMs
   NEXTBIGRAMs   PREV2TAGs   NEXT2TAGc         C   sV   t  i  ƒ  i |  i ƒ |  _ |  i d j o d GHd GHn |  i |  i ƒ d GHd  Sd  S(   Ns    s(   ERROR: could not find CONTEXTUALRULEFILEs'   in current dir, %MONTYLINGUA% or %PATH%s   ContextualRuleParser OK!(   s
   MontyUtilss	   find_files   selfs   contextualrules_filenames   populate_from_file(   s   self(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   __init__   s    	c         C   sh   |  i } xT t t | ƒ ƒ D]@ } | | } x- t t | ƒ ƒ D] } |  i | | | ƒ q? Wq Wd  Sd  S(   N(	   s   selfs   ruless   ranges   lens   is   rules   text_arrs   js
   apply_rule(   s   selfs   text_arrs   ruless   js   is   rule(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   apply_rules_to_all_words_brill   s    	 
 s   depthc         C   sƒ   | d j o
 d } n d } d } xU | oM d } x@ t t | ƒ ƒ D], } |  i | | | ƒ } | o
 d } qF qF Wq& Wd  Sd  S(   Ns   breadthi    i   (
   s   depth_or_breadth_first_firings   exhaustive_ps   dirtyBits   ranges   lens   text_arrs   is   selfs   apply_rules_to_one_words   res(   s   selfs   text_arrs   depth_or_breadth_first_firings   dirtyBits   is   ress   exhaustive_p(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   apply_rules_to_all_words   s    
  i    c         C   sÌ   |  i } d }
 d } x¬ | o¤ d } x— t t | ƒ ƒ D]ƒ } | | } | | d } |  i | | | ƒ }	 |	 oI d } d }
 d G| | d Gd G| Gd G| | d GH| o |
 Sq» q8 q8 Wq W|
 Sd  S(   Ni    i   s   poss   DEBUG: POS of words   words   changed froms   to(   s   selfs   ruless   wordLevelDirtyBits   dirtyBits   ranges   lens   is   rules   text_arrs
   word_indexs   cur_poss
   apply_rules   ress   exhaustive_p(   s   selfs   text_arrs
   word_indexs   exhaustive_ps   is   dirtyBits   ruless   cur_poss   rules   ress   wordLevelDirtyBit(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   apply_rules_to_one_word+   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 | Sd  S(   Ni    s   poss   all_posi   i   s   UNKs    i   s   PREVTAGs   NEXTTAGs   PREV1OR2TAGs   NEXT1OR2TAGs   PREV1OR2OR3TAGs   NEXT1OR2OR3TAGs   SURROUNDTAGs
   PREVBIGRAMs
   NEXTBIGRAMs   PREV2TAGs   NEXT2TAG(   s   dirtyBits   text_arrs
   word_indexs   poss   all_poss   rules   preds   argss   from_tags   to_tags	   real_argss   prevprevprevs   prevprevs   prevs   nexts   nextnexts   nextnextnexts   len(   s   selfs   rules   text_arrs
   word_indexs   nextnextnexts   argss   dirtyBits   preds   poss   nexts   prevprevs   from_tags   to_tags   prevs   prevprevprevs   nextnexts   all_poss	   real_args(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys
   apply_rule=   s–    




"!!c         C   s£   y t  | d ƒ } | i ƒ  } xS | oK t i | ƒ } | d } | } | | g } |  i i | ƒ | i ƒ  } q! W| i ƒ  Wn d GHt i d ƒ n Xd  Sd  S(   Ns   ri   s#   Error parsing contextual rule file!iÿÿÿÿ(   s   opens   filenames   fs   readlines   lines   strings   splits   tokss   preds   argss   rules   selfs   ruless   appends   closes   syss   exit(   s   selfs   filenames   tokss   fs   preds   argss   rules   line(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   populate_from_fileŠ   s      
(   s   __name__s
   __module__s   contextualrules_filenames   ruless
   rule_namess   __init__s   apply_rules_to_all_words_brills   apply_rules_to_all_wordss   apply_rules_to_one_words
   apply_rules   populate_from_file(    (    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   ContextualRuleParser   s   '				M(   s
   __author__s   __version__s   syss   strings
   MontyUtilss   typess   ContextualRuleParser(   s   strings   ContextualRuleParsers
   __author__s   syss
   MontyUtilss   __version__(    (    sY   C:\Documents and Settings\Administrator\Desktop\pyCSVoice\omcsnet\ContextualRuleParser.pys   ?   s
   	