



'''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


_UpperCamelCase  						=			{
    """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 			_lowerCAmelCase(      UpperCAmelCase_      :	int						) ->							Tuple:
							lowerCAmelCase__  =   task_cls()
							lowerCAmelCase__  =   asdict(UpperCAmelCase_						)
							lowerCAmelCase__  =   task_template_from_dict(UpperCAmelCase_						)
							assert task == reloaded

class      lowerCamelCase__     :






	'''simple docstring'''

	def      lowercase__							(  self		:  int					)     ->			List[str]:




								'''simple docstring'''





								lowerCAmelCase__  =   LanguageModeling(text_column="""input_text"""					)
								assert {"input_text": "text"} == task.column_mapping




	def      lowercase__							(  self		:  Dict					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""text""": Value("""string"""					)}					)
								lowerCAmelCase__  =   {"""text_column""": """input_text"""}
								lowerCAmelCase__  =   LanguageModeling.from_dict(__A					)
								assert "language-modeling" == task.task
								assert input_schema == task.input_schema





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  str					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   sorted(["""pos""", """neg"""]					)




	def      lowercase__							(  self		:  int					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   TextClassification(text_column="""input_text"""   ,		label_column="""input_label"""					)
								self.assertDictEqual({"""input_text""": """text""", """input_label""": """labels"""}   ,		task.column_mapping					)




	def      lowercase__							(  self		:  Optional[int]					)     ->			Tuple:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""text""": Value("""string"""					)}					)
								# Labels are cast to tuple during `TextClassification.__post_init__`, so we do the same here
								lowerCAmelCase__  =   Features({"""labels""": ClassLabel}					)
								lowerCAmelCase__  =   {"""text_column""": """input_text""", """label_column""": """input_labels"""}
								lowerCAmelCase__  =   TextClassification.from_dict(__A					)
								self.assertEqual("""text-classification"""   ,		task.task					)
								self.assertEqual(__A   ,		task.input_schema					)
								self.assertEqual(__A   ,		task.label_schema					)




	def      lowercase__							(  self		:  List[Any]					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   TextClassification(text_column="""input_text"""   ,		label_column="""input_label"""					)
								self.assertEqual(task.label_schema["""labels"""]   ,		__A					)
								lowerCAmelCase__  =   task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels					)}					)					)
								self.assertEqual(task.label_schema["""labels"""]   ,		ClassLabel(names=self.labels					)					)





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  int					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   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		:  str					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""question""": Value("""string"""					), """context""": Value("""string"""					)}					)
								lowerCAmelCase__  =   Features(
								    {
								        """answers""": Sequence(
								            {
								                """text""": Value("""string"""					),
								                """answer_start""": Value("""int32"""					),
								            }					)
								    }					)
								lowerCAmelCase__  =   {
								    """context_column""": """input_input_context""",
								    """question_column""": """input_question""",
								    """answers_column""": """input_answers""",
								}
								lowerCAmelCase__  =   QuestionAnsweringExtractive.from_dict(__A					)
								self.assertEqual("""question-answering-extractive"""   ,		task.task					)
								self.assertEqual(__A   ,		task.input_schema					)
								self.assertEqual(__A   ,		task.label_schema					)





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  Any					)     ->			Any:




								'''simple docstring'''





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




	def      lowercase__							(  self		:  Tuple					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""text""": Value("""string"""					)}					)
								lowerCAmelCase__  =   Features({"""summary""": Value("""string"""					)}					)
								lowerCAmelCase__  =   {"""text_column""": """input_text""", """summary_column""": """input_summary"""}
								lowerCAmelCase__  =   Summarization.from_dict(__A					)
								self.assertEqual("""summarization"""   ,		task.task					)
								self.assertEqual(__A   ,		task.input_schema					)
								self.assertEqual(__A   ,		task.label_schema					)





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  Optional[int]					)     ->			int:




								'''simple docstring'''





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




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




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""audio""": Audio()}					)
								lowerCAmelCase__  =   Features({"""transcription""": Value("""string"""					)}					)
								lowerCAmelCase__  =   {
								    """audio_column""": """input_audio""",
								    """transcription_column""": """input_transcription""",
								}
								lowerCAmelCase__  =   AutomaticSpeechRecognition.from_dict(__A					)
								self.assertEqual("""automatic-speech-recognition"""   ,		task.task					)
								self.assertEqual(__A   ,		task.input_schema					)
								self.assertEqual(__A   ,		task.label_schema					)





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  Dict					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   sorted(["""pos""", """neg"""]					)




	def      lowercase__							(  self		:  Any					)     ->			Any:




								'''simple docstring'''





								lowerCAmelCase__  =   AudioClassification(audio_column="""input_audio"""   ,		label_column="""input_label"""					)
								self.assertDictEqual({"""input_audio""": """audio""", """input_label""": """labels"""}   ,		task.column_mapping					)




	def      lowercase__							(  self		:  List[str]					)     ->			str:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""audio""": Audio()}					)
								lowerCAmelCase__  =   Features({"""labels""": ClassLabel}					)
								lowerCAmelCase__  =   {
								    """audio_column""": """input_image""",
								    """label_column""": """input_label""",
								}
								lowerCAmelCase__  =   AudioClassification.from_dict(__A					)
								self.assertEqual("""audio-classification"""   ,		task.task					)
								self.assertEqual(__A   ,		task.input_schema					)
								self.assertEqual(__A   ,		task.label_schema					)




	def      lowercase__							(  self		:  int					)     ->			List[Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   AudioClassification(audio_column="""input_audio"""   ,		label_column="""input_label"""					)
								self.assertEqual(task.label_schema["""labels"""]   ,		__A					)
								lowerCAmelCase__  =   task.align_with_features(Features({"""input_label""": ClassLabel(names=self.labels					)}					)					)
								self.assertEqual(task.label_schema["""labels"""]   ,		ClassLabel(names=self.labels					)					)





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

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




								'''simple docstring'''





								lowerCAmelCase__  =   sorted(["""pos""", """neg"""]					)




	def      lowercase__							(  self		:  List[Any]					)     ->			int:




								'''simple docstring'''





								lowerCAmelCase__  =   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]					)     ->			List[Any]:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""image""": Image()}					)
								lowerCAmelCase__  =   Features({"""labels""": ClassLabel}					)
								lowerCAmelCase__  =   {
								    """image_column""": """input_image""",
								    """label_column""": """input_label""",
								}
								lowerCAmelCase__  =   ImageClassification.from_dict(__A					)
								self.assertEqual("""image-classification"""   ,		task.task					)
								self.assertEqual(__A   ,		task.input_schema					)
								self.assertEqual(__A   ,		task.label_schema					)




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




								'''simple docstring'''





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





class      lowerCamelCase__     (     _A				):






	'''simple docstring'''

	def      lowercase__							(  self		:  Any					)     ->			Dict:




								'''simple docstring'''





								lowerCAmelCase__  =   DatasetInfo(task_templates=QuestionAnsweringExtractive()					)
								lowerCAmelCase__  =   Dataset.from_dict({k: [v] for k, v in SAMPLE_QUESTION_ANSWERING_EXTRACTIVE.items()}   ,		info=__A					)
								assert isinstance(dataset.info.task_templates   ,		__A					)
								assert len(dataset.info.task_templates					) == 1

								def keep_task(__A		:  Dict					):
															return x

								def dont_keep_task(__A		:  Any					):
															lowerCAmelCase__  =   deepcopy(__A					)
															lowerCAmelCase__  =   0
															return out

								lowerCAmelCase__  =   dataset.map(__A					)
								assert mapped_dataset.info.task_templates == dataset.info.task_templates
								# reload from cache
								lowerCAmelCase__  =   dataset.map(__A					)
								assert mapped_dataset.info.task_templates == dataset.info.task_templates

								lowerCAmelCase__  =   dataset.map(__A					)
								assert mapped_dataset.info.task_templates == []
								# reload from cache
								lowerCAmelCase__  =   dataset.map(__A					)
								assert mapped_dataset.info.task_templates == []




	def      lowercase__							(  self		:  Optional[int]					)     ->			Optional[int]:




								'''simple docstring'''





								lowerCAmelCase__  =   Features({"""text""": Value("""string"""					), """label""": ClassLabel(names=("""pos""", """neg""")					)}					)
								lowerCAmelCase__  =   TextClassification(text_column="""text"""   ,		label_column="""label"""					)
								lowerCAmelCase__  =   DatasetInfo(features=__A   ,		task_templates=__A					)
								lowerCAmelCase__  =   Dataset.from_dict({"""text""": ["""A sentence."""], """label""": ["""pos"""]}   ,		info=__A					)

								def process(__A		:  List[str]					):
															return example

								lowerCAmelCase__  =   dataset.remove_columns("""label"""					)
								lowerCAmelCase__  =   modified_dataset.map(__A					)
								assert mapped_dataset.info.task_templates == []










'''simple docstring'''







_UpperCamelCase  						=			{
    "kilogram": 1,
    "gram": pow(10, 3),
    "milligram": pow(10, 6),
    "metric-ton": pow(10, -3),
    "long-ton": 0.0009842073,
    "short-ton": 0.0011023122,
    "pound": 2.2046244202,
    "stone": 0.1574731728,
    "ounce": 35.273990723,
    "carrat": 5000,
    "atomic-mass-unit": 6.0_2213_6652e26,
}

_UpperCamelCase  						=			{
    "kilogram": 1,
    "gram": pow(10, -3),
    "milligram": pow(10, -6),
    "metric-ton": pow(10, 3),
    "long-ton": 1016.04608,
    "short-ton": 907.184,
    "pound": 0.453592,
    "stone": 6.35029,
    "ounce": 0.0283495,
    "carrat": 0.0002,
    "atomic-mass-unit": 1.6_6054_0199e-27,
}
def 			_lowerCAmelCase(      UpperCAmelCase_      :	str					, UpperCAmelCase_      :	str					, UpperCAmelCase_      :	float						) ->							float:
							if to_type not in KILOGRAM_CHART or from_type not in WEIGHT_TYPE_CHART:
														lowerCAmelCase__  =   (
														    F'''Invalid \'from_type\' or \'to_type\' value: {from_type!r}, {to_type!r}\n'''
														    F'''Supported values are: {", ".join(UpperCAmelCase_						)}'''
														)
														raise ValueError(UpperCAmelCase_						)
							return value * KILOGRAM_CHART[to_type] * WEIGHT_TYPE_CHART[from_type]


if __name__ == "__main__":
		import doctest

		doctest.testmod()





