





'''simple docstring'''


import numpy as np

lowerCAmelCase      							=[
    ["a", "b", "c", "d", "e"],
    ["f", "g", "h", "i", "k"],
    ["l", "m", "n", "o", "p"],
    ["q", "r", "s", "t", "u"],
    ["v", "w", "x", "y", "z"],
]
class    a_     :





     def __init__(				self	:      int		):





        """simple docstring"""




        lowercase_    :Optional[int]					    =				np.array(a_		)





     def 							lowercase__   (				self	:      List[str]			,   lowercase	:      str		):





        """simple docstring"""




        lowercase_    ,							lowercase_    :Optional[Any]					    =				np.where(letter == self.SQUARE		)
        lowercase_    :Tuple					    =				np.concatenate([indexa + 1, indexa + 1]		)
        return indexes





     def 							lowercase__   (				self	:      List[Any]			,   lowercase	:      int			,   lowercase	:      int		):





        """simple docstring"""




        return self.SQUARE[indexa - 1, indexa - 1]





     def 							lowercase__   (				self	:      Union[str, Any]			,   lowercase	:      str		):





        """simple docstring"""




        lowercase_    :str					    =				message.lower()
        lowercase_    :List[str]					    =				message.replace("j"			,   "i"		)

        lowercase_    :Union[str, Any]					    =				""
        for letter_index in range(len(a_		)		):
           if message[letter_index] != " ":
              lowercase_    :str					    =				self.letter_to_numbers(message[letter_index]		)
              lowercase_    :Optional[Any]					    =				encoded_message + str(numbers[0]		) + str(numbers[1]		)
           elif message[letter_index] == " ":
              lowercase_    :List[Any]					    =				encoded_message + " "

        return encoded_message







     def 							lowercase__   (				self	:      Union[str, Any]			,   lowercase	:      str		):





        """simple docstring"""




        lowercase_    :List[Any]					    =				message.replace(" "			,   "  "		)
        lowercase_    :Tuple					    =				""
        for numbers_index in range(int(len(a_		) / 2		)		):
           if message[numbers_index * 2] != " ":
              lowercase_    :int					    =				message[numbers_index * 2]
              lowercase_    :List[str]					    =				message[numbers_index * 2 + 1]

              lowercase_    :int					    =				self.numbers_to_letter(int(a_		)			,   int(a_		)		)
              lowercase_    :Any					    =				decoded_message + letter
           elif message[numbers_index * 2] == " ":
              lowercase_    :Dict					    =				decoded_message + " "

        return decoded_message









'''simple docstring'''


from copy import deepcopy
from unittest.case import TestCase

import pytest

from datasets.arrow_dataset import Dataset
from datasets.features import Audio, ClassLabel, Features, Image, Sequence, Value
from datasets.info import DatasetInfo
from datasets.tasks import (
    AudioClassification,
    AutomaticSpeechRecognition,
    ImageClassification,
    LanguageModeling,
    QuestionAnsweringExtractive,
    Summarization,
    TextClassification,
    task_template_from_dict,
)
from datasets.utils.py_utils import asdict


lowerCAmelCase      :  Tuple      							={
    '''id''': '''5733be284776f41900661182''',
    '''title''': '''University_of_Notre_Dame''',
    '''context''': '''Architecturally, the school has a Catholic character. Atop the Main Building\'s gold dome is a golden statue of the Virgin Mary. Immediately in front of the Main Building and facing it, is a copper statue of Christ with arms upraised with the legend "Venite Ad Me Omnes". Next to the Main Building is the Basilica of the Sacred Heart. Immediately behind the basilica is the Grotto, a Marian place of prayer and reflection. It is a replica of the grotto at Lourdes, France where the Virgin Mary reputedly appeared to Saint Bernadette Soubirous in 1858. At the end of the main drive (and in a direct line that connects through 3 statues and the Gold Dome), is a simple, modern stone statue of Mary.''',
    '''question''': '''To whom did the Virgin Mary allegedly appear in 1858 in Lourdes France?''',
    '''answers''': {'''text''': ['''Saint Bernadette Soubirous'''], '''answer_start''': [515]},
}
@pytest.mark.parametrize(
    "task_cls"			,[
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]			,)
def 							UpperCAmelCase_						(		__lowerCamelCase      :      str				):
   lowercase_    :str					    =				task_cls()
   lowercase_    :Tuple					    =				asdict(__lowerCamelCase				)
   lowercase_    :Dict					    =				task_template_from_dict(__lowerCamelCase				)
   assert task == reloaded
class    a_     :





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Optional[int]					    =				LanguageModeling(text_column="input_text"		)
        assert {"input_text": "text"} == task.column_mapping







     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :Tuple					    =				Features({"text": Value("string"		)}		)
        lowercase_    :List[Any]					    =				{"text_column": "input_text"}
        lowercase_    :List[str]					    =				LanguageModeling.from_dict(lowercase		)
        assert "language-modeling" == task.task
        assert input_schema == task.input_schema







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Tuple		):





        """simple docstring"""




        lowercase_    :List[str]					    =				sorted(["pos", "neg"]		)





     def 							lowercase__   (				self	:      int		):





        """simple docstring"""




        lowercase_    :List[str]					    =				TextClassification(text_column="input_text"			,   label_column="input_label"		)
        self.assertDictEqual({"input_text": "text", "input_label": "labels"}			,   task.column_mapping		)





     def 							lowercase__   (				self	:      List[Any]		):





        """simple docstring"""




        lowercase_    :Union[str, Any]					    =				Features({"text": Value("string"		)}		)
        # Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
        lowercase_    :Any					    =				Features({"labels": ClassLabel}		)
        lowercase_    :str					    =				{"text_column": "input_text", "label_column": "input_labels"}
        lowercase_    :Optional[int]					    =				TextClassification.from_dict(lowercase		)
        self.assertEqual("text-classification"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







     def 							lowercase__   (				self	:      str		):





        """simple docstring"""




        lowercase_    :Union[str, Any]					    =				TextClassification(text_column="input_text"			,   label_column="input_label"		)
        self.assertEqual(task.label_schema["labels"]			,   lowercase		)
        lowercase_    :Tuple					    =				task.align_with_features(Features({"input_label": ClassLabel(names=self.labels		)}		)		)
        self.assertEqual(task.label_schema["labels"]			,   ClassLabel(names=self.labels		)		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




        lowercase_    :int					    =				QuestionAnsweringExtractive(
            context_column="input_context"			,   question_column="input_question"			,   answers_column="input_answers"		)
        self.assertDictEqual(
            {"input_context": "context", "input_question": "question", "input_answers": "answers"}			,   task.column_mapping		)







     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :Dict					    =				Features({"question": Value("string"		), "context": Value("string"		)}		)
        lowercase_    :List[Any]					    =				Features(
            {
                "answers": Sequence(
                    {
                        "text": Value("string"		),
                        "answer_start": Value("int32"		),
                    }		)
            }		)
        lowercase_    :int					    =				{
            "context_column": "input_input_context",
            "question_column": "input_question",
            "answers_column": "input_answers",
        }
        lowercase_    :int					    =				QuestionAnsweringExtractive.from_dict(lowercase		)
        self.assertEqual("question-answering-extractive"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :Tuple					    =				Summarization(text_column="input_text"			,   summary_column="input_summary"		)
        self.assertDictEqual({"input_text": "text", "input_summary": "summary"}			,   task.column_mapping		)







     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :int					    =				Features({"text": Value("string"		)}		)
        lowercase_    :str					    =				Features({"summary": Value("string"		)}		)
        lowercase_    :Tuple					    =				{"text_column": "input_text", "summary_column": "input_summary"}
        lowercase_    :Optional[int]					    =				Summarization.from_dict(lowercase		)
        self.assertEqual("summarization"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :Any					    =				AutomaticSpeechRecognition(audio_column="input_audio"			,   transcription_column="input_transcription"		)
        self.assertDictEqual({"input_audio": "audio", "input_transcription": "transcription"}			,   task.column_mapping		)







     def 							lowercase__   (				self	:      Optional[int]		):





        """simple docstring"""




        lowercase_    :Union[str, Any]					    =				Features({"audio": Audio()}		)
        lowercase_    :str					    =				Features({"transcription": Value("string"		)}		)
        lowercase_    :Dict					    =				{
            "audio_column": "input_audio",
            "transcription_column": "input_transcription",
        }
        lowercase_    :Tuple					    =				AutomaticSpeechRecognition.from_dict(lowercase		)
        self.assertEqual("automatic-speech-recognition"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      int		):





        """simple docstring"""




        lowercase_    :str					    =				sorted(["pos", "neg"]		)





     def 							lowercase__   (				self	:      List[str]		):





        """simple docstring"""




        lowercase_    :Optional[int]					    =				AudioClassification(audio_column="input_audio"			,   label_column="input_label"		)
        self.assertDictEqual({"input_audio": "audio", "input_label": "labels"}			,   task.column_mapping		)





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :int					    =				Features({"audio": Audio()}		)
        lowercase_    :Tuple					    =				Features({"labels": ClassLabel}		)
        lowercase_    :List[str]					    =				{
            "audio_column": "input_image",
            "label_column": "input_label",
        }
        lowercase_    :List[Any]					    =				AudioClassification.from_dict(lowercase		)
        self.assertEqual("audio-classification"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :Dict					    =				AudioClassification(audio_column="input_audio"			,   label_column="input_label"		)
        self.assertEqual(task.label_schema["labels"]			,   lowercase		)
        lowercase_    :List[Any]					    =				task.align_with_features(Features({"input_label": ClassLabel(names=self.labels		)}		)		)
        self.assertEqual(task.label_schema["labels"]			,   ClassLabel(names=self.labels		)		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Union[str, Any]		):





        """simple docstring"""




        lowercase_    :Union[str, Any]					    =				sorted(["pos", "neg"]		)





     def 							lowercase__   (				self	:      Any		):





        """simple docstring"""




        lowercase_    :Optional[int]					    =				ImageClassification(image_column="input_image"			,   label_column="input_label"		)
        self.assertDictEqual({"input_image": "image", "input_label": "labels"}			,   task.column_mapping		)





     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Dict					    =				Features({"image": Image()}		)
        lowercase_    :str					    =				Features({"labels": ClassLabel}		)
        lowercase_    :Optional[Any]					    =				{
            "image_column": "input_image",
            "label_column": "input_label",
        }
        lowercase_    :str					    =				ImageClassification.from_dict(lowercase		)
        self.assertEqual("image-classification"			,   task.task		)
        self.assertEqual(lowercase			,   task.input_schema		)
        self.assertEqual(lowercase			,   task.label_schema		)







     def 							lowercase__   (				self	:      List[Any]		):





        """simple docstring"""




        lowercase_    :Any					    =				ImageClassification(image_column="input_image"			,   label_column="input_label"		)
        self.assertEqual(task.label_schema["labels"]			,   lowercase		)
        lowercase_    :Dict					    =				task.align_with_features(Features({"input_label": ClassLabel(names=self.labels		)}		)		)
        self.assertEqual(task.label_schema["labels"]			,   ClassLabel(names=self.labels		)		)







class    a_     (       _lowerCAmelCase							):





     def 							lowercase__   (				self	:      Tuple		):





        """simple docstring"""




        lowercase_    :Dict					    =				DatasetInfo(task_templates=QuestionAnsweringExtractive()		)
        lowercase_    :Optional[Any]					    =				Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}			,   info=lowercase		)
        assert isinstance(dataset.info.task_templates			,   lowercase		)
        assert len(dataset.info.task_templates		) == 1

        def keep_task(lowercase	:      List[str]		):
           return x

        def dont_keep_task(lowercase	:      Any		):
           lowercase_    :Optional[Any]					    =				deepcopy(lowercase		)
           lowercase_    :Dict					    =				0
           return out

        lowercase_    :List[str]					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates
        # reload from cache
        lowercase_    :List[Any]					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == dataset.info.task_templates

        lowercase_    :str					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == []
        # reload from cache
        lowercase_    :Union[str, Any]					    =				dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == []







     def 							lowercase__   (				self	:      Optional[Any]		):





        """simple docstring"""




        lowercase_    :Optional[Any]					    =				Features({"text": Value("string"		), "label": ClassLabel(names=("pos", "neg")		)}		)
        lowercase_    :str					    =				TextClassification(text_column="text"			,   label_column="label"		)
        lowercase_    :Optional[int]					    =				DatasetInfo(features=lowercase			,   task_templates=lowercase		)
        lowercase_    :Dict					    =				Dataset.from_dict({"text": ["A sentence."], "label": ["pos"]}			,   info=lowercase		)

        def process(lowercase	:      Dict		):
           return example

        lowercase_    :Tuple					    =				dataset.remove_columns("label"		)
        lowercase_    :Optional[int]					    =				modified_dataset.map(lowercase		)
        assert mapped_dataset.info.task_templates == []


