Пример #1
0
    def post(self, unused_exploration_id):
        """Handle POST requests.

        Note: unused_exploration_id is needed because
            @acl_decorators.can_play_exploration needs 2 arguments.
        """
        # A domain object representing the old state.
        old_state = exp_domain.State.from_dict(self.payload.get('old_state'))
        # The learner's raw answer.
        answer = self.payload.get('answer')
        # The learner's parameter values.
        params = self.payload.get('params')
        params['answer'] = answer
        result = classifier_services.classify(old_state, answer)
        self.render_json(result)
Пример #2
0
    def post(self, unused_exploration_id):
        """Handle POST requests.

        Note: unused_exploration_id is needed because @require_playable needs 2
        arguments.
        """
        # A domain object representing the old state.
        old_state = exp_domain.State.from_dict(self.payload.get('old_state'))
        # The learner's raw answer.
        answer = self.payload.get('answer')
        # The learner's parameter values.
        params = self.payload.get('params')
        params['answer'] = answer
        result = classifier_services.classify(old_state, answer)
        self.render_json(result)
Пример #3
0
    def _is_string_classifier_called(self, answer):
        sc = classifier_registry.Registry.get_classifier_by_algorithm_id(
            feconf.INTERACTION_CLASSIFIER_MAPPING['TextInput']['algorithm_id'])
        string_classifier_predict = (sc.__class__.predict)
        predict_counter = test_utils.CallCounter(string_classifier_predict)

        with self.swap(sc.__class__, 'predict', predict_counter):
            response = classifier_services.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)
Пример #4
0
    def _is_string_classifier_called(self, answer):
        sc = classifier_registry.Registry.get_classifier_by_algorithm_id(
            feconf.INTERACTION_CLASSIFIER_MAPPING['TextInput'])
        string_classifier_predict = (
            sc.__class__.predict)
        predict_counter = test_utils.CallCounter(
            string_classifier_predict)

        with self.swap(sc.__class__, 'predict', predict_counter):
            response = classifier_services.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)