





"""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_	:		List[Any]         =   {
    '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': [5_15]},
}





@pytest.mark.parametrize(
    'task_cls'					,   [
        AudioClassification,
        AutomaticSpeechRecognition,
        ImageClassification,
        LanguageModeling,
        QuestionAnsweringExtractive,
        Summarization,
        TextClassification,
    ]					,   )
def 		UpperCAmelCase__						(	_UpperCAmelCase   ):






  """simple docstring"""





  A_    :			str									=    task_cls()
  A_    :			Optional[int]									=    asdict(_UpperCAmelCase   )
  A_    :			Union[str, Any]									=    task_template_from_dict(_UpperCAmelCase   )
  assert task == reloaded

class 					_UpperCAmelCase    :



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			List[str]									=    LanguageModeling(text_column='input_text'    )
        assert {"input_text": "text"} == task.column_mapping

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			int									=    Features({'text': Value('string'    )}    )
        A_    :			Optional[int]									=    {'text_column': 'input_text'}
        A_    :			List[str]									=    LanguageModeling.from_dict(snake_case_    )
        assert "language-modeling" == task.task
        assert input_schema == task.input_schema


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Optional[Any]									=    sorted(['pos', 'neg']    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			int									=    TextClassification(text_column='input_text'   , label_column='input_label'    )
        self.assertDictEqual({'input_text': 'text', 'input_label': 'labels'}   , task.column_mapping    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

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

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Union[str, Any]									=    TextClassification(text_column='input_text'   , label_column='input_label'    )
        self.assertEqual(task.label_schema['labels']   , snake_case_    )
        A_    :			Optional[int]									=    task.align_with_features(Features({'input_label': ClassLabel(names=self.labels    )}    )    )
        self.assertEqual(task.label_schema['labels']   , ClassLabel(names=self.labels    )    )


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Dict									=    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    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Union[str, Any]									=    Features({'question': Value('string'    ), 'context': Value('string'    )}    )
        A_    :			Tuple									=    Features(
            {
                'answers': Sequence(
                    {
                        'text': Value('string'    ),
                        'answer_start': Value('int32'    ),
                    }    )
            }    )
        A_    :			int									=    {
            'context_column': 'input_input_context',
            'question_column': 'input_question',
            'answers_column': 'input_answers',
        }
        A_    :			Any									=    QuestionAnsweringExtractive.from_dict(snake_case_    )
        self.assertEqual('question-answering-extractive'   , task.task    )
        self.assertEqual(snake_case_   , task.input_schema    )
        self.assertEqual(snake_case_   , task.label_schema    )


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Union[str, Any]									=    Summarization(text_column='input_text'   , summary_column='input_summary'    )
        self.assertDictEqual({'input_text': 'text', 'input_summary': 'summary'}   , task.column_mapping    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			List[Any]									=    Features({'text': Value('string'    )}    )
        A_    :			Any									=    Features({'summary': Value('string'    )}    )
        A_    :			List[str]									=    {'text_column': 'input_text', 'summary_column': 'input_summary'}
        A_    :			Tuple									=    Summarization.from_dict(snake_case_    )
        self.assertEqual('summarization'   , task.task    )
        self.assertEqual(snake_case_   , task.input_schema    )
        self.assertEqual(snake_case_   , task.label_schema    )


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Optional[Any]									=    AutomaticSpeechRecognition(audio_column='input_audio'   , transcription_column='input_transcription'    )
        self.assertDictEqual({'input_audio': 'audio', 'input_transcription': 'transcription'}   , task.column_mapping    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Tuple									=    Features({'audio': Audio()}    )
        A_    :			List[Any]									=    Features({'transcription': Value('string'    )}    )
        A_    :			Tuple									=    {
            'audio_column': 'input_audio',
            'transcription_column': 'input_transcription',
        }
        A_    :			Any									=    AutomaticSpeechRecognition.from_dict(snake_case_    )
        self.assertEqual('automatic-speech-recognition'   , task.task    )
        self.assertEqual(snake_case_   , task.input_schema    )
        self.assertEqual(snake_case_   , task.label_schema    )


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Dict									=    sorted(['pos', 'neg']    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			str									=    AudioClassification(audio_column='input_audio'   , label_column='input_label'    )
        self.assertDictEqual({'input_audio': 'audio', 'input_label': 'labels'}   , task.column_mapping    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Tuple									=    Features({'audio': Audio()}    )
        A_    :			Optional[Any]									=    Features({'labels': ClassLabel}    )
        A_    :			Optional[Any]									=    {
            'audio_column': 'input_image',
            'label_column': 'input_label',
        }
        A_    :			Optional[Any]									=    AudioClassification.from_dict(snake_case_    )
        self.assertEqual('audio-classification'   , task.task    )
        self.assertEqual(snake_case_   , task.input_schema    )
        self.assertEqual(snake_case_   , task.label_schema    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Dict									=    AudioClassification(audio_column='input_audio'   , label_column='input_label'    )
        self.assertEqual(task.label_schema['labels']   , snake_case_    )
        A_    :			Optional[Any]									=    task.align_with_features(Features({'input_label': ClassLabel(names=self.labels    )}    )    )
        self.assertEqual(task.label_schema['labels']   , ClassLabel(names=self.labels    )    )


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			str									=    sorted(['pos', 'neg']    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Any									=    ImageClassification(image_column='input_image'   , label_column='input_label'    )
        self.assertDictEqual({'input_image': 'image', 'input_label': 'labels'}   , task.column_mapping    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			int									=    Features({'image': Image()}    )
        A_    :			List[Any]									=    Features({'labels': ClassLabel}    )
        A_    :			Any									=    {
            'image_column': 'input_image',
            'label_column': 'input_label',
        }
        A_    :			int									=    ImageClassification.from_dict(snake_case_    )
        self.assertEqual('image-classification'   , task.task    )
        self.assertEqual(snake_case_   , task.input_schema    )
        self.assertEqual(snake_case_   , task.label_schema    )

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Tuple									=    ImageClassification(image_column='input_image'   , label_column='input_label'    )
        self.assertEqual(task.label_schema['labels']   , snake_case_    )
        A_    :			Dict									=    task.align_with_features(Features({'input_label': ClassLabel(names=self.labels    )}    )    )
        self.assertEqual(task.label_schema['labels']   , ClassLabel(names=self.labels    )    )


class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

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

        def keep_task(snake_case_    ):
          return x

        def dont_keep_task(snake_case_    ):
          A_    :			int									=    deepcopy(snake_case_    )
          A_    :			Optional[Any]									=    0
          return out

        A_    :			List[str]									=    dataset.map(snake_case_    )
        assert mapped_dataset.info.task_templates == dataset.info.task_templates
        # reload from cache
        A_    :			Tuple									=    dataset.map(snake_case_    )
        assert mapped_dataset.info.task_templates == dataset.info.task_templates

        A_    :			str									=    dataset.map(snake_case_    )
        assert mapped_dataset.info.task_templates == []
        # reload from cache
        A_    :			Optional[Any]									=    dataset.map(snake_case_    )
        assert mapped_dataset.info.task_templates == []

      def    lowerCamelCase_     (	self    ):

        """simple docstring"""

        A_    :			Optional[int]									=    Features({'text': Value('string'    ), 'label': ClassLabel(names=('pos', 'neg')    )}    )
        A_    :			str									=    TextClassification(text_column='text'   , label_column='label'    )
        A_    :			List[str]									=    DatasetInfo(features=snake_case_   , task_templates=snake_case_    )
        A_    :			Tuple									=    Dataset.from_dict({'text': ['A sentence.'], 'label': ['pos']}   , info=snake_case_    )

        def process(snake_case_    ):
          return example

        A_    :			Optional[Any]									=    dataset.remove_columns('label'    )
        A_    :			str									=    modified_dataset.map(snake_case_    )
        assert mapped_dataset.info.task_templates == []






"""simple docstring"""




import warnings

from ...utils import logging
from .image_processing_detr import DetrImageProcessor


lowerCamelCase_	:		List[str]         =   logging.get_logger(__name__)

class 					_UpperCAmelCase    (  UpperCAmelCase__						):



      '''simple docstring'''

      def __init__(	self   , *snake_case_   , **snake_case_    ):

        """simple docstring"""

        warnings.warn(
            'The class DetrFeatureExtractor is deprecated and will be removed in version 5 of Transformers.'
            ' Please use DetrImageProcessor instead.'   , snake_case_   , )
        super().__init__(*snake_case_   , **snake_case_    )