Package miopia :: Package preprocessor :: Module PreProcessorDecorator
[hide private]
[frames] | no frames]

Source Code for Module miopia.preprocessor.PreProcessorDecorator

 1  ''' 
 2   
 3  @author: David Vilares Calvo  
 4  ''' 
 5   
 6  from PreProcessorI import * 
 7   
8 -class PreProcessorDecorator(PreProcessorI):
9 ''' 10 classdocs 11 ''' 12 13 14
15 - def __init__(self,params):
16 ''' 17 Constructor 18 ''' 19 raise NotImplementedError
20 21
22 - def _build_new_text(self,text,old_string,new_string, maxreplace=None):
23 24 try: 25 index_beginning = text.index(old_string) 26 add_beginning_punkt = self._include_beginning_punct(text, index_beginning) 27 index_ending = index_beginning + len(old_string) 28 add_ending_punkt = self._include_ending_punct(text, index_ending) 29 except ValueError: 30 return text 31 if add_beginning_punkt: 32 new_string = ' . '+new_string 33 if add_ending_punkt: 34 new_string = new_string+' . ' 35 if maxreplace ==None: 36 text = text.replace(old_string,new_string) 37 else: 38 text = text.replace(old_string,new_string,1) 39 return text
40 41 # def _build_new_sentence(self,string, add_beggining_punkt=True, 42 # add_ending_punkt): 43 # if add_beggining_punkt: 44 # string = ". "+string 45 # if add_ending_punkt: 46 # #if not string.endswith("."): 47 # string =string+"." 48 # return string 49 50
51 - def _include_beginning_punct(self,text,i):
52 return (not text[0:i].strip().endswith('.') and i!=0)
53
54 - def _include_ending_punct(self,text,i):
55 return (not text[i:].strip().startswith('.'))
56
57 - def preprocess(self,text):
58 raise NotImplementedError
59