Пример #1
0
 def count_fitness(self, *args):
     ff_max = sys.float_info.min
     ff_min = sys.float_info.max
     for rule in self.rules:
         rule_ff_value = rule.profit - rule.debt
         if rule_ff_value > ff_max:
             ff_max = rule_ff_value
         if rule_ff_value < ff_min:
             ff_min = rule_ff_value
     for rule in self.rules:
         if not args:
             RulesService.count_fitness(ff_max, ff_min,
                                        self.fitness_defaults, rule)
         else:
             RulesService.count_fitness2(rule, args[0], args[1])
Пример #2
0
    def test_descriptions_generation(self):
        rule = Rule([self.left, self.rightTerminal])
        rule.fitness = 1
        rule.profit = 2
        rule.usages_in_invalid_parsing = 3
        rule.usages_in_proper_parsing = 4
        rule.debt = 5
        rule.age = 6

        descriptions = RulesService.get_description_string_for_rule(rule)
        self.assertEqual(descriptions[0], "fitness (f): 1")
        self.assertEqual(descriptions[1], "proper usages (u_p): 4")
        self.assertEqual(descriptions[2], "invalid usages (u_n): 3")
        self.assertEqual(descriptions[3], "profit (p): 2")
        self.assertEqual(descriptions[4], "debt (d): 5")
        self.assertEqual(descriptions[5], "age: 6")
Пример #3
0
 def test_rules_similar_three_points(self):
     rule = Rule([self.left, self.rightNonTerminal, self.rightTerminal])
     rule2 = Rule([self.left, self.rightNonTerminal, self.rightTerminal])
     similarities = RulesService.similarities_between_rules(rule, rule2)
     self.assertEqual(similarities, 3)