Package miopia :: Package adapter :: Module CompositeAdapter
[hide private]
[frames] | no frames]

Source Code for Module miopia.adapter.CompositeAdapter

 1  ''' 
 2  Created on 28/05/2013 
 3   
 4  @author: David Vilares Calvo 
 5  ''' 
 6   
 7  from miopia.parser.Parser import Parser 
 8  from miopia.adapter.Adapter import Adapter 
 9  from collections import defaultdict, OrderedDict 
10  import os 
11   
12   
13 -class CompositeAdapter(Adapter):
14 ''' 15 CompositeAdapter allows to combine different L{Adapter}'s to obtain a global ranking 16 off all features 17 ''' 18 FEATURE_TYPE = "COMPOSITE_FEATURE_TYPE" 19
20 - def __init__(self,path_weka,counter):
21 ''' 22 @param path_weka: The path to the WEKA.jar 23 @param counter: An instance of L{CompositeAuxiliaryCounter} 24 ''' 25 self._list_adapters = [] 26 self._list_external_resources = [] 27 super(CompositeAdapter,self).__init__(path_weka,counter,None) 28 self._dict_str_ftc_adapter_weight = {}
29
30 - def add(self,adapter):
31 """ 32 Add an L{Adapter} to the composite adapter 33 """ 34 self._list_adapters.append(adapter) 35 self._dict_str_ftc_adapter_weight[str(adapter._get_feature_type())] = adapter.get_weighting_factor()
36
37 - def remove(self,adapter):
38 """ 39 Remove and L{Adapter} from the composite adapter 40 """ 41 self._list_adapters.remove(adapter) 42 self._dict_str_ftc_adapter_weight.pop(str(adapter._get_feature_type()))
43
44 - def get_children(self):
45 """ 46 Obtain the children of a L{CompositeAdapter} 47 """ 48 return self._list_adapters
49
50 - def _get_feature_type(self):
51 return self.FEATURE_TYPE
52 53
54 - def _analyze_graph(self,dgs):
55 dict_features = {} 56 for adapter in self._list_adapters: 57 dict_features.update(adapter._analyze_graph(dgs)) 58 return dict_features
59 60
61 - def count_features(self,list_text_info):
62 """ 63 @return A dictionary with the number of features considered by the adapter in an instance 64 of a L{nltk.parse.dependencygraph.DependencyGraph} 65 """ 66 dict_features = {} 67 for adapter in self._list_adapters: 68 dict_features.update(adapter.count_features(list_text_info)) 69 return dict_features
70
71 - def get_weighting_value(self,str_ftc,value):
72 73 weighting_factor = self._dict_str_ftc_adapter_weight[str_ftc] 74 if weighting_factor == self.BINARY_WEIGHTING_FACTOR: 75 return 1 76 if weighting_factor == self.TOTAL_WEIGHTING_FACTOR: 77 return value
78