1 '''
2 Created on 07.10.2011
3
4 @author: Eleftherios Avramidis
5 '''
6 from featuregenerator import FeatureGenerator
7
9 '''
10 It produces a new ranking of the translated sentences, based on another value.
11 This "clean" ranking starts from zero and has a maximum ranking difference of 1
12 '''
13
14 - def __init__(self, critical_attribute, new_attribute_name = None, reverse = False):
15 '''
16 @param critical_attribute The name of the attribute whose value will guide the ranking
17 @type critical_attribute String
18 @param new_attribute_name If the attributes needs to be renamed, the new name must be entered here. If not entered, then the attribute name is created based on the critical attribute, with the addition of the ending "-rank"
19 @type new_attribute_name String
20 @param reverse Set True if you need it to be sorted on the reverse order
21 @type boolean
22 '''
23 self.critical_attribute = critical_attribute
24 self.new_attribute_name = new_attribute_name
25 self.reverse = reverse
26 if not new_attribute_name:
27 self.new_attribute_name = "%s-rank" % critical_attribute
28
29
30
32 values = [float(tgt.get_attribute(self.critical_attribute)) for tgt in ps.get_translations()]
33 values = list(set(values))
34 values = sorted(values)
35 if self.reverse:
36 values.reverse()
37
38 for translation in ps.get_translations():
39 value = float(translation.get_attribute(self.critical_attribute))
40 new_attribute_value = values.index(value) + 1
41 translation.add_attribute(self.new_attribute_name, str(new_attribute_value))
42 return ps
43