


import unittest

from cer import CER


_UpperCAmelCase      :	List[str]  =CER()







class 					snake_case__(				unittest.TestCase				):







						'''simple docstring'''




						def     lowercase_			(					self				)       ->     List[str]:
										lowerCAmelCase_			:   Tuple     					=					['''White House''']
										lowerCAmelCase_			:   Optional[Any]     					=					['''white house''']
										# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
										lowerCAmelCase_			:   str     					=					cer.compute(predictions=__lowercase ,    references=__lowercase				)
										self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18				) < 1e-6				)




						def     lowercase_			(					self				)       ->     List[str]:
										lowerCAmelCase_			:   Optional[int]     					=					['''were wolf''']
										lowerCAmelCase_			:   str     					=					['''werewolf''']
										# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
										lowerCAmelCase_			:   Dict     					=					cer.compute(predictions=__lowercase ,    references=__lowercase				)
										self.assertTrue(abs(char_error_rate - 0.1_11_11_11				) < 1e-6				)

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

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

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




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




						def     lowercase_			(					self				)       ->     int:
										lowerCAmelCase_			:   Dict     					=					['''werewolf''']
										lowerCAmelCase_			:   str     					=					['''wereawolf''']
										# S = 0, D = 1, I = 0, N = 8, CER = 0.125
										lowerCAmelCase_			:   Any     					=					cer.compute(predictions=__lowercase ,    references=__lowercase				)
										self.assertTrue(abs(char_error_rate - 0.1_25				) < 1e-6				)




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




						def     lowercase_			(					self				)       ->     Union[str, Any]:
										lowerCAmelCase_			:   int     					=					['''werewolf''']
										lowerCAmelCase_			:   Union[str, Any]     					=					cer.compute(predictions=__lowercase ,    references=__lowercase				)
										self.assertEqual(__lowercase ,    0.0				)




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

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




						def     lowercase_			(					self				)       ->     Dict:
										lowerCAmelCase_			:   Optional[int]     					=					['''My hovercraft''', '''is full of eels''']
										lowerCAmelCase_			:   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
										lowerCAmelCase_			:   Any     					=					cer.compute(predictions=__lowercase ,    references=__lowercase ,    concatenate_texts=__lowercase				)
										self.assertTrue(abs(char_error_rate - 0.07_14_28				) < 1e-6				)




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

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

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




						def     lowercase_			(					self				)       ->     Union[str, Any]:
										lowerCAmelCase_			:   Optional[int]     					=					['''''']
										lowerCAmelCase_			:   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