






"""simple docstring"""
import random
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin, prepare_image_inputs


if is_torch_available():
      import torch

if is_vision_available():
      import PIL

      from transformers import FlavaImageProcessor
      from transformers.image_utils import PILImageResampling
      from transformers.models.flava.image_processing_flava import (
          FLAVA_CODEBOOK_MEAN,
          FLAVA_CODEBOOK_STD,
          FLAVA_IMAGE_MEAN,
          FLAVA_IMAGE_STD,
      )
else:
      A_			: str				=			None



class 		a_      (	unittest.TestCase ):







      '''simple docstring'''

      def __init__(self,     lowerCamelCase_,     lowerCamelCase_=7,     lowerCamelCase_=3,     lowerCamelCase_=3_0,     lowerCamelCase_=4_0_0,     lowerCamelCase_=True,     lowerCamelCase_=None,     lowerCamelCase_=True,     lowerCamelCase_=None,     lowerCamelCase_=None,     lowerCamelCase_=True,     lowerCamelCase_=1 / 2_5_5,     lowerCamelCase_=True,     lowerCamelCase_=FLAVA_IMAGE_MEAN,     lowerCamelCase_=FLAVA_IMAGE_STD,     lowerCamelCase_=1_4,     lowerCamelCase_=7_5,     lowerCamelCase_=None,     lowerCamelCase_=1_6,     lowerCamelCase_=0.3,     lowerCamelCase_=None,     lowerCamelCase_=True,     lowerCamelCase_=None,     lowerCamelCase_=None,     lowerCamelCase_=True,     lowerCamelCase_=None,     lowerCamelCase_=True,     lowerCamelCase_=True,     lowerCamelCase_=FLAVA_CODEBOOK_MEAN,     lowerCamelCase_=FLAVA_CODEBOOK_STD,     ):

       '''simple docstring'''



       lowerCamelCase__     :			List[str]     				=						size if size is not None else {'height': 2_2_4, 'width': 2_2_4}
       lowerCamelCase__     :			Optional[Any]     				=						crop_size if crop_size is not None else {'height': 2_2_4, 'width': 2_2_4}
       lowerCamelCase__     :			List[str]     				=						codebook_size if codebook_size is not None else {'height': 1_1_2, 'width': 1_1_2}
       lowerCamelCase__     :			Union[str, Any]     				=						codebook_crop_size if codebook_crop_size is not None else {'height': 1_1_2, 'width': 1_1_2}

       lowerCamelCase__     :			Tuple     				=						parent
       lowerCamelCase__     :			int     				=						batch_size
       lowerCamelCase__     :			List[str]     				=						num_channels
       lowerCamelCase__     :			Dict     				=						do_resize
       lowerCamelCase__     :			List[str]     				=						do_rescale
       lowerCamelCase__     :			str     				=						rescale_factor
       lowerCamelCase__     :			List[str]     				=						min_resolution
       lowerCamelCase__     :			Optional[int]     				=						max_resolution
       lowerCamelCase__     :			Optional[int]     				=						size
       lowerCamelCase__     :			Optional[int]     				=						resample if resample is not None else PILImageResampling.BICUBIC
       lowerCamelCase__     :			List[Any]     				=						do_normalize
       lowerCamelCase__     :			Any     				=						image_mean
       lowerCamelCase__     :			List[Any]     				=						image_std
       lowerCamelCase__     :			Dict     				=						do_center_crop
       lowerCamelCase__     :			Optional[Any]     				=						crop_size

       lowerCamelCase__     :			Optional[int]     				=						input_size_patches
       lowerCamelCase__     :			Optional[Any]     				=						total_mask_patches
       lowerCamelCase__     :			List[str]     				=						mask_group_max_patches
       lowerCamelCase__     :			Any     				=						mask_group_min_patches
       lowerCamelCase__     :			Tuple     				=						mask_group_min_aspect_ratio
       lowerCamelCase__     :			List[Any]     				=						mask_group_max_aspect_ratio

       lowerCamelCase__     :			List[Any]     				=						codebook_do_resize
       lowerCamelCase__     :			Optional[Any]     				=						codebook_size
       lowerCamelCase__     :			str     				=						codebook_resample if codebook_resample is not None else PILImageResampling.LANCZOS
       lowerCamelCase__     :			Dict     				=						codebook_do_center_crop
       lowerCamelCase__     :			Tuple     				=						codebook_crop_size
       lowerCamelCase__     :			Union[str, Any]     				=						codebook_do_map_pixels
       lowerCamelCase__     :			Dict     				=						codebook_do_normalize
       lowerCamelCase__     :			Union[str, Any]     				=						codebook_image_mean
       lowerCamelCase__     :			str     				=						codebook_image_std




      def 			a__							(self					):

       '''simple docstring'''



       return {
           "image_mean": self.image_mean,
           "image_std": self.image_std,
           "do_normalize": self.do_normalize,
           "do_resize": self.do_resize,
           "size": self.size,
           "resample": self.resample,
           "do_rescale": self.do_rescale,
           "rescale_factor": self.rescale_factor,
           "do_center_crop": self.do_center_crop,
           "crop_size": self.crop_size,
           "input_size_patches": self.input_size_patches,
           "total_mask_patches": self.total_mask_patches,
           "mask_group_max_patches": self.mask_group_max_patches,
           "mask_group_min_patches": self.mask_group_min_patches,
           "mask_group_min_aspect_ratio": self.mask_group_min_aspect_ratio,
           "mask_group_max_aspect_ratio": self.mask_group_min_aspect_ratio,
           "codebook_do_resize": self.codebook_do_resize,
           "codebook_size": self.codebook_size,
           "codebook_resample": self.codebook_resample,
           "codebook_do_center_crop": self.codebook_do_center_crop,
           "codebook_crop_size": self.codebook_crop_size,
           "codebook_do_map_pixels": self.codebook_do_map_pixels,
           "codebook_do_normalize": self.codebook_do_normalize,
           "codebook_image_mean": self.codebook_image_mean,
           "codebook_image_std": self.codebook_image_std,
       }




      def 			a__							(self					):

       '''simple docstring'''



       return (self.size["height"], self.size["width"])




      def 			a__							(self					):

       '''simple docstring'''



       return (
           (self.input_size_patches, self.input_size_patches)
           if not isinstance(self.input_size_patches,     lowerCamelCase_					)
           else self.input_size_patches
       )





      def 			a__							(self					):

       '''simple docstring'''



       return (self.codebook_size["height"], self.codebook_size["width"])



@require_torch
@require_vision
class 		a_      (	snake_case_  ,						unittest.TestCase ):







      '''simple docstring'''

      lowerCamelCase__       :				Optional[int] =	FlavaImageProcessor if is_vision_available() else None
      lowerCamelCase__       :				Dict =	None




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Tuple     				=						FlavaImageProcessingTester(self					)




      @property
      def 			a__							(self					):

       '''simple docstring'''



       return self.image_processor_tester.prepare_image_processor_dict()




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Tuple     				=						self.image_processing_class(**self.image_processor_dict					)
       self.assertTrue(hasattr(lowerCamelCase_,     'image_mean'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'image_std'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'do_normalize'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'do_resize'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'resample'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'crop_size'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'do_center_crop'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'do_rescale'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'rescale_factor'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'masking_generator'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_do_resize'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_size'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_resample'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_do_center_crop'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_crop_size'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_do_map_pixels'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_do_normalize'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_image_mean'					)					)
       self.assertTrue(hasattr(lowerCamelCase_,     'codebook_image_std'					)					)




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Tuple     				=						self.image_processing_class.from_dict(self.image_processor_dict					)
       self.assertEqual(image_processor.size,     {'height': 2_2_4, 'width': 2_2_4}					)
       self.assertEqual(image_processor.crop_size,     {'height': 2_2_4, 'width': 2_2_4}					)
       self.assertEqual(image_processor.codebook_size,     {'height': 1_1_2, 'width': 1_1_2}					)
       self.assertEqual(image_processor.codebook_crop_size,     {'height': 1_1_2, 'width': 1_1_2}					)

       lowerCamelCase__     :			List[str]     				=						self.image_processing_class.from_dict(
           self.image_processor_dict,     size=4_2,     crop_size=8_4,     codebook_size=3_3,     codebook_crop_size=6_6					)
       self.assertEqual(image_processor.size,     {'height': 4_2, 'width': 4_2}					)
       self.assertEqual(image_processor.crop_size,     {'height': 8_4, 'width': 8_4}					)
       self.assertEqual(image_processor.codebook_size,     {'height': 3_3, 'width': 3_3}					)
       self.assertEqual(image_processor.codebook_crop_size,     {'height': 6_6, 'width': 6_6}					)




      def 			a__							(self					):

       '''simple docstring'''



       pass




      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Dict     				=						self.image_processing_class(**self.image_processor_dict					)
       # create random PIL images
       lowerCamelCase__     :			List[str]     				=						prepare_image_inputs(self.image_processor_tester,     equal_resolution=lowerCamelCase_					)
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase_,     PIL.Image.Image					)

       # Test not batched input
       lowerCamelCase__     :			List[Any]     				=						image_processing(image_inputs[0],     return_tensors='pt'					)

       # Test no bool masked pos
       self.assertFalse('bool_masked_pos' in encoded_images					)

       lowerCamelCase__				,     lowerCamelCase__     :			List[Any]     				=						self.image_processor_tester.get_expected_image_size()

       self.assertEqual(
           encoded_images.pixel_values.shape,     (1, self.image_processor_tester.num_channels, expected_height, expected_width),     )

       # Test batched
       lowerCamelCase__     :			str     				=						image_processing(lowerCamelCase_,     return_tensors='pt'					)
       lowerCamelCase__				,     lowerCamelCase__     :			Optional[Any]     				=						self.image_processor_tester.get_expected_image_size()

       # Test no bool masked pos
       self.assertFalse('bool_masked_pos' in encoded_images					)

       self.assertEqual(
           encoded_images.pixel_values.shape,     (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ),     )




      def 			a__							(self,     lowerCamelCase_,     lowerCamelCase_					):

       '''simple docstring'''



       lowerCamelCase__     :			List[str]     				=						self.image_processing_class(**self.image_processor_dict					)
       # create random tensors
       lowerCamelCase__     :			str     				=						prepare_image_inputs(self.image_processor_tester,     equal_resolution=lowerCamelCase_,     **lowerCamelCase_					)
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase_,     lowerCamelCase_					)

       # Test not batched input
       lowerCamelCase__     :			Optional[int]     				=						image_processing(image_inputs[0],     return_tensors='pt'					)

       lowerCamelCase__				,     lowerCamelCase__     :			Dict     				=						self.image_processor_tester.get_expected_image_size()
       self.assertEqual(
           encoded_images.pixel_values.shape,     (1, self.image_processor_tester.num_channels, expected_height, expected_width),     )

       lowerCamelCase__     :			int     				=						image_processing(lowerCamelCase_,     return_image_mask=lowerCamelCase_,     return_tensors='pt'					)

       lowerCamelCase__				,     lowerCamelCase__     :			List[str]     				=						self.image_processor_tester.get_expected_image_size()
       self.assertEqual(
           encoded_images.pixel_values.shape,     (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ),     )

       lowerCamelCase__				,     lowerCamelCase__     :			Dict     				=						self.image_processor_tester.get_expected_mask_size()
       self.assertEqual(
           encoded_images.bool_masked_pos.shape,     (
               self.image_processor_tester.batch_size,
               expected_height,
               expected_width,
           ),     )

       # Test batched
       lowerCamelCase__     :			List[Any]     				=						image_processing(lowerCamelCase_,     return_tensors='pt'					).pixel_values

       lowerCamelCase__				,     lowerCamelCase__     :			List[str]     				=						self.image_processor_tester.get_expected_image_size()
       self.assertEqual(
           encoded_images.shape,     (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ),     )

       # Test masking
       lowerCamelCase__     :			Optional[Any]     				=						image_processing(lowerCamelCase_,     return_image_mask=lowerCamelCase_,     return_tensors='pt'					)

       lowerCamelCase__				,     lowerCamelCase__     :			str     				=						self.image_processor_tester.get_expected_image_size()
       self.assertEqual(
           encoded_images.pixel_values.shape,     (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ),     )

       lowerCamelCase__				,     lowerCamelCase__     :			Tuple     				=						self.image_processor_tester.get_expected_mask_size()
       self.assertEqual(
           encoded_images.bool_masked_pos.shape,     (
               self.image_processor_tester.batch_size,
               expected_height,
               expected_width,
           ),     )




      def 			a__							(self					):

       '''simple docstring'''



       self._test_call_framework(np.ndarray,     prepare_kwargs={'numpify': True}					)




      def 			a__							(self					):

       '''simple docstring'''



       self._test_call_framework(torch.Tensor,     prepare_kwargs={'torchify': True}					)




      def 			a__							(self					):

       '''simple docstring'''



       random.seed(1_2_3_4					)
       lowerCamelCase__     :			str     				=						self.image_processing_class(**self.image_processor_dict					)
       lowerCamelCase__     :			Tuple     				=						prepare_image_inputs(self.image_processor_tester,     equal_resolution=lowerCamelCase_,     torchify=lowerCamelCase_					)

       # Test not batched input
       lowerCamelCase__     :			int     				=						image_processing(image_inputs[0],     return_image_mask=lowerCamelCase_,     return_tensors='pt'					)
       self.assertEqual(encoded_images.bool_masked_pos.sum().item(),     7_5					)





      def 			a__							(self					):

       '''simple docstring'''



       lowerCamelCase__     :			Union[str, Any]     				=						self.image_processing_class(**self.image_processor_dict					)
       # create random PIL images
       lowerCamelCase__     :			Union[str, Any]     				=						prepare_image_inputs(self.image_processor_tester,     equal_resolution=lowerCamelCase_					)
       for image in image_inputs:
        self.assertIsInstance(lowerCamelCase_,     PIL.Image.Image					)

       # Test not batched input
       lowerCamelCase__     :			int     				=						image_processing(image_inputs[0],     return_codebook_pixels=lowerCamelCase_,     return_tensors='pt'					)
       lowerCamelCase__				,     lowerCamelCase__     :			List[Any]     				=						self.image_processor_tester.get_expected_codebook_image_size()
       self.assertEqual(
           encoded_images.codebook_pixel_values.shape,     (1, self.image_processor_tester.num_channels, expected_height, expected_width),     )

       # Test batched
       lowerCamelCase__     :			Optional[Any]     				=						image_processing(lowerCamelCase_,     return_codebook_pixels=lowerCamelCase_,     return_tensors='pt'					)
       lowerCamelCase__				,     lowerCamelCase__     :			Optional[Any]     				=						self.image_processor_tester.get_expected_codebook_image_size()
       self.assertEqual(
           encoded_images.codebook_pixel_values.shape,     (
               self.image_processor_tester.batch_size,
               self.image_processor_tester.num_channels,
               expected_height,
               expected_width,
           ),     )




import logging
from pathlib import Path
from typing import Any, List, Tuple

import yaml


# loading package files: https://stackoverflow.com/a/20885799
try:
 import importlib.resources as pkg_resources
except ImportError:
 # Try backported to PY<37 `importlib_resources`.
 import importlib_resources as pkg_resources

from . import resources


_UpperCamelCase			       =			'''https://github.com/huggingface/datasets/tree/main/src/datasets/utils'''
_UpperCamelCase			       =			F"""{BASE_REF_URL}/{__file__}"""
_UpperCamelCase			       =			logging.getLogger(__name__)
def 						UpperCamelCase_(			snake_case__:  str   )       -> Tuple[Any, str]:
 UpperCAmelCase__							=				pkg_resources.read_text(snake_case__  ,    snake_case__   )
 return yaml.safe_load(snake_case__   ), f"{BASE_REF_URL}/resources/{resource}"


_UpperCamelCase       ,				_UpperCamelCase			       =			load_yaml_resource('''readme_structure.yaml''')

_UpperCamelCase			       =			[
    '''[Needs More Information]''',
    '''[More Information Needed]''',
    '''(https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)''',
]

# Dictionary representation of section/readme, error_list, warning_list
_UpperCamelCase			       =			Tuple[dict, List[str], List[str]]



class     lowercase						:



 '''simple docstring'''


 def __init__(self       ,       __a       ,       __a       ,       __a = None       ,       __a = False ) ->					List[str]:






  """simple docstring"""





  UpperCAmelCase__							=				name
  UpperCAmelCase__							=				level
  UpperCAmelCase__							=				lines
  UpperCAmelCase__							=				''
  UpperCAmelCase__							=				True
  UpperCAmelCase__							=				{}
  UpperCAmelCase__							=				[]
  UpperCAmelCase__							=				[]
  if self.lines is not None:
   self.parse(suppress_parsing_errors=__a )




 def   UpperCamelCase__							(self       ,       __a = False ) ->					Tuple:






  """simple docstring"""





  UpperCAmelCase__							=				''
  UpperCAmelCase__							=				[]
  UpperCAmelCase__							=				False
  for line in self.lines:
   if line.strip(' \n' ) == "":
    continue
   elif line.strip(' \n' )[:3] == "```":
    UpperCAmelCase__							=				not code_start
   elif line.split()[0] == self.level + "#" and not code_start:
    if current_sub_level != "":
     UpperCAmelCase__							=				Section(__a       ,       self.level + '#'       ,       __a )
     UpperCAmelCase__							=				[]
    else:
     if current_lines != []:
      self.text += "".join(__a ).strip()
      if self.text != "" and self.text not in FILLER_TEXT:
       UpperCAmelCase__							=				False
      UpperCAmelCase__							=				[]

    UpperCAmelCase__							=				' '.join(line.split()[1:] ).strip(' \n' )
   else:
    current_lines.append(__a )
  else:
   if current_sub_level != "":
    if current_sub_level in self.content:
     self.parsing_error_list.append(
         F"Multiple sections with the same heading `{current_sub_level}` have been found. Please keep only one of these sections." )
    UpperCAmelCase__							=				Section(__a       ,       self.level + '#'       ,       __a )
   else:
    if current_lines != []:
     self.text += "".join(__a ).strip()
     if self.text != "" and self.text not in FILLER_TEXT:
      UpperCAmelCase__							=				False

  if self.level == "" and not suppress_parsing_errors:
   if self.parsing_error_list != [] or self.parsing_warning_list != []:
    UpperCAmelCase__							=				UpperCAmelCase__							=				'\n'.join('-\t' + x for x in self.parsing_error_list + self.parsing_warning_list )
    UpperCAmelCase__							=				F"The following issues were found while parsing the README at `{self.name}`:\n" + errors
    raise ValueError(__a )




 def   UpperCamelCase__							(self       ,       __a ) ->					ReadmeValidatorOutput:






  """simple docstring"""





  UpperCAmelCase__							=				[]
  UpperCAmelCase__							=				[]
  if structure["allow_empty"] is False:
   # If content is expected
   if self.is_empty_text and self.content == {}:
    # If no content is found, mention it in the error_list
    error_list.append(F"Expected some content in section `{self.name}` but it is empty." )

  if structure["allow_empty_text"] is False:
   # If some text is expected
   if self.is_empty_text:
    # If no text is found, mention it in the error_list
    error_list.append(
        F"Expected some text in section `{self.name}` but it is empty (text in subsections are ignored)." )
        # Subsections Validation
  if structure["subsections"] is not None:
   # If subsections are expected
   if self.content == {}:
    # If no subsections are present
    UpperCAmelCase__							=				[subsection['name'] for subsection in structure['subsections']]
    # Mention the expected values in the error_list
    error_list.append(
        F"Section `{self.name}` expected the following subsections: {', '.join(['`'+x+'`' for x in values] )}. Found 'None'." )
   else:
    # If some subsections are present
    UpperCAmelCase__							=				[subsection['name'] for subsection in structure['subsections']]
    UpperCAmelCase__							=				False
    for idx, name in enumerate(__a ):
     if name not in self.content:
      # If the expected subsection is not present
      error_list.append(F"Section `{self.name}` is missing subsection: `{name}`." )
      UpperCAmelCase__							=				True
     else:
      # If the subsection is present, validate subsection, return the result
      # and concat the errors from subsection to section error_list

      # Skip sublevel validation if current level is `###`
      if self.level == "###":
       continue
      else:
       UpperCAmelCase__				,    UpperCAmelCase__				,    UpperCAmelCase__							=				self.content[name].validate(
           structure['subsections'][idx] )
      error_list += subsec_error_list
      warning_list += subsec_warning_list

    if has_missing_subsections:  # we only allow to have extra subsections if all the other ones are here
     for name in self.content:
      if name not in structure_names:
       # If an extra subsection is present
       warning_list.append(
           F"`{self.name}` has an extra subsection: `{name}`. Skipping further validation checks for this subsection as expected structure is unknown." )
  if error_list:
   # If there are errors, do not return the dictionary as it is invalid
   return {}, error_list, warning_list
  else:
   return self.to_dict(), error_list, warning_list




 def   UpperCamelCase__							(self ) ->					dict:






  """simple docstring"""





  return {
      "name": self.name,
      "text": self.text,
      "is_empty_text": self.is_empty_text,
      "subsections": [value.to_dict() for value in self.content.values()],
  }







class     lowercase						(       _UpperCamelCase					):  # Level 0



 '''simple docstring'''


 def __init__(self       ,       __a       ,       __a       ,       __a = None       ,       __a = False ) ->					Optional[int]:






  """simple docstring"""





  super().__init__(name=__a       ,       level='' )  # Not using lines here as we need to use a child class parse
  UpperCAmelCase__							=				structure
  UpperCAmelCase__							=				-2
  UpperCAmelCase__							=				0
  UpperCAmelCase__							=				lines
  if self.lines is not None:
   self.parse(suppress_parsing_errors=__a )




 def   UpperCamelCase__							(self ) ->					int:






  """simple docstring"""





  if self.structure is None:
   UpperCAmelCase__				,    UpperCAmelCase__				,    UpperCAmelCase__							=				self._validate(__a )
  else:
   UpperCAmelCase__				,    UpperCAmelCase__				,    UpperCAmelCase__							=				self._validate(self.structure )
  if error_list != [] or warning_list != []:
   UpperCAmelCase__							=				'\n'.join(['-\t' + x for x in error_list + warning_list] )
   UpperCAmelCase__							=				F"The following issues were found for the README at `{self.name}`:\n" + errors
   raise ValueError(__a )




 @classmethod
 def   UpperCamelCase__							(cls       ,       __a       ,       __a = None       ,       __a = False ) ->					List[str]:






  """simple docstring"""





  with open(__a       ,       encoding='utf-8' ) as f:
   UpperCAmelCase__							=				f.readlines()
  return cls(__a       ,       __a       ,       __a       ,       suppress_parsing_errors=__a )




 @classmethod
 def   UpperCamelCase__							(cls       ,       __a       ,       __a = None       ,       __a = "root"       ,       __a = False ) ->					Dict:






  """simple docstring"""





  UpperCAmelCase__							=				string.split('\n' )
  return cls(__a       ,       __a       ,       __a       ,       suppress_parsing_errors=__a )




 def   UpperCamelCase__							(self       ,       __a = False ) ->					Optional[Any]:






  """simple docstring"""





  UpperCAmelCase__							=				0

  for line in self.lines:
   self.yaml_tags_line_count += 1
   if line.strip(' \n' ) == "---":
    self.tag_count += 1
    if self.tag_count == 2:
     break
   line_count += 1
  if self.tag_count == 2:
   UpperCAmelCase__							=				self.lines[line_count + 1 :]  # Get the last + 1 th item.
  else:
   UpperCAmelCase__							=				self.lines[self.tag_count :]
  super().parse(suppress_parsing_errors=__a )




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






  """simple docstring"""





  return str(self.to_dict() )




 def   UpperCamelCase__							(self       ,       __a ) ->					Tuple:






  """simple docstring"""





  UpperCAmelCase__							=				[]
  UpperCAmelCase__							=				[]
  if self.yaml_tags_line_count == 0:
   warning_list.append('Empty YAML markers are present in the README.' )
  elif self.tag_count == 0:
   warning_list.append('No YAML markers are present in the README.' )
  elif self.tag_count == 1:
   warning_list.append('Only the start of YAML tags present in the README.' )
  # Check how many first level sections are present.
  UpperCAmelCase__							=				len(self.content.keys() )
  if num_first_level_keys > 1:
   # If more than one, add to the error list, continue
   error_list.append(
       F"The README has several first-level headings: {', '.join(['`'+x+'`' for x in list(self.content.keys() )] )}. Only one heading is expected. Skipping further validation for this README." )
  elif num_first_level_keys < 1:
   # If less than one, append error.
   error_list.append(
       'The README has no first-level headings. One heading is expected. Skipping further validation for this README.' )

  else:
   # If one exactly
   UpperCAmelCase__							=				list(self.content.keys() )[0]  # Get the key
   if start_key.startswith('Dataset Card for' ):  # Check correct start
    # If the starting is correct, validate all the sections
    UpperCAmelCase__				,    UpperCAmelCase__				,    UpperCAmelCase__							=				self.content[start_key].validate(
        readme_structure['subsections'][0] )
    error_list += sec_error_list
    warning_list += sec_warning_list
   else:
    # If not found, append error
    error_list.append(
        'No first-level heading starting with `Dataset Card for` found in README. Skipping further validation for this README.' )
  if error_list:
   # If there are errors, do not return the dictionary as it is invalid
   return {}, error_list, warning_list
  else:
   return self.to_dict(), error_list, warning_list


if __name__ == "__main__":
 from argparse import ArgumentParser

 _UpperCamelCase			       =			ArgumentParser(usage='''Validate the content (excluding YAML tags) of a README.md file.''')
 ap.add_argument('''readme_filepath''')
 _UpperCamelCase			       =			ap.parse_args()
 _UpperCamelCase			       =			Path(args.readme_filepath)
 _UpperCamelCase			       =			ReadMe.from_readme(readme_filepath)



