


import unittest

from cer import CER


snake_case__  				=			CER()



class      snake_case__	(   unittest.TestCase	):
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Tuple				=   ['''White House''']
										__magic_name__					:				Optional[Any]				=   ['''white house''']
										# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
										__magic_name__					:				str				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.1818181818   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Optional[int]				=   ['''were wolf''']
										__magic_name__					:				str				=   ['''werewolf''']
										# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
										__magic_name__					:				Dict				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.1111111   ) < 1E-6   )

										__magic_name__					:				Dict				=   ['''werewolf''']
										__magic_name__					:				str				=   ['''weae     wolf''']
										# S = 1, D = 1, I = 0, N = 8, CER = 0.25
										__magic_name__					:				Dict				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.25   ) < 1E-6   )

										# consecutive whitespaces case 1
										__magic_name__					:				str				=   ['''were wolf''']
										__magic_name__					:				Optional[Any]				=   ['''were               wolf''']
										# S = 0, D = 0, I = 0, N = 9, CER = 0
										__magic_name__					:				List[Any]				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.0   ) < 1E-6   )

										# consecutive whitespaces case 2
										__magic_name__					:				Any				=   ['''were   wolf''']
										__magic_name__					:				Any				=   ['''were               wolf''']
										# S = 0, D = 0, I = 0, N = 9, CER = 0
										__magic_name__					:				Tuple				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.0   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Dict				=   ['''werewolf''']
										__magic_name__					:				str				=   ['''weaewolf''']
										# S = 1, D = 0, I = 0, N = 8, CER = 0.125
										__magic_name__					:				List[Any]				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Dict				=   ['''werewolf''']
										__magic_name__					:				str				=   ['''wereawolf''']
										# S = 0, D = 1, I = 0, N = 8, CER = 0.125
										__magic_name__					:				Any				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Optional[int]				=   ['''werewolf''']
										__magic_name__					:				str				=   ['''wereolf''']
										# S = 0, D = 0, I = 1, N = 8, CER = 0.125
										__magic_name__					:				Tuple				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.125   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				int				=   ['''werewolf''']
										__magic_name__					:				Union[str, Any]				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertEqual(__lowercase  ,   0.0   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				List[str]				=   ['''werewolf''', '''I am your father''']
										__magic_name__					:				int				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertEqual(__lowercase  ,   0.0   )

										__magic_name__					:				Dict				=   ['''werewolf''', '''I am your father''', '''doge''']
										__magic_name__					:				Union[str, Any]				=   ['''werxwolf''', '''I       am your father''', '''doge''']
										# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
										__magic_name__					:				str				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.03571428   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Optional[int]				=   ['''My hovercraft''', '''is full of eels''']
										__magic_name__					:				Tuple				=   ['''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
										__magic_name__					:				Any				=   cer.compute(predictions=__lowercase  ,   references=__lowercase  ,   concatenate_texts=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.071428   ) < 1E-6   )
				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				int				=   ['''我能吞下玻璃而不伤身体''']
										__magic_name__					:				Union[str, Any]				=   [''' 能吞虾玻璃而 不霜身体啦''']
										# S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
										__magic_name__					:				Optional[Any]				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.4545454545   ) < 1E-6   )

										__magic_name__					:				List[str]				=   ['''我能吞下玻璃''', '''而不伤身体''']
										__magic_name__					:				Optional[Any]				=   ['''我    能 吞 下 玻 璃''', '''而不伤身体''']
										# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
										__magic_name__					:				Union[str, Any]				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertTrue(abs(char_error_rate - 0.454545454545   ) < 1E-6   )

										__magic_name__					:				Optional[Any]				=   ['''我能吞下玻璃而不伤身体''']
										__magic_name__					:				Any				=   cer.compute(predictions=__lowercase  ,   references=__lowercase   )
										self.assertFalse(__lowercase  ,   0.0   )





				def 			UpperCamelCase_    (	self   ):




										"""simple docstring"""




										__magic_name__					:				Optional[int]				=   ['''''']
										__magic_name__					:				int				=   ['''Hypothesis''']
										with self.assertRaises(__lowercase   ):
																cer.compute(predictions=__lowercase  ,   references=__lowercase   )


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






import numpy as np

_UpperCAmelCase      :	int  =[
    ["""a""", """b""", """c""", """d""", """e"""],
    ["""f""", """g""", """h""", """i""", """k"""],
    ["""l""", """m""", """n""", """o""", """p"""],
    ["""q""", """r""", """s""", """t""", """u"""],
    ["""v""", """w""", """x""", """y""", """z"""],
]







class 					snake_case__:







						'''simple docstring'''




						def __init__(					self				)       ->     None:
										lowerCAmelCase_			:   List[Any]     					=					np.array(__lowercase				)




						def     lowercase_			(					self ,    __lowercase				)       ->     np.ndarray:
										lowerCAmelCase_					,	lowerCAmelCase_			:   List[str]     					=					np.where(letter == self.SQUARE				)
										lowerCAmelCase_			:   Union[str, Any]     					=					np.concatenate([indexa + 1, indexa + 1]				)
										return indexes




						def     lowercase_			(					self ,    __lowercase ,    __lowercase				)       ->     str:
										return self.SQUARE[indexa - 1, indexa - 1]




						def     lowercase_			(					self ,    __lowercase				)       ->     str:
										lowerCAmelCase_			:   Dict     					=					message.lower()
										lowerCAmelCase_			:   Any     					=					message.replace('''j''' ,    '''i'''				)

										lowerCAmelCase_			:   Optional[Any]     					=					''''''
										for letter_index in range(len(__lowercase				)				):
														if message[letter_index] != " ":
																		lowerCAmelCase_			:   Optional[Any]     					=					self.letter_to_numbers(message[letter_index]				)
																		lowerCAmelCase_			:   List[Any]     					=					encoded_message + str(numbers[0]				) + str(numbers[1]				)
														elif message[letter_index] == " ":
																		lowerCAmelCase_			:   Optional[Any]     					=					encoded_message + ''' '''

										return encoded_message




						def     lowercase_			(					self ,    __lowercase				)       ->     str:
										lowerCAmelCase_			:   List[str]     					=					message.replace(''' ''' ,    '''  '''				)
										lowerCAmelCase_			:   Union[str, Any]     					=					''''''
										for numbers_index in range(int(len(__lowercase				) / 2				)				):
														if message[numbers_index * 2] != " ":
																		lowerCAmelCase_			:   Any     					=					message[numbers_index * 2]
																		lowerCAmelCase_			:   Dict     					=					message[numbers_index * 2 + 1]

																		lowerCAmelCase_			:   Dict     					=					self.numbers_to_letter(int(__lowercase				) ,    int(__lowercase				)				)
																		lowerCAmelCase_			:   Tuple     					=					decoded_message + letter
														elif message[numbers_index * 2] == " ":
																		lowerCAmelCase_			:   List[str]     					=					decoded_message + ''' '''

										return decoded_message