import unittest

from cer import CER


_SCREAMING_SNAKE_CASE     =     CER()







class        UpperCAmelCase_					(				unittest.TestCase     ):




    def     __lowerCamelCase			(       self	: Union[str, Any] )						->			Union[str, Any]:
      a__  		=  ["White House"]
      a__  		=  ["white house"]
      # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.1_818_181_818 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: List[str] )						->			Optional[Any]:
      a__  		=  ["were wolf"]
      a__  		=  ["werewolf"]
      # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.1_111_111 ) < 1e-6 )

      a__  		=  ["werewolf"]
      a__  		=  ["weae     wolf"]
      # S = 1, D = 1, I = 0, N = 8, CER = 0.25
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.25 ) < 1e-6 )

      # consecutive whitespaces case 1
      a__  		=  ["were wolf"]
      a__  		=  ["were               wolf"]
      # S = 0, D = 0, I = 0, N = 9, CER = 0
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.0 ) < 1e-6 )

      # consecutive whitespaces case 2
      a__  		=  ["were   wolf"]
      a__  		=  ["were               wolf"]
      # S = 0, D = 0, I = 0, N = 9, CER = 0
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.0 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: Dict )						->			Optional[int]:
      a__  		=  ["werewolf"]
      a__  		=  ["weaewolf"]
      # S = 1, D = 0, I = 0, N = 8, CER = 0.125
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.125 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: int )						->			int:
      a__  		=  ["werewolf"]
      a__  		=  ["wereawolf"]
      # S = 0, D = 1, I = 0, N = 8, CER = 0.125
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.125 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: Any )						->			Dict:
      a__  		=  ["werewolf"]
      a__  		=  ["wereolf"]
      # S = 0, D = 0, I = 1, N = 8, CER = 0.125
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.125 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: List[Any] )						->			Optional[Any]:
      a__  		=  ["werewolf"]
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertEqual(lowerCAmelCase   ,   0.0 )




    def     __lowerCamelCase			(       self	: Optional[Any] )						->			str:
      a__  		=  ["werewolf", "I am your father"]
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertEqual(lowerCAmelCase   ,   0.0 )

      a__  		=  ["werewolf", "I am your father", "doge"]
      a__  		=  ["werxwolf", "I       am your father", "doge"]
      # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.03_571_428 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: Dict )						->			Union[str, Any]:
      a__  		=  ["My hovercraft", "is full of eels"]
      a__  		=  ["My hovercraft is full", " of eels"]
      # S = 0, D = 0, I = 2, N = 28, CER = 2 / 28
      # whitespace at the front of " of eels" will be strip during preporcessing
      # so need to insert 2 whitespaces
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase   ,   concatenate_texts=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.071_428 ) < 1e-6 )




    def     __lowerCamelCase			(       self	: Tuple )						->			Optional[int]:
      a__  		=  ["我能吞下玻璃而不伤身体"]
      a__  		=  [" 能吞虾玻璃而 不霜身体啦"]
      # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.4_545_454_545 ) < 1e-6 )

      a__  		=  ["我能吞下玻璃", "而不伤身体"]
      a__  		=  ["我    能 吞 下 玻 璃", "而不伤身体"]
      # S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertTrue(abs(char_error_rate - 0.454_545_454_545 ) < 1e-6 )

      a__  		=  ["我能吞下玻璃而不伤身体"]
      a__  		=  cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )
      self.assertFalse(lowerCAmelCase   ,   0.0 )




    def     __lowerCamelCase			(       self	: List[Any] )						->			Optional[Any]:
      a__  		=  [""]
      a__  		=  ["Hypothesis"]
      with self.assertRaises(lowerCAmelCase ):
        cer.compute(predictions=lowerCAmelCase   ,   references=lowerCAmelCase )


if __name__ == "__main__":
     unittest.main()


from typing import List

import datasets
from datasets.tasks import ImageClassification

from ..folder_based_builder import folder_based_builder


_SCREAMING_SNAKE_CASE     =     datasets.utils.logging.get_logger(__name__)







class        UpperCAmelCase_					(				folder_based_builder.FolderBasedBuilderConfig     ):
    UpperCAmelCase_      :							bool    			=				None
    UpperCAmelCase_      :							bool    			=				None







class        UpperCAmelCase_					(				folder_based_builder.FolderBasedBuilder     ):
    UpperCAmelCase_      :							Any    			=				datasets.Image()
    UpperCAmelCase_      :							List[Any]    			=				'image'
    UpperCAmelCase_      :							int    			=				ImageFolderConfig
    UpperCAmelCase_      :							List[str]  # definition at the bottom of the script
    UpperCAmelCase_      :							Dict    			=				ImageClassification(image_column='image'  ,  label_column='label'     )

_SCREAMING_SNAKE_CASE     =     [
    """.blp""",
    """.bmp""",
    """.dib""",
    """.bufr""",
    """.cur""",
    """.pcx""",
    """.dcx""",
    """.dds""",
    """.ps""",
    """.eps""",
    """.fit""",
    """.fits""",
    """.fli""",
    """.flc""",
    """.ftc""",
    """.ftu""",
    """.gbr""",
    """.gif""",
    """.grib""",
    """.h5""",
    """.hdf""",
    """.png""",
    """.apng""",
    """.jp2""",
    """.j2k""",
    """.jpc""",
    """.jpf""",
    """.jpx""",
    """.j2c""",
    """.icns""",
    """.ico""",
    """.im""",
    """.iim""",
    """.tif""",
    """.tiff""",
    """.jfif""",
    """.jpe""",
    """.jpg""",
    """.jpeg""",
    """.mpg""",
    """.mpeg""",
    """.msp""",
    """.pcd""",
    """.pxr""",
    """.pbm""",
    """.pgm""",
    """.ppm""",
    """.pnm""",
    """.psd""",
    """.bw""",
    """.rgb""",
    """.rgba""",
    """.sgi""",
    """.ras""",
    """.tga""",
    """.icb""",
    """.vda""",
    """.vst""",
    """.webp""",
    """.wmf""",
    """.emf""",
    """.xbm""",
    """.xpm""",
]
_SCREAMING_SNAKE_CASE     =     IMAGE_EXTENSIONS

