code: 
  '''simple docstring'''
  
  import re
  import tempfile
  import unittest
  from pathlib import Path
  
  from datasets.utils.metadata import DatasetMetadata
  
  
  def 	_UpperCAmelCase				(  _lowerCamelCase						:       str		)    ->						str:
    _lowerCAmelCase       :  List[str]   				=					min(re.search("""^ +"""  ,      _lowerCamelCase		).end() if t.startswith(""" """		) else 0 for t in string.splitlines()		)
    return "\n".join([line[indent_level:] for line in string.splitlines() if indent_level < len(_lowerCamelCase		)]		)
  
  
  UpperCamelCase_     			=       """\
  ---
  language:
  - zh
  - en
  task_ids:
  - sentiment-classification
  ---
  # Begin of markdown
  
  Some cool dataset card
  """
  
  UpperCamelCase_     			=       """\
  ---
  ---
  # Begin of markdown
  
  Some cool dataset card
  """
  
  
  UpperCamelCase_     			=       """\
  # Begin of markdown
  
  Some cool dataset card
  """
  
  
  
  class   a_  (unittest.TestCase    ):
  
  
  
  
         def 							__UpperCamelCase       (     self  ):
           with tempfile.TemporaryDirectory() as tmp_dir:
             _lowerCAmelCase       :  Union[str, Any]   				=					Path(snake_case_  ) / """README.md"""
             with open(snake_case_   ,   """w+"""  ) as readme_file:
               readme_file.write(snake_case_  )
             _lowerCAmelCase       :  Any   				=					DatasetMetadata.from_readme(snake_case_  )
             self.assertDictEqual(snake_case_   ,   {"""language""": ["""zh""", """en"""], """task_ids""": ["""sentiment-classification"""]}  )
  
             with open(snake_case_   ,   """w+"""  ) as readme_file:
               readme_file.write(snake_case_  )
             _lowerCAmelCase       :  Any   				=					DatasetMetadata.from_readme(snake_case_  )
             self.assertDictEqual(snake_case_   ,   {}  )
  
             with open(snake_case_   ,   """w+"""  ) as readme_file:
               readme_file.write(snake_case_  )
             _lowerCAmelCase       :  str   				=					DatasetMetadata.from_readme(snake_case_  )
             self.assertEqual(snake_case_   ,   {}  )
  
  
  
  
  
  
  
         def 							__UpperCamelCase       (     self  ):
           _lowerCAmelCase       :  List[Any]   				=					_dedent(
               """\
              annotations_creators:
              - found
              language_creators:
              - found
              language:
              - en
              license:
              - unknown
              multilinguality:
              - monolingual
              pretty_name: Test Dataset
              size_categories:
              - 10K<n<100K
              source_datasets:
              - extended|other-yahoo-webscope-l6
              task_categories:
              - question-answering
              task_ids:
              - open-domain-qa
              """  )
           assert DatasetMetadata.from_yaml_string(snake_case_  )
  
           _lowerCAmelCase       :  Any   				=					_dedent(
               """\
              annotations_creators:
              - found
              language:
              - en
              license:
              - unknown
              multilinguality:
              - monolingual
              pretty_name: Test Dataset
              size_categories:
              - 10K<n<100K
              source_datasets:
              - extended|other-yahoo-webscope-l6
              task_categories:
              - question-answering
              task_ids:
              - open-domain-qa
              task_ids:
              - open-domain-qa
              """  )
           with self.assertRaises(snake_case_  ):
             DatasetMetadata.from_yaml_string(snake_case_  )
  
           _lowerCAmelCase       :  List[str]   				=					_dedent(
               """\
              annotations_creators:
              - found
              language_creators:
              - found
              language:
              - en
              license:
              - unknown
              multilinguality:
              - monolingual
              pretty_name: Test Dataset
              size_categories:
              - 10K<n<100K
              source_datasets:
              - extended|other-yahoo-webscope-l6
              task_categories:
              - text-classification
              task_ids:
              - multi-class-classification
              paperswithcode_id:
              - squad
              configs:
              - en
              train-eval-index:
              - config: en
                task: text-classification
                task_id: multi_class_classification
                splits:
                  train_split: train
                  eval_split: test
                col_mapping:
                  text: text
                  label: target
                metrics:
                  - type: accuracy
                    name: Accuracy
              extra_gated_prompt: |
                By clicking on “Access repository” below, you also agree to ImageNet Terms of Access:
                [RESEARCHER_FULLNAME] (the \"Researcher\") has requested permission to use the ImageNet database (the \"Database\") at Princeton University and Stanford University. In exchange for such permission, Researcher hereby agrees to the following terms and conditions:
                1. Researcher shall use the Database only for non-commercial research and educational purposes.
              extra_gated_fields:
                Company: text
                Country: text
                I agree to use this model for non-commerical use ONLY: checkbox
              """  )
           assert DatasetMetadata.from_yaml_string(snake_case_  )
  
  
  
style_context: 
  '''simple docstring'''
  
  import sys
  from collections.abc import Mapping
  
  import numpy as np
  import pyarrow as pa
  
  from .. import config
  from ..utils.py_utils import map_nested
  from .formatting import TensorFormatter
  
  
  class   a_  (TensorFormatter[Mapping, np.ndarray, Mapping]    ):
  
  
  
  
         def __init__(     self   ,   snake_case_=None   ,   **snake_case_  ):
           super().__init__(features=snake_case_  )
           _lowerCAmelCase       :  Any   				=					np_array_kwargs
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           if isinstance(snake_case_   ,   snake_case_  ):
             if column and all(
                 isinstance(snake_case_   ,   np.ndarray  ) and x.shape == column[0].shape and x.dtype == column[0].dtype for x in column  ):
               return np.stack(snake_case_  )
             else:
               # don't use np.array(column, dtype=object)
               # since it fails in certain cases
               # see https://stackoverflow.com/q/51005699
               _lowerCAmelCase       :  str   				=					np.empty(len(snake_case_  )   ,   dtype=snake_case_  )
               _lowerCAmelCase       :  List[Any]   				=					column
               return out
           return column
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           if isinstance(snake_case_   ,   (str, bytes, type(snake_case_  ))  ):
             return value
           elif isinstance(snake_case_   ,   (np.character, np.ndarray)  ) and np.issubdtype(value.dtype   ,   np.character  ):
             return value
           elif isinstance(snake_case_   ,   np.number  ):
             return value
  
           _lowerCAmelCase       :  List[Any]   				=					{}
  
           if isinstance(snake_case_   ,   np.ndarray  ) and np.issubdtype(value.dtype   ,   np.integer  ):
             _lowerCAmelCase       :  Union[str, Any]   				=					{"""dtype""": np.intaa}
           elif isinstance(snake_case_   ,   np.ndarray  ) and np.issubdtype(value.dtype   ,   np.floating  ):
             _lowerCAmelCase       :  Tuple   				=					{"""dtype""": np.floataa}
           elif config.PIL_AVAILABLE and "PIL" in sys.modules:
             import PIL.Image
  
             if isinstance(snake_case_   ,   PIL.Image.Image  ):
               return np.asarray(snake_case_   ,   **self.np_array_kwargs  )
  
           return np.asarray(snake_case_   ,   **{**default_dtype, **self.np_array_kwargs}  )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           # support for torch, tf, jax etc.
           if config.TORCH_AVAILABLE and "torch" in sys.modules:
             import torch
  
             if isinstance(snake_case_   ,   torch.Tensor  ):
               return self._tensorize(data_struct.detach().cpu().numpy()[()]  )
           if hasattr(snake_case_   ,   """__array__"""  ) and not isinstance(snake_case_   ,   (np.ndarray, np.character, np.number)  ):
             _lowerCAmelCase       :  List[Any]   				=					data_struct.__array__()
           # support for nested types like struct of list of struct
           if isinstance(snake_case_   ,   np.ndarray  ):
             if data_struct.dtype == object:
               return self._consolidate([self.recursive_tensorize(snake_case_  ) for substruct in data_struct]  )
           if isinstance(snake_case_   ,   (list, tuple)  ):
             return self._consolidate([self.recursive_tensorize(snake_case_  ) for substruct in data_struct]  )
           return self._tensorize(snake_case_  )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           return map_nested(self._recursive_tensorize   ,   snake_case_   ,   map_list=snake_case_  )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           _lowerCAmelCase       :  Optional[Any]   				=					self.numpy_arrow_extractor().extract_row(snake_case_  )
           _lowerCAmelCase       :  Any   				=					self.python_features_decoder.decode_row(snake_case_  )
           return self.recursive_tensorize(snake_case_  )
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           _lowerCAmelCase       :  List[Any]   				=					self.numpy_arrow_extractor().extract_column(snake_case_  )
           _lowerCAmelCase       :  Tuple   				=					self.python_features_decoder.decode_column(snake_case_   ,   pa_table.column_names[0]  )
           _lowerCAmelCase       :  Optional[int]   				=					self.recursive_tensorize(snake_case_  )
           _lowerCAmelCase       :  Optional[Any]   				=					self._consolidate(snake_case_  )
           return column
  
  
  
  
  
  
  
         def 							__UpperCamelCase       (     self   ,   snake_case_  ):
           _lowerCAmelCase       :  List[Any]   				=					self.numpy_arrow_extractor().extract_batch(snake_case_  )
           _lowerCAmelCase       :  str   				=					self.python_features_decoder.decode_batch(snake_case_  )
           _lowerCAmelCase       :  Dict   				=					self.recursive_tensorize(snake_case_  )
           for column_name in batch:
             _lowerCAmelCase       :  int   				=					self._consolidate(batch[column_name]  )
           return batch
  
  
  