Ejemplo n.º 1
0
    def _get_classiying_rule_type(self, answer):
        string_classifier_predict = (
            classifier_services.StringClassifier.predict_label_for_doc)
        predict_counter = test_utils.CallCounter(
            string_classifier_predict)

        with self.swap(
            classifier_services.StringClassifier,
            'predict_label_for_doc', predict_counter):

            response = reader.classify(
                self.exp_id, self.exp_state, answer, {'answer': answer})

        answer_group_index = response['answer_group_index']
        rule_spec_index = response['rule_spec_index']
        answer_groups = self.exp_state.interaction.answer_groups
        if answer_group_index == len(answer_groups):
            return 'default'

        answer_group = answer_groups[answer_group_index]
        if answer_group.get_fuzzy_rule_index() == rule_spec_index:
            return (
                'soft' if predict_counter.times_called == 0
                else 'classifier')
        return 'hard'
Ejemplo n.º 2
0
    def _is_string_classifier_called(self, answer):
        string_classifier_predict = classifier_services.StringClassifier.predict_label_for_doc
        predict_counter = test_utils.CallCounter(string_classifier_predict)

        with self.swap(classifier_services.StringClassifier, "predict_label_for_doc", predict_counter):

            response = reader.classify(self.exp_state, answer)

        answer_group_index = response["answer_group_index"]
        rule_spec_index = response["rule_spec_index"]
        answer_groups = self.exp_state.interaction.answer_groups
        if answer_group_index == len(answer_groups):
            return "default"

        answer_group = answer_groups[answer_group_index]
        return answer_group.get_classifier_rule_index() == rule_spec_index and predict_counter.times_called == 1
Ejemplo n.º 3
0
    def _is_string_classifier_called(self, answer):
        string_classifier_predict = (
            classifier_services.StringClassifier.predict_label_for_doc)
        predict_counter = test_utils.CallCounter(string_classifier_predict)

        with self.swap(classifier_services.StringClassifier,
                       'predict_label_for_doc', predict_counter):

            response = reader.classify(self.exp_state, answer)

        answer_group_index = response['answer_group_index']
        rule_spec_index = response['rule_spec_index']
        answer_groups = self.exp_state.interaction.answer_groups
        if answer_group_index == len(answer_groups):
            return 'default'

        answer_group = answer_groups[answer_group_index]
        return (answer_group.get_classifier_rule_index() == rule_spec_index
                and predict_counter.times_called == 1)