Exemple #1
0
    def to_dict(self):
        """Gets a dict representing this interaction. Only default values are
        provided.
        """
        result = {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'display_mode': self.display_mode,
            'is_terminal': self.is_terminal,
            'is_trainable': self.is_trainable,
            'is_string_classifier_trainable':
                self.is_string_classifier_trainable,
            'is_linear': self.is_linear,
            'needs_summary': self.needs_summary,
            'customization_arg_specs': [{
                'name': ca_spec.name,
                'description': ca_spec.description,
                'default_value': ca_spec.default_value,
                'schema': ca_spec.schema,
            } for ca_spec in self.customization_arg_specs],
            'instructions': self.instructions,
            'default_outcome_heading': self.default_outcome_heading,
        }

        # Add information about rule descriptions corresponding to the answer
        # type for this interaction.
        result['rule_descriptions'] = (
            rule_domain.get_description_strings_for_obj_type(
                self.answer_type))

        return result
Exemple #2
0
    def to_dict(self):
        """Gets a dict representing this interaction. Only default values are
        provided.
        """
        result = {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'display_mode': self.display_mode,
            'is_terminal': self.is_terminal,
            'is_trainable': self.is_trainable,
            'needs_summary': self.needs_summary,
            'customization_arg_specs': [{
                'name': ca_spec.name,
                'description': ca_spec.description,
                'default_value': ca_spec.default_value,
                'schema': ca_spec.schema,
            } for ca_spec in self.customization_arg_specs],
            'instructions': self.instructions,
        }

        # Add information about rule descriptions corresponding to the answer
        # type for this interaction.
        result['rule_descriptions'] = (
            rule_domain.get_description_strings_for_obj_type(
                self.answer_type))

        return result
Exemple #3
0
    def to_dict(self):
        """Gets a dict representing this interaction. Only default values are
        provided.
        """
        result = {
            'id': self.id,
            'name': self.name,
            'description': self.description,
            'display_mode': self.display_mode,
            'is_terminal': self.is_terminal,
            'customization_arg_specs': [{
                'name': ca_spec.name,
                'description': ca_spec.description,
                'default_value': ca_spec.default_value,
                'schema': ca_spec.schema,
            } for ca_spec in self.customization_arg_specs],
        }

        # Add information about the handlers.
        result['handler_specs'] = [h.to_dict() for h in self.handlers]
        for idx, handler in enumerate(self.handlers):
            result['handler_specs'][idx]['rules'] = dict((
                rule_cls.description,
                {'classifier': rule_cls.__name__}
            ) for rule_cls in handler.rules)

        # Add information about rule descriptions corresponding to the answer
        # type for this interaction.
        result['rule_descriptions'] = (
            rule_domain.get_description_strings_for_obj_type(
                self.handlers[0].obj_type))

        return result
Exemple #4
0
 def test_get_description_strings_for_obj_type(self):
     rule_descriptions = rule_domain.get_description_strings_for_obj_type("UnicodeString")
     self.assertEqual(
         rule_descriptions,
         {
             "CaseSensitiveEquals": ("is equal to {{x|UnicodeString}}, taking case into account"),
             "Contains": "contains {{x|UnicodeString}}",
             "Equals": "is equal to {{x|UnicodeString}}",
             "MatchesBase64EncodedFile": ("has same content as the file located at " "{{filepath|UnicodeString}}"),
             "StartsWith": "starts with {{x|UnicodeString}}",
         },
     )
Exemple #5
0
 def test_get_description_strings_for_obj_type(self):
     rule_descriptions = rule_domain.get_description_strings_for_obj_type(
         'Real')
     self.assertEqual(rule_descriptions, {
         'Equals': 'is equal to {{x|Real}}',
         'IsLessThan': 'is less than {{x|Real}}',
         'IsGreaterThan': 'is greater than {{x|Real}}',
         'IsLessThanOrEqualTo': 'is less than or equal to {{x|Real}}',
         'IsGreaterThanOrEqualTo': 'is greater than or equal to {{x|Real}}',
         'IsInclusivelyBetween': (
             'is between {{a|Real}} and {{b|Real}}, inclusive'),
         'IsWithinTolerance': 'is within {{tol|Real}} of {{x|Real}}'
     })
 def test_get_description_strings_for_obj_type(self):
     rule_descriptions = rule_domain.get_description_strings_for_obj_type(
         'UnicodeString')
     self.assertEqual(rule_descriptions, {
         'CaseSensitiveEquals': (
             'is equal to {{x|UnicodeString}}, taking case into account'),
         'Contains': 'contains {{x|UnicodeString}}',
         'Equals': 'is equal to {{x|UnicodeString}}',
         'MatchesBase64EncodedFile': (
             'has same content as the file located at '
             '{{filepath|UnicodeString}}'),
         'StartsWith': 'starts with {{x|UnicodeString}}',
     })
Exemple #7
0
 def test_get_description_strings_for_obj_type(self):
     rule_descriptions = rule_domain.get_description_strings_for_obj_type(
         'UnicodeString')
     self.assertEqual(rule_descriptions, {
         'CaseSensitiveEquals': (
             'is equal to {{x|UnicodeString}}, taking case into account'),
         'Contains': 'contains {{x|UnicodeString}}',
         'Equals': 'is equal to {{x|UnicodeString}}',
         'MatchesBase64EncodedFile': (
             'has same content as the file located at '
             '{{filepath|UnicodeString}}'),
         'StartsWith': 'starts with {{x|UnicodeString}}',
     })
Exemple #8
0
    def to_dict(self):
        """Gets a dict representing this interaction. Only default values are
        provided.
        """
        result = {
            'id':
            self.id,
            'name':
            self.name,
            'description':
            self.description,
            'display_mode':
            self.display_mode,
            'is_terminal':
            self.is_terminal,
            'customization_arg_specs': [{
                'name': ca_spec.name,
                'description': ca_spec.description,
                'default_value': ca_spec.default_value,
                'schema': ca_spec.schema,
            } for ca_spec in self.customization_arg_specs],
        }

        # Add information about the handlers.
        result['handler_specs'] = [h.to_dict() for h in self.handlers]
        for idx, handler in enumerate(self.handlers):
            result['handler_specs'][idx]['rules'] = dict(
                (rule_cls.description, {
                    'classifier': rule_cls.__name__
                }) for rule_cls in handler.rules)

        # Add information about rule descriptions corresponding to the answer
        # type for this interaction.
        result['rule_descriptions'] = (
            rule_domain.get_description_strings_for_obj_type(
                self.handlers[0].obj_type))

        return result