


from typing import TYPE_CHECKING

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


__lowerCAmelCase									=				{
    '''configuration_oneformer''': ['''ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP''', '''OneFormerConfig'''],
    '''processing_oneformer''': ['''OneFormerProcessor'''],
}

try:
 if not is_vision_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowerCAmelCase									=				['''OneFormerImageProcessor''']

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 __lowerCAmelCase									=				[
     '''ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST''',
     '''OneFormerForUniversalSegmentation''',
     '''OneFormerModel''',
     '''OneFormerPreTrainedModel''',
 ]

if TYPE_CHECKING:
 from .configuration_oneformer import ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP, OneFormerConfig
 from .processing_oneformer import OneFormerProcessor

 try:
  if not is_vision_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .image_processing_oneformer import OneFormerImageProcessor
 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_oneformer import (
      ONEFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
      OneFormerForUniversalSegmentation,
      OneFormerModel,
      OneFormerPreTrainedModel,
  )


else:
 import sys

 __lowerCAmelCase									=				_LazyModule(__name__, globals()['''__file__'''], _import_structure)






import unittest

from cer import CER


__lowerCAmelCase									=				CER()





class     __a     (       unittest.TestCase ):
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  ['White House']
        lowercase__:  Optional[int]         =  ['white house']
        # S = 2, D = 0, I = 0, N = 11, CER = 2 / 11
        lowercase__:  str         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_8_1_8_1_8_1_8_1_8					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Union[str, Any]         =  ['were wolf']
        lowercase__:  Union[str, Any]         =  ['werewolf']
        # S = 0, D = 0, I = 1, N = 9, CER = 1 / 9
        lowercase__:  Tuple         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_1_1_1_1_1_1					) < 1E-6					)

        lowercase__:  Dict         =  ['werewolf']
        lowercase__:  Optional[Any]         =  ['weae     wolf']
        # S = 1, D = 1, I = 0, N = 8, CER = 0.25
        lowercase__:  Optional[int]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.2_5					) < 1E-6					)

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

        # consecutive whitespaces case 2
        lowercase__:  List[str]         =  ['were   wolf']
        lowercase__:  Tuple         =  ['were               wolf']
        # S = 0, D = 0, I = 0, N = 9, CER = 0
        lowercase__:  Dict         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Optional[int]         =  ['werewolf']
        lowercase__:  Dict         =  ['weaewolf']
        # S = 1, D = 0, I = 0, N = 8, CER = 0.125
        lowercase__:  int         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_2_5					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  int         =  ['werewolf']
        lowercase__:  Optional[int]         =  ['wereawolf']
        # S = 0, D = 1, I = 0, N = 8, CER = 0.125
        lowercase__:  Dict         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_2_5					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[Any]:




        '''simple docstring'''
        lowercase__:  Optional[Any]         =  ['werewolf']
        lowercase__:  List[str]         =  ['wereolf']
        # S = 0, D = 0, I = 1, N = 8, CER = 0.125
        lowercase__:  Optional[Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.1_2_5					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[int]:




        '''simple docstring'''
        lowercase__:  List[str]         =  ['werewolf']
        lowercase__:  List[Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertEqual(lowerCAmelCase__							,					0.0					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[Any]:




        '''simple docstring'''
        lowercase__:  int         =  ['werewolf', 'I am your father']
        lowercase__:  Union[str, Any]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertEqual(lowerCAmelCase__							,					0.0					)

        lowercase__:  List[str]         =  ['werewolf', 'I am your father', 'doge']
        lowercase__:  Any         =  ['werxwolf', 'I       am your father', 'doge']
        # S = 1, D = 0, I = 0, N = 28, CER = 1 / 28
        lowercase__:  int         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0_3_5_7_1_4_2_8					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Optional[int]:




        '''simple docstring'''
        lowercase__:  List[Any]         =  ['My hovercraft', 'is full of eels']
        lowercase__:  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
        lowercase__:  Optional[int]         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__							,					concatenate_texts=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.0_7_1_4_2_8					) < 1E-6					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							Dict:




        '''simple docstring'''
        lowercase__:  Dict         =  ['我能吞下玻璃而不伤身体']
        lowercase__:  Tuple         =  [' 能吞虾玻璃而 不霜身体啦']
        # S = 3, D = 2, I = 0, N = 11, CER = 5 / 11
        lowercase__:  str         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertTrue(abs(char_error_rate - 0.4_5_4_5_4_5_4_5_4_5					) < 1E-6					)

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

        lowercase__:  int         =  ['我能吞下玻璃而不伤身体']
        lowercase__:  Any         =  cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)
        self.assertFalse(lowerCAmelCase__							,					0.0					)
 def 						SCREAMING_SNAKE_CASE__  (  self					)   ->							List[str]:




        '''simple docstring'''
        lowercase__:  Dict         =  ['']
        lowercase__:  int         =  ['Hypothesis']
        with self.assertRaises(lowerCAmelCase__					):
               cer.compute(predictions=lowerCAmelCase__							,					references=lowerCAmelCase__					)


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


