<commit_before>from typing import NamedTuple

from lexos.receivers.base_receiver import BaseReceiver


class TopwordFrontEndOption(NamedTuple):
    """The typed tuple to implement topword options."""
    analysis_option: str


class TopwordReceiver(BaseReceiver):
    def __init__(self):
        """The Receiver to get all the topword options from front end."""
        super().__init__()

    def options_from_front_end(self) -> TopwordFrontEndOption:
        """Get the topword option from front end.

        :return: a TopwordFrontEndOption object to hold the analysis option.
        """
        analysis_option = self._front_end_data['testInput']

        return TopwordFrontEndOption(analysis_option=analysis_option)<commit_msg>Use Enum<commit_after>from enum import Enum
from lexos.receivers.base_receiver import BaseReceiver


class TopwordAnalysisType(Enum):
    ALL_TO_PARA = "allToPara"
    CLASS_TO_PARA = "classToPara"
    CLASS_TO_CLASS = "classToClass"


class TopwordReceiver(BaseReceiver):
    def __init__(self):
        """The Receiver to get the topword analysis type from front end."""
        super().__init__()

    def options_from_front_end(self) -> TopwordAnalysisType:
        """Get the topword option from front end.

        :return: a TopwordAnalysisType object that holds the analysis option.
        """
        if self._front_end_data["testInput"] == "allToPara":
            return TopwordAnalysisType.ALL_TO_PARA
        elif self._front_end_data["testInput"] == "classToPara":
            return TopwordAnalysisType.CLASS_TO_PARA
        elif self._front_end_data["testInput"] == "classToClass":
            return TopwordAnalysisType.CLASS_TO_CLASS
        else:
            raise ValueError("Invalid topword analysis option from front end.")
{'fraction_non_alphanumeric': 0.08253790005614824, 'fraction_numerical': 0.0, 'mean_word_length': 3.5343511450381677, 'pattern_counts': {'":': 3, '<': 3, '<?xml version=': 0, '>': 5, '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': '3728358', 'n_tokens_mistral': 503, 'n_tokens_neox': 485, 'n_words': 133}