
"""simple docstring"""

import unittest

from cer import CER


__A							=     CER()
class      lowerCamelCase__      (					unittest.TestCase     ):


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Any        =			["White House"]
					snake_case						:  Optional[int]        =			["white house"]
					# S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
					snake_case						:  Any        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.18_18_18_18_18							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Any        =			["were wolf"]
					snake_case						:  Optional[Any]        =			["werewolf"]
					# S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
					snake_case						:  str        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_11_11_11							) < 1E-6							)

					snake_case						:  int        =			["werewolf"]
					snake_case						:  Any        =			["weae     wolf"]
					# S = 1, D = 1, I = 0, N = 8, CER = 0.25
					snake_case						:  int        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.25							) < 1E-6							)

					# consecutive whitespaces case 1
					snake_case						:  str        =			["were wolf"]
					snake_case						:  Union[str, Any]        =			["were               wolf"]
					# S = 0, D = 0, I = 0, N = 9, CER = 0
					snake_case						:  int        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.0							) < 1E-6							)

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


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			["werewolf"]
					snake_case						:  Optional[int]        =			["weaewolf"]
					# S = 1, D = 0, I = 0, N = 8, CER = 0.125
					snake_case						:  Optional[int]        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_25							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[Any]        =			["werewolf"]
					snake_case						:  Optional[Any]        =			["wereawolf"]
					# S = 0, D = 1, I = 0, N = 8, CER = 0.125
					snake_case						:  Optional[int]        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_25							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[str]        =			["werewolf"]
					snake_case						:  List[Any]        =			["wereolf"]
					# S = 0, D = 0, I = 1, N = 8, CER = 0.125
					snake_case						:  Tuple        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.1_25							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Dict        =			["werewolf"]
					snake_case						:  Dict        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertEqual(SCREAMING_SNAKE_CASE			,	0.0							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  str        =			["werewolf", "I am your father"]
					snake_case						:  Any        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertEqual(SCREAMING_SNAKE_CASE			,	0.0							)

					snake_case						:  List[Any]        =			["werewolf", "I am your father", "doge"]
					snake_case						:  List[str]        =			["werxwolf", "I       am your father", "doge"]
					# S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
					snake_case						:  Tuple        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.03_57_14_28							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  Union[str, Any]        =			["My hovercraft", "is full of eels"]
					snake_case						:  Union[str, Any]        =			["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
					snake_case						:  List[Any]        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE			,	concatenate_texts=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.07_14_28							) < 1E-6							)


			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







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

					snake_case						:  List[Any]        =			["我能吞下玻璃", "而不伤身体"]
					snake_case						:  Any        =			["我    能 吞 下 玻 璃", "而不伤身体"]
					# S = 0, D = 5, I = 0, N = 11, CER = 5 / 11
					snake_case						:  Dict        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertTrue(abs(char_error_rate - 0.45_45_45_45_45_45							) < 1E-6							)

					snake_case						:  List[Any]        =			["我能吞下玻璃而不伤身体"]
					snake_case						:  int        =			cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)
					self.assertFalse(SCREAMING_SNAKE_CASE			,	0.0							)



			def 							lowerCamelCase_			(       self							):



					"""simple docstring"""







					snake_case						:  List[str]        =			[""]
					snake_case						:  Tuple        =			["Hypothesis"]
					with self.assertRaises(SCREAMING_SNAKE_CASE							):
							cer.compute(predictions=SCREAMING_SNAKE_CASE			,	references=SCREAMING_SNAKE_CASE							)


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







"""simple docstring"""

from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_torch_available, is_vision_available


__A							=     {
    "configuration_flava": [
        "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP",
        "FlavaConfig",
        "FlavaImageCodebookConfig",
        "FlavaImageConfig",
        "FlavaMultimodalConfig",
        "FlavaTextConfig",
    ],
}

try:
							if not is_vision_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__A							=     ["FlavaFeatureExtractor"]
							__A							=     ["FlavaImageProcessor"]
							__A							=     ["FlavaProcessor"]

try:
							if not is_torch_available():
														raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
							pass
else:
							__A							=     [
							    "FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST",
							    "FlavaForPreTraining",
							    "FlavaImageCodebook",
							    "FlavaImageModel",
							    "FlavaModel",
							    "FlavaMultimodalModel",
							    "FlavaPreTrainedModel",
							    "FlavaTextModel",
							]

if TYPE_CHECKING:
							from .configuration_flava import (
							    FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP,
							    FlavaConfig,
							    FlavaImageCodebookConfig,
							    FlavaImageConfig,
							    FlavaMultimodalConfig,
							    FlavaTextConfig,
							)

							try:
														if not is_vision_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .feature_extraction_flava import FlavaFeatureExtractor
														from .image_processing_flava import FlavaImageProcessor
														from .processing_flava import FlavaProcessor

							try:
														if not is_torch_available():
																					raise OptionalDependencyNotAvailable()
							except OptionalDependencyNotAvailable:
														pass
							else:
														from .modeling_flava import (
														    FLAVA_PRETRAINED_MODEL_ARCHIVE_LIST,
														    FlavaForPreTraining,
														    FlavaImageCodebook,
														    FlavaImageModel,
														    FlavaModel,
														    FlavaMultimodalModel,
														    FlavaPreTrainedModel,
														    FlavaTextModel,
														)

else:
							import sys

							__A							=     _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

