Package miopia :: Package analyzer :: Module BackOff
[hide private]
[frames] | no frames]

Source Code for Module miopia.analyzer.BackOff

 1  ''' 
 2  Created on 16/05/2014 
 3   
 4  @author: David Vilares 
 5  ''' 
 6   
 7  from miopia.adapter.Feature import FeatureLevelBackOff 
 8   
 9   
10 -class BackOff(object):
11 ''' 12 This class manages the generalisations (a.k.a as back-off) which make possible to represent tokens 13 as more abstract concepts. 14 ''' 15 16 NGRAM_BACK_OFF_DELIMITER = "-" 17 EMPTY_TOKEN = "EMPTY_TOKEN" 18 19
20 - def __init__(self, dictionary):
21 ''' 22 @param dictionary: An instance of a L{Dictionary} 23 ''' 24 super(BackOff,self).__init__() 25 self._dictionary = dictionary
26 27
28 - def back_off(self, token_info, type_back_off):
29 """ 30 @param token_info: A instance of a L{TokenInfo} 31 @param type_back_off: A valid value for L{FeatureLevelBackOff} 32 """ 33 34 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_COARSE_TAG: 35 return token_info.get_ctag() 36 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_FINE_TAG: 37 return token_info.get_ftag() 38 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_LEMMA: 39 return self._dictionary.get_lemma(token_info.get_ctag(), 40 token_info.get_form()).lower() 41 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_POLARITY_WORDS: 42 raise NotImplementedError 43 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_SEMANTIC_ORIENTATION: 44 raise NotImplementedError 45 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_WORD: 46 return token_info.get_form() 47 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_PSYCHOMETRIC: 48 return self._dictionary.get_psychometric_categories(token_info.get_form().lower()) 49 if type_back_off == FeatureLevelBackOff.TYPE_BACK_OFF_EMPTY: 50 return self.EMPTY_TOKEN
51