


"""simple docstring"""





import json
import os
import unittest

from transformers.models.gptsan_japanese.tokenization_gptsan_japanese import (
    VOCAB_FILES_NAMES,
    GPTSanJapaneseTokenizer,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class 						snake_case_(				a__							,    unittest.TestCase	):
     __UpperCamelCase     =    GPTSanJapaneseTokenizer
     __UpperCamelCase     =    False
     __UpperCamelCase     =    {'''do_clean_text''': False, '''add_prefix_space''': False}






     def    lowerCamelCase__   (		self     :    Optional[int] ):
           super().setUp()

           # fmt: off
           lowerCAmelCase    :		List[str]				=      ['''こん''', '''こんに''', '''にちは''', '''ばんは''', '''世界,㔺界''', '''、''', '''。''', '''<BR>''', '''<SP>''', '''<TAB>''', '''<URL>''', '''<EMAIL>''', '''<TEL>''', '''<DATE>''', '''<PRICE>''', '''<BLOCK>''', '''<KIGOU>''', '''<U2000U2BFF>''', '''<|emoji1|>''', '''<unk>''', '''<|bagoftoken|>''', '''<|endoftext|>''']
           # fmt: on
           lowerCAmelCase    :		int				=      {'''emoji''': {'''\ud83d\ude00''': '''<|emoji1|>'''}, '''emoji_inv''': {'''<|emoji1|>''': '''\ud83d\ude00'''}}  # 😀
           lowerCAmelCase    :		List[str]				=      {'''unk_token''': '''<unk>'''}

           lowerCAmelCase    :		Union[str, Any]				=      os.path.join(self.tmpdirname    , VOCAB_FILES_NAMES['''vocab_file'''] )
           lowerCAmelCase    :		Any				=      os.path.join(self.tmpdirname    , VOCAB_FILES_NAMES['''emoji_file'''] )
           with open(self.vocab_file    , '''w'''    , encoding='''utf-8''' ) as vocab_writer:
                 vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens] ) )
           with open(self.emoji_file    , '''w''' ) as emoji_writer:
                 emoji_writer.write(json.dumps(UpperCamelCase_ ) )






     def    lowerCamelCase__   (		self     :    Union[str, Any]    , **UpperCamelCase_     :    Optional[Any] ):
           kwargs.update(self.special_tokens_map )
           return GPTSanJapaneseTokenizer.from_pretrained(self.tmpdirname    , **UpperCamelCase_ )






     def    lowerCamelCase__   (		self     :    str    , UpperCamelCase_     :    Optional[int] ):
           lowerCAmelCase    :		int				=      '''こんにちは、世界。 \nこんばんは、㔺界。😀'''
           lowerCAmelCase    :		List[Any]				=      '''こんにちは、世界。 \nこんばんは、世界。😀'''
           return input_text, output_text






     def    lowerCamelCase__   (		self     :    Dict    , UpperCamelCase_     :    Dict ):
           lowerCAmelCase,					lowerCAmelCase    :		List[Any]				=      self.get_input_output_texts(UpperCamelCase_ )
           lowerCAmelCase    :		Optional[Any]				=      tokenizer.encode(UpperCamelCase_    , add_special_tokens=UpperCamelCase_ )
           lowerCAmelCase    :		List[str]				=      tokenizer.decode(UpperCamelCase_    , clean_up_tokenization_spaces=UpperCamelCase_ )
           return text, ids






     def    lowerCamelCase__   (		self     :    Any ):
           pass  # TODO add if relevant






     def    lowerCamelCase__   (		self     :    Union[str, Any] ):
           pass  # TODO add if relevant






     def    lowerCamelCase__   (		self     :    Union[str, Any] ):
           pass  # TODO add if relevant






     def    lowerCamelCase__   (		self     :    Optional[Any] ):
           lowerCAmelCase    :		Any				=      self.get_tokenizer()

           # Testing tokenization
           lowerCAmelCase    :		int				=      '''こんにちは、世界。　こんばんは、㔺界。'''
           lowerCAmelCase    :		Union[str, Any]				=      ['''こん''', '''にちは''', '''、''', '''世界''', '''。''', '''<SP>''', '''こん''', '''ばんは''', '''、''', '''㔺界''', '''。''']
           lowerCAmelCase    :		Dict				=      tokenizer.tokenize(UpperCamelCase_ )
           self.assertListEqual(UpperCamelCase_    , UpperCamelCase_ )

           # Testing conversion to ids without special tokens
           lowerCAmelCase    :		int				=      [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6]
           lowerCAmelCase    :		Tuple				=      tokenizer.convert_tokens_to_ids(UpperCamelCase_ )
           self.assertListEqual(UpperCamelCase_    , UpperCamelCase_ )

           # Testing conversion to ids with special tokens
           lowerCAmelCase    :		Tuple				=      tokens + [tokenizer.unk_token]
           lowerCAmelCase    :		Tuple				=      [0, 2, 5, 4, 6, 8, 0, 3, 5, 4, 6, 1_9]
           lowerCAmelCase    :		List[str]				=      tokenizer.convert_tokens_to_ids(UpperCamelCase_ )
           self.assertListEqual(UpperCamelCase_    , UpperCamelCase_ )






     def    lowerCamelCase__   (		self     :    Union[str, Any] ):
           lowerCAmelCase    :		List[Any]				=      self.get_tokenizer()

           # Testing tokenization
           lowerCAmelCase    :		str				=      '''こんにちは、<|bagoftoken|>世界。こんばんは、<|bagoftoken|>㔺界。'''
           lowerCAmelCase    :		List[Any]				=      '''こんにちは、、、、世界。こんばんは、、、、世界。'''
           lowerCAmelCase    :		Dict				=      tokenizer.encode(UpperCamelCase_ )
           lowerCAmelCase    :		Dict				=      tokenizer.decode(UpperCamelCase_ )
           self.assertEqual(UpperCamelCase_    , UpperCamelCase_ )






     @slow
     def    lowerCamelCase__   (		self     :    str ):
           lowerCAmelCase    :		str				=      self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese''' )

           # Testing tokenization
           lowerCAmelCase    :		Optional[int]				=      '''こんにちは、世界。'''
           lowerCAmelCase    :		Dict				=      '''こんばんは、㔺界。😀'''
           lowerCAmelCase    :		int				=      '''こんにちは、世界。こんばんは、世界。😀'''
           lowerCAmelCase    :		Any				=      tokenizer.encode(prefix_text + input_text )
           lowerCAmelCase    :		List[str]				=      tokenizer.encode(''''''    , prefix_text=prefix_text + input_text )
           lowerCAmelCase    :		Any				=      tokenizer.encode(UpperCamelCase_    , prefix_text=UpperCamelCase_ )
           lowerCAmelCase    :		Tuple				=      tokenizer.decode(UpperCamelCase_ )
           lowerCAmelCase    :		List[str]				=      tokenizer.decode(UpperCamelCase_ )
           lowerCAmelCase    :		Optional[int]				=      tokenizer.decode(UpperCamelCase_ )
           self.assertEqual(UpperCamelCase_    , UpperCamelCase_ )
           self.assertEqual(UpperCamelCase_    , UpperCamelCase_ )
           self.assertEqual(UpperCamelCase_    , UpperCamelCase_ )






     @slow
     def    lowerCamelCase__   (		self     :    Optional[int] ):
           lowerCAmelCase    :		Optional[int]				=      self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese''' )

           # Testing tokenization
           lowerCAmelCase    :		Optional[int]				=      '''こんにちは、世界。'''
           lowerCAmelCase    :		Union[str, Any]				=      '''こんばんは、㔺界。😀'''

           lowerCAmelCase    :		Dict				=      len(tokenizer.encode(UpperCamelCase_ ) ) - 2
           lowerCAmelCase    :		List[Any]				=      len(tokenizer.encode(UpperCamelCase_ ) ) - 2

           lowerCAmelCase    :		List[Any]				=      [1] + [0] * (len_prefix + len_text + 1)
           lowerCAmelCase    :		Tuple				=      [1] * (len_prefix + len_text + 1) + [0]
           lowerCAmelCase    :		int				=      [1] + [1] * (len_prefix) + [0] * (len_text + 1)

           lowerCAmelCase    :		Dict				=      tokenizer(prefix_text + input_text ).token_type_ids
           lowerCAmelCase    :		Optional[int]				=      tokenizer(''''''    , prefix_text=prefix_text + input_text ).token_type_ids
           lowerCAmelCase    :		Dict				=      tokenizer(UpperCamelCase_    , prefix_text=UpperCamelCase_ ).token_type_ids
           self.assertListEqual(UpperCamelCase_    , UpperCamelCase_ )
           self.assertListEqual(UpperCamelCase_    , UpperCamelCase_ )
           self.assertListEqual(UpperCamelCase_    , UpperCamelCase_ )






     @slow
     def    lowerCamelCase__   (		self     :    Dict ):
           lowerCAmelCase    :		Optional[Any]				=      self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese''' )

           lowerCAmelCase    :		List[Any]				=      tokenizer.encode('''あンいワ''' )
           lowerCAmelCase    :		List[Any]				=      tokenizer.encode(''''''    , prefix_text='''あンいワ''' )
           lowerCAmelCase    :		List[Any]				=      tokenizer.encode('''いワ'''    , prefix_text='''あン''' )

           self.assertEqual(tokenizer.decode(UpperCamelCase_ )    , tokenizer.decode(UpperCamelCase_ ) )
           self.assertEqual(tokenizer.decode(UpperCamelCase_ )    , tokenizer.decode(UpperCamelCase_ ) )
           self.assertNotEqual(UpperCamelCase_    , UpperCamelCase_ )
           self.assertNotEqual(UpperCamelCase_    , UpperCamelCase_ )
           self.assertEqual(x_token_a[1]    , x_token_a[-1] )  # SEG token
           self.assertEqual(x_token_a[1]    , x_token_a[3] )  # SEG token






     @slow
     def    lowerCamelCase__   (		self     :    Union[str, Any] ):
           lowerCAmelCase    :		Optional[int]				=      self.tokenizer_class.from_pretrained('''Tanrei/GPTSAN-japanese''' )

           lowerCAmelCase    :		List[Any]				=      [['''武田信玄''', '''は、'''], ['''織田信長''', '''の配下の、''']]
           lowerCAmelCase    :		List[str]				=      tokenizer(UpperCamelCase_    , padding=UpperCamelCase_ )
           lowerCAmelCase    :		Optional[Any]				=      tokenizer.batch_encode_plus(UpperCamelCase_    , padding=UpperCamelCase_ )

           # fmt: off
           lowerCAmelCase    :		Optional[Any]				=      [[3_5_9_9_3, 8_6_4_0, 2_5_9_4_8, 3_5_9_9_8, 3_0_6_4_7, 3_5_6_7_5, 3_5_9_9_9, 3_5_9_9_9], [3_5_9_9_3, 1_0_3_8_2, 9_8_6_8, 3_5_9_9_8, 3_0_6_4_6, 9_4_5_9, 3_0_6_4_6, 3_5_6_7_5]]
           lowerCAmelCase    :		Tuple				=      [[1, 1, 1, 0, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 0]]
           lowerCAmelCase    :		int				=      [[1, 1, 1, 1, 1, 1, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1]]
           # fmt: on
           self.assertListEqual(x_token.input_ids    , UpperCamelCase_ )
           self.assertListEqual(x_token.token_type_ids    , UpperCamelCase_ )
           self.assertListEqual(x_token.attention_mask    , UpperCamelCase_ )
           self.assertListEqual(x_token_a.input_ids    , UpperCamelCase_ )
           self.assertListEqual(x_token_a.token_type_ids    , UpperCamelCase_ )
           self.assertListEqual(x_token_a.attention_mask    , UpperCamelCase_ )






     def    lowerCamelCase__   (		self     :    Optional[int] ):
           # Intentionally convert some words to accommodate character fluctuations unique to Japanese
           pass






     def    lowerCamelCase__   (		self     :    int ):
           # tokenizer has no padding token
           pass






"""simple docstring"""





def    _snake_case  (  _snake_case :	list	):

      def merge(_snake_case :	list       ,      _snake_case :	list	) -> list:

            def _merge():
                  while left and right:
                        yield (left if left[0] <= right[0] else right).pop(0	)
                  yield from left
                  yield from right

            return list(_merge()	)

      if len(_snake_case	) <= 1:
            return collection
      lowerCAmelCase    :		Union[str, Any]				=      len(_snake_case	) // 2
      return merge(merge_sort(collection[:mid]	)       ,      merge_sort(collection[mid:]	)	)


if __name__ == "__main__":
 import doctest

 doctest.testmod()
 snake_case__						:   Optional[Any]			 = input('''Enter numbers separated by a comma:\n''').strip()
 snake_case__						:   Union[str, Any]			 = [int(item) for item in user_input.split(''',''')]
 print(*merge_sort(unsorted), sep=''',''')


