<commit_before>from vusion.error import MissingField, VusionError

class Action(object):

    ACTION_TYPE = None
    
    def __init__ (self, _process_fields=True, **kwargs):
        if _process_fields:
            kwargs = self.process_fields(kwargs)
        self.payload = kwargs
        self.validate_fields()

    def __eq__(self, other):
        if isinstance(other, Action):
            return self.payload == other.payload
        return False

    def __getitem__(self, key):
        return self.payload[key]

    def __setitem__(self, key, value):
        self.payload[key] = value

    def process_fields(self, fields):
        return fields

    def validate_fields(self):
        pass
    
    def get_type(self):
        return self.ACTION_TYPE
    
    def assert_field_present(self, *fields):
        for field in fields:
            if field not in self.payload:
                raise MissingField(field)
            

class OptinAction(Action):
    
    ACTION_TYPE = 'optin'

    def validate_fields(self):
        pass


class OptoutAction(Action):
    
    ACTION_TYPE = 'optout'
    
    def validate_fields(self):
        pass


class FeedbackAction(Action):
    
    ACTION_TYPE = 'feedback'
    
    def validate_fields(self):
        self.assert_field_present(
        'content')


class UnMatchingAnswerAction(Action):
    
    ACTION_TYPE = 'unmatching-answer'
    
    def validate_fields(self):
        self.assert_field_present(
        'answer')


class TaggingAction(Action):

    ACTION_TYPE = 'tagging'
    
    def validate_fields(self):
        self.assert_field_present(
        'tag')


class EnrollingAction(Action):

    ACTION_TYPE = 'enrolling'
    
    def validate_fields(self):
        self.assert_field_present(
        'enroll')


class ProfilingAction(Action):

    ACTION_TYPE = 'profiling'
    
    def validate_fields(self):
        self.assert_field_present(
        'label',
        'value')


def action_generator(**kwargs):
    # Condition to be removed when Dialogue structure freezed
    if 'type-action' not in kwargs:
        kwargs['type-action'] = kwargs['type-answer-action']
    if kwargs['type-action'] == 'optin':
        return OptinAction(**kwargs)
    elif kwargs['type-action'] == 'optout':
        return OptoutAction(**kwargs)
    elif kwargs['type-action'] == 'enrolling':
        return EnrollingAction(**kwargs)
    elif kwargs['type-action'] == 'tagging':
        return TaggingAction(**kwargs)
    elif kwargs['type-action'] == 'profiling':
        return ProfilingAction(**kwargs)
    elif kwargs['type-action'] == 'feedback':
        return FeedbackAction(**kwargs)
    elif kwargs['type-action'] == 'unmatching-answer':
        return UnMatchingAnswerAction(**kwargs)<commit_msg>added a RemoveRemindersAction in action.py<commit_after>from vusion.error import MissingField, VusionError

class Action(object):

    ACTION_TYPE = None
    
    def __init__ (self, _process_fields=True, **kwargs):
        if _process_fields:
            kwargs = self.process_fields(kwargs)
        self.payload = kwargs
        self.validate_fields()

    def __eq__(self, other):
        if isinstance(other, Action):
            return self.payload == other.payload
        return False

    def __getitem__(self, key):
        return self.payload[key]

    def __setitem__(self, key, value):
        self.payload[key] = value

    def process_fields(self, fields):
        return fields

    def validate_fields(self):
        pass
    
    def get_type(self):
        return self.ACTION_TYPE
    
    def assert_field_present(self, *fields):
        for field in fields:
            if field not in self.payload:
                raise MissingField(field)
            

class OptinAction(Action):
    
    ACTION_TYPE = 'optin'

    def validate_fields(self):
        pass


class OptoutAction(Action):
    
    ACTION_TYPE = 'optout'
    
    def validate_fields(self):
        pass


class FeedbackAction(Action):
    
    ACTION_TYPE = 'feedback'
    
    def validate_fields(self):
        self.assert_field_present(
        'content')


class UnMatchingAnswerAction(Action):
    
    ACTION_TYPE = 'unmatching-answer'
    
    def validate_fields(self):
        self.assert_field_present(
        'answer')


class TaggingAction(Action):

    ACTION_TYPE = 'tagging'
    
    def validate_fields(self):
        self.assert_field_present(
        'tag')


class EnrollingAction(Action):

    ACTION_TYPE = 'enrolling'
    
    def validate_fields(self):
        self.assert_field_present(
        'enroll')


class ProfilingAction(Action):

    ACTION_TYPE = 'profiling'
    
    def validate_fields(self):
        self.assert_field_present(
        'label',
        'value')
        
class RemoveRemindersAction(Action):
    
    ACTION_TYPE = 'remove-reminders'
    
    def validate_fields(self):
        self.assert_field_present(
          'dialogue-id',
          'interaction-id')


def action_generator(**kwargs):
    # Condition to be removed when Dialogue structure freezed
    if 'type-action' not in kwargs:
        kwargs['type-action'] = kwargs['type-answer-action']
    if kwargs['type-action'] == 'optin':
        return OptinAction(**kwargs)
    elif kwargs['type-action'] == 'optout':
        return OptoutAction(**kwargs)
    elif kwargs['type-action'] == 'enrolling':
        return EnrollingAction(**kwargs)
    elif kwargs['type-action'] == 'tagging':
        return TaggingAction(**kwargs)
    elif kwargs['type-action'] == 'profiling':
        return ProfilingAction(**kwargs)
    elif kwargs['type-action'] == 'feedback':
        return FeedbackAction(**kwargs)
    elif kwargs['type-action'] == 'unmatching-answer':
        return UnMatchingAnswerAction(**kwargs)
    elif kwargs['type-action'] == 'remove-reminders':
        return RemoveRemindersAction(**kwargs)
{'fraction_non_alphanumeric': 0.10481392966882895, 'fraction_numerical': 0.0, 'mean_word_length': 2.6099815157116453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2047980', 'n_tokens_mistral': 1736, 'n_tokens_neox': 1674, 'n_words': 369}