
'''simple docstring'''





import unittest

from transformers import CamembertTokenizer, CamembertTokenizerFast
from transformers.testing_utils import get_tests_dir, require_sentencepiece, require_tokenizers, slow
from transformers.utils import is_torch_available

from ...test_tokenization_common import TokenizerTesterMixin


lowerCamelCase      =get_tests_dir("fixtures/test_sentencepiece.model")
lowerCamelCase      =get_tests_dir("fixtures/test_sentencepiece_bpe.model")

lowerCamelCase      ="pt" if is_torch_available() else "tf"




@require_sentencepiece
@require_tokenizers
class 				_lowerCamelCase (      UpperCamelCase_	,							unittest.TestCase ):





     """simple docstring"""







     SCREAMING_SNAKE_CASE_		   =  CamembertTokenizer
     SCREAMING_SNAKE_CASE_		   =  CamembertTokenizerFast
     SCREAMING_SNAKE_CASE_		   =  True
     SCREAMING_SNAKE_CASE_		   =  True






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Optional[Any]:




           """simple docstring"""







           super().setUp()

           # We have a SentencePiece fixture for testing
           UpperCamelCase__    :   int					=				CamembertTokenizer(__SCREAMING_SNAKE_CASE  )
           tokenizer.save_pretrained(self.tmpdirname  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   str:




           """simple docstring"""







           UpperCamelCase__    :   Tuple					=				'''<pad>'''
           UpperCamelCase__    :   Optional[int]					=				1

           self.assertEqual(self.get_tokenizer()._convert_token_to_id(__SCREAMING_SNAKE_CASE  )						,						__SCREAMING_SNAKE_CASE  )
           self.assertEqual(self.get_tokenizer()._convert_id_to_token(__SCREAMING_SNAKE_CASE  )						,						__SCREAMING_SNAKE_CASE  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[str]:




           """simple docstring"""







           UpperCamelCase__    :   Optional[int]					=				list(self.get_tokenizer().get_vocab().keys()  )

           self.assertEqual(vocab_keys[0]						,						'''<s>NOTUSED'''  )
           self.assertEqual(vocab_keys[1]						,						'''<pad>'''  )
           self.assertEqual(vocab_keys[-1]						,						'''<mask>'''  )
           self.assertEqual(len(__SCREAMING_SNAKE_CASE  )						,						1_0_0_4  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[Any]:




           """simple docstring"""







           self.assertEqual(self.get_tokenizer().vocab_size						,						1_0_0_5  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Union[str, Any]:




           """simple docstring"""







           UpperCamelCase__    :   Optional[Any]					=				CamembertTokenizer(__SCREAMING_SNAKE_CASE  )
           tokenizer.save_pretrained(self.tmpdirname  )
           UpperCamelCase__    :   List[Any]					=				CamembertTokenizerFast.from_pretrained(self.tmpdirname  )

           UpperCamelCase__    :   Optional[Any]					=				'''I was born in 92000, and this is falsé.'''

           UpperCamelCase__    :   str					=				tokenizer.encode(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   int					=				rust_tokenizer.encode(__SCREAMING_SNAKE_CASE  )
           self.assertListEqual(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__    :   Optional[Any]					=				tokenizer.encode(__SCREAMING_SNAKE_CASE						,						add_special_tokens=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Optional[Any]					=				rust_tokenizer.encode(__SCREAMING_SNAKE_CASE						,						add_special_tokens=__SCREAMING_SNAKE_CASE  )
           self.assertListEqual(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )

           # <unk> tokens are not the same for `rust` than for `slow`.
           # Because spm gives back raw token instead of `unk` in EncodeAsPieces
           # tokens = tokenizer.tokenize(sequence)
           UpperCamelCase__    :   Union[str, Any]					=				tokenizer.convert_ids_to_tokens(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Dict					=				rust_tokenizer.tokenize(__SCREAMING_SNAKE_CASE  )
           self.assertListEqual(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )






     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   List[str]:




           """simple docstring"""







           if not self.test_rust_tokenizer:
                 return

           UpperCamelCase__    :   Optional[Any]					=				self.get_tokenizer()
           UpperCamelCase__    :   Optional[Any]					=				self.get_rust_tokenizer()

           UpperCamelCase__    :   int					=				'''I was born in 92000, and this is falsé.'''

           UpperCamelCase__    :   Dict					=				tokenizer.tokenize(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Dict					=				rust_tokenizer.tokenize(__SCREAMING_SNAKE_CASE  )
           self.assertListEqual(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__    :   Optional[Any]					=				tokenizer.encode(__SCREAMING_SNAKE_CASE						,						add_special_tokens=__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Any					=				rust_tokenizer.encode(__SCREAMING_SNAKE_CASE						,						add_special_tokens=__SCREAMING_SNAKE_CASE  )
           self.assertListEqual(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )

           UpperCamelCase__    :   Optional[Any]					=				self.get_rust_tokenizer()
           UpperCamelCase__    :   int					=				tokenizer.encode(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Any					=				rust_tokenizer.encode(__SCREAMING_SNAKE_CASE  )
           self.assertListEqual(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )






     @slow
     def    __SCREAMING_SNAKE_CASE			(							self  )  ->   Optional[Any]:




           """simple docstring"""







           UpperCamelCase__    :   List[Any]					=				{'''input_ids''': [[5, 5_4, 7_1_9_6, 2_9_7, 3_0, 2_3, 7_7_6, 1_8, 1_1, 3_2_1_5, 3_7_0_5, 8_2_5_2, 2_2, 3_1_6_4, 1_1_8_1, 2_1_1_6, 2_9, 1_6, 8_1_3, 2_5, 7_9_1, 3_3_1_4, 2_0, 3_4_4_6, 3_8, 2_7_5_7_5, 1_2_0, 6, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [5, 4_6_8, 1_7, 1_1, 9_0_8_8, 2_0, 1_5_1_7, 8, 2_2_8_0_4, 1_8_8_1_8, 1_0, 3_8, 6_2_9, 6_0_7, 6_0_7, 1_4_2, 1_9, 7_1_9_6, 8_6_7, 5_6, 1_0_3_2_6, 2_4, 2_2_6_7, 2_0, 4_1_6, 5_0_7_2, 1_5_6_1_2, 2_3_3, 7_3_4, 7, 2_3_9_9, 2_7, 1_6, 3_0_1_5, 1_6_4_9, 7, 2_4, 2_0, 4_3_3_8, 2_3_9_9, 2_7, 1_3, 3_4_0_0, 1_4, 1_3, 6_1_8_9, 8, 9_3_0, 9, 6]], '''attention_mask''': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}  # noqa: E501
           # fmt: on

           # camembert is a french model. So we also use french texts.
           UpperCamelCase__    :   Union[str, Any]					=				[
               '''Le transformeur est un modèle d\'apprentissage profond introduit en 2017, '''
               '''utilisé principalement dans le domaine du traitement automatique des langues (TAL).''',
               '''À l\'instar des réseaux de neurones récurrents (RNN), les transformeurs sont conçus '''
               '''pour gérer des données séquentielles, telles que le langage naturel, pour des tâches '''
               '''telles que la traduction et la synthèse de texte.''',
           ]

           self.tokenizer_integration_test_util(
               expected_encoding=__SCREAMING_SNAKE_CASE						,						model_name='''camembert-base'''						,						revision='''3a0641d9a1aeb7e848a74299e7e4c4bca216b4cf'''						,						sequences=__SCREAMING_SNAKE_CASE						,						)




class 				_lowerCamelCase :





     """simple docstring"""







     def __init__(							self  )  ->   Tuple:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				''''''
           UpperCamelCase__    :   int					=				''''''
           UpperCamelCase__    :   Optional[int]					=				[]






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   int:




           """simple docstring"""







           if m == -1:
                 return n + 1
           elif n == -1:
                 return m + 1
           elif self.dp[m][n] > -1:
                 return self.dp[m][n]
           else:
                 if self.worda[m] == self.worda[n]:
                       UpperCamelCase__    :   Union[str, Any]					=				self.__min_dist_top_down_dp(m - 1						,						n - 1  )
                 else:
                       UpperCamelCase__    :   int					=				self.__min_dist_top_down_dp(__SCREAMING_SNAKE_CASE						,						n - 1  )
                       UpperCamelCase__    :   Tuple					=				self.__min_dist_top_down_dp(m - 1						,						__SCREAMING_SNAKE_CASE  )
                       UpperCamelCase__    :   Optional[Any]					=				self.__min_dist_top_down_dp(m - 1						,						n - 1  )
                       UpperCamelCase__    :   Optional[int]					=				1 + min(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )

                 return self.dp[m][n]






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   int:




           """simple docstring"""







           UpperCamelCase__    :   Union[str, Any]					=				worda
           UpperCamelCase__    :   Any					=				worda
           UpperCamelCase__    :   List[str]					=				[[-1 for _ in range(len(__SCREAMING_SNAKE_CASE  )  )] for _ in range(len(__SCREAMING_SNAKE_CASE  )  )]

           return self.__min_dist_top_down_dp(len(__SCREAMING_SNAKE_CASE  ) - 1						,						len(__SCREAMING_SNAKE_CASE  ) - 1  )






     def    __SCREAMING_SNAKE_CASE			(							self						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )  ->   int:




           """simple docstring"""







           UpperCamelCase__    :   int					=				worda
           UpperCamelCase__    :   List[str]					=				worda
           UpperCamelCase__    :   int					=				len(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   Optional[Any]					=				len(__SCREAMING_SNAKE_CASE  )
           UpperCamelCase__    :   int					=				[[0 for _ in range(n + 1  )] for _ in range(m + 1  )]

           for i in range(m + 1  ):
                 for j in range(n + 1  ):
                       if i == 0:  # first string is empty
                             UpperCamelCase__    :   List[Any]					=				j
                       elif j == 0:  # second string is empty
                             UpperCamelCase__    :   Union[str, Any]					=				i
                       elif worda[i - 1] == worda[j - 1]:  # last characters are equal
                             UpperCamelCase__    :   List[Any]					=				self.dp[i - 1][j - 1]
                       else:
                             UpperCamelCase__    :   Union[str, Any]					=				self.dp[i][j - 1]
                             UpperCamelCase__    :   str					=				self.dp[i - 1][j]
                             UpperCamelCase__    :   Union[str, Any]					=				self.dp[i - 1][j - 1]
                             UpperCamelCase__    :   List[Any]					=				1 + min(__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE						,						__SCREAMING_SNAKE_CASE  )
           return self.dp[m][n]


if __name__ == "__main__":
    lowerCamelCase      =EditDistance()

    print("****************** Testing Edit Distance DP Algorithm ******************")
    print()

    lowerCamelCase      =input("Enter the first string: ").strip()
    lowerCamelCase      =input("Enter the second string: ").strip()

    print()
    print(F'''The minimum edit distance is: {solver.min_dist_top_down(Sa, Sa)}''')
    print(F'''The minimum edit distance is: {solver.min_dist_bottom_up(Sa, Sa)}''')
    print()
    print("*************** End of Testing Edit Distance DP Algorithm ***************")


