1# Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. 2# 3# Use of this source code is governed by a BSD-style license 4# that can be found in the LICENSE file in the root of the source 5# tree. An additional intellectual property rights grant can be found 6# in the file PATENTS. All contributing project authors may 7# be found in the AUTHORS file in the root of the source tree. 8 9"""EvaluationScore factory class. 10""" 11 12import logging 13 14from . import exceptions 15from . import eval_scores 16 17 18class EvaluationScoreWorkerFactory(object): 19 """Factory class used to instantiate evaluation score workers. 20 21 The ctor gets the parametrs that are used to instatiate the evaluation score 22 workers. 23 """ 24 25 def __init__(self, polqa_tool_bin_path): 26 self._score_filename_prefix = None 27 self._polqa_tool_bin_path = polqa_tool_bin_path 28 29 def SetScoreFilenamePrefix(self, prefix): 30 self._score_filename_prefix = prefix 31 32 def GetInstance(self, evaluation_score_class): 33 """Creates an EvaluationScore instance given a class object. 34 35 Args: 36 evaluation_score_class: EvaluationScore class object (not an instance). 37 38 Returns: 39 An EvaluationScore instance. 40 """ 41 if self._score_filename_prefix is None: 42 raise exceptions.InitializationException( 43 'The score file name prefix for evaluation score workers is not set') 44 logging.debug( 45 'factory producing a %s evaluation score', evaluation_score_class) 46 47 if evaluation_score_class == eval_scores.PolqaScore: 48 return eval_scores.PolqaScore( 49 self._score_filename_prefix, self._polqa_tool_bin_path) 50 else: 51 return evaluation_score_class(self._score_filename_prefix) 52