| OLD | NEW |
| (Empty) |
| 1 # Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """Aggregator aggregates all the scorers passed in. | |
| 6 | |
| 7 Multiplies scores together and combines reasons and summaries the result. | |
| 8 """ | |
| 9 | |
| 10 | |
| 11 class Aggregator(object): | |
| 12 | |
| 13 def __init__(self, scorers): | |
| 14 self.scorers = scorers | |
| 15 | |
| 16 def ScoreAndReason(self, result): | |
| 17 """Sets result.confidence and result.reason.""" | |
| 18 | |
| 19 score = 1.0 | |
| 20 reason = '' | |
| 21 for i, scorer in enumerate(self.scorers): | |
| 22 current_score, current_reason = scorer(result) | |
| 23 # TODO(katesonia): Compare this mutiply aggregator with a vector of scores | |
| 24 # aggregator later. | |
| 25 score *= current_score | |
| 26 reason += '(%d) %s\n' % (i + 1, current_reason) | |
| 27 | |
| 28 reason += '\n%s' % str(result) | |
| 29 | |
| 30 result.confidence = score | |
| 31 result.reason = reason | |
| OLD | NEW |