'''simple docstring'''




import json
import os
import re
import unicodedata
from json.encoder import INFINITY
from typing import Any, Dict, List, Optional, Tuple, Union

import numpy as np
import regex

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...tokenization_utils_base import BatchEncoding
from ...utils import TensorType, is_flax_available, is_tf_available, is_torch_available, logging
from ...utils.generic import _is_jax, _is_numpy


__UpperCAmelCase     							=logging.get_logger(__name__)

__UpperCAmelCase     							={
    """artists_file""": """artists.json""",
    """lyrics_file""": """lyrics.json""",
    """genres_file""": """genres.json""",
}

__UpperCAmelCase     							={
    """artists_file""": {
        """jukebox""": """https://huggingface.co/ArthurZ/jukebox/blob/main/artists.json""",
    },
    """genres_file""": {
        """jukebox""": """https://huggingface.co/ArthurZ/jukebox/blob/main/genres.json""",
    },
    """lyrics_file""": {
        """jukebox""": """https://huggingface.co/ArthurZ/jukebox/blob/main/lyrics.json""",
    },
}

__UpperCAmelCase     							={
    """jukebox""": 5_1_2,
}




class     a__      (   _UpperCAmelCase ):
     lowerCamelCase  :     Any							=VOCAB_FILES_NAMES
     lowerCamelCase  :     Dict							=PRETRAINED_VOCAB_FILES_MAP
     lowerCamelCase  :     int							=PRETRAINED_LYRIC_TOKENS_SIZES
     lowerCamelCase  :     Any							=['''input_ids''', '''attention_mask''']






     def __init__( self		:		Optional[int]  ,				a		:		Optional[int]  ,				a		:		Tuple  ,				a		:		Tuple  ,				a		:		Dict=["v3", "v2", "v2"]  ,				a		:		int=5_12  ,				a		:		Union[str, Any]=5  ,				a		:		str="<|endoftext|>"  ,				**a		:		List[Any]  ,				):





         """simple docstring"""



         __lowerCamelCase		=  AddedToken(lowerCAmelCase__  ,				lstrip=lowerCAmelCase__  ,				rstrip=lowerCAmelCase__    ) if isinstance(lowerCAmelCase__  ,				lowerCAmelCase__    ) else unk_token
         super().__init__(
             unk_token=lowerCAmelCase__  ,				n_genres=lowerCAmelCase__  ,				version=lowerCAmelCase__  ,				max_n_lyric_tokens=lowerCAmelCase__  ,				**lowerCAmelCase__  ,				)
         __lowerCamelCase		=  version
         __lowerCamelCase		=  max_n_lyric_tokens
         __lowerCamelCase		=  n_genres

         with open(lowerCAmelCase__  ,				encoding='''utf-8'''    ) as vocab_handle:
             __lowerCamelCase		=  json.load(lowerCAmelCase__    )

         with open(lowerCAmelCase__  ,				encoding='''utf-8'''    ) as vocab_handle:
             __lowerCamelCase		=  json.load(lowerCAmelCase__    )

         with open(lowerCAmelCase__  ,				encoding='''utf-8'''    ) as vocab_handle:
             __lowerCamelCase		=  json.load(lowerCAmelCase__    )

         __lowerCamelCase		=  R'''[^A-Za-z0-9.,:;!?\-\'\"()\[\] \t\n]+'''
         # In v2, we had a n_vocab=80 and in v3 we missed + and so n_vocab=79 of characters.
         if len(self.lyrics_encoder    ) == 79:
             __lowerCamelCase		=  oov.replace(R'''\-\''''  ,				R'''\-+\''''    )

         __lowerCamelCase		=  regex.compile(lowerCAmelCase__    )
         __lowerCamelCase		=  {v: k for k, v in self.artists_encoder.items()}
         __lowerCamelCase		=  {v: k for k, v in self.genres_encoder.items()}
         __lowerCamelCase		=  {v: k for k, v in self.lyrics_encoder.items()}






     @property
     def    SCREAMING_SNAKE_CASE__   ( self		:		List[Any]    ):





         """simple docstring"""



         return len(self.artists_encoder    ) + len(self.genres_encoder    ) + len(self.lyrics_encoder    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Any    ):





         """simple docstring"""



         return dict(self.artists_encoder  ,				self.genres_encoder  ,				self.lyrics_encoder    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]  ,				a		:		Any  ,				a		:		Dict  ,				a		:		List[Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  [self.artists_encoder.get(lowerCAmelCase__  ,				0    ) for artist in list_artists]
         for genres in range(len(lowerCAmelCase__    )    ):
             __lowerCamelCase		=  [self.genres_encoder.get(lowerCAmelCase__  ,				0    ) for genre in list_genres[genres]]
             __lowerCamelCase		=  list_genres[genres] + [-1] * (self.n_genres - len(list_genres[genres]    ))

         __lowerCamelCase		=  [[self.lyrics_encoder.get(lowerCAmelCase__  ,				0    ) for character in list_lyrics[0]], [], []]
         return artists_id, list_genres, lyric_ids






     def    SCREAMING_SNAKE_CASE__   ( self		:		Union[str, Any]  ,				a		:		Optional[Any]    ):





         """simple docstring"""



         return list(lowerCAmelCase__    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		List[str]  ,				a		:		Union[str, Any]  ,				a		:		Union[str, Any]  ,				a		:		List[str]  ,				**a		:		Optional[Any]    ):





         """simple docstring"""



         __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase		=  self.prepare_for_tokenization(lowerCAmelCase__  ,				lowerCAmelCase__  ,				lowerCAmelCase__    )
         __lowerCamelCase		=  self._tokenize(lowerCAmelCase__    )
         return artist, genre, lyrics






     def    SCREAMING_SNAKE_CASE__   ( self		:		Dict  ,				a		:		Optional[Any]  ,				a		:		Optional[int]  ,				a		:		str  ,				a		:		List[Any] = False    ):





         """simple docstring"""



         for idx in range(len(self.version    )    ):
             if self.version[idx] == "v3":
                 __lowerCamelCase		=  artists[idx].lower()
                 __lowerCamelCase		=  [genres[idx].lower()]
             else:
                 __lowerCamelCase		=  self._normalize(artists[idx]    ) + '''.v2'''
                 __lowerCamelCase		=  [
                     self._normalize(lowerCAmelCase__    ) + '''.v2''' for genre in genres[idx].split('''_'''    )
                 ]  # split is for the full dictionary with combined genres

         if self.version[0] == "v2":
             __lowerCamelCase		=  regex.compile(R'''[^A-Za-z0-9.,:;!?\-\'\"()\[\] \t\n]+'''    )
             __lowerCamelCase		=  '''ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.,:;!?-+\'\"()[] \t\n'''
             __lowerCamelCase		=  {vocab[index]: index + 1 for index in range(len(lowerCAmelCase__    )    )}
             __lowerCamelCase		=  0
             __lowerCamelCase		=  len(lowerCAmelCase__    ) + 1
             __lowerCamelCase		=  self.vocab
             __lowerCamelCase		=  {v: k for k, v in self.vocab.items()}
             __lowerCamelCase		=  ''''''
         else:
             __lowerCamelCase		=  regex.compile(R'''[^A-Za-z0-9.,:;!?\-+\'\"()\[\] \t\n]+'''    )

         __lowerCamelCase		=  self._run_strip_accents(lowerCAmelCase__    )
         __lowerCamelCase		=  lyrics.replace('''\\'''  ,				'''\n'''    )
         __lowerCamelCase		=  self.out_of_vocab.sub(''''''  ,				lowerCAmelCase__    ), [], []
         return artists, genres, lyrics






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]  ,				a		:		Tuple    ):





         """simple docstring"""



         __lowerCamelCase		=  unicodedata.normalize('''NFD'''  ,				lowerCAmelCase__    )
         __lowerCamelCase		=  []
         for char in text:
             __lowerCamelCase		=  unicodedata.category(lowerCAmelCase__    )
             if cat == "Mn":
                 continue
             output.append(lowerCAmelCase__    )
         return "".join(lowerCAmelCase__    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[int]  ,				a		:		str    ):





         """simple docstring"""



         __lowerCamelCase		=  (
             [chr(lowerCAmelCase__    ) for i in range(ord('''a'''    )  ,				ord('''z'''    ) + 1    )]
             + [chr(lowerCAmelCase__    ) for i in range(ord('''A'''    )  ,				ord('''Z'''    ) + 1    )]
             + [chr(lowerCAmelCase__    ) for i in range(ord('''0'''    )  ,				ord('''9'''    ) + 1    )]
             + ['''.''']
         )
         __lowerCamelCase		=  frozenset(lowerCAmelCase__    )
         __lowerCamelCase		=  re.compile(R'''_+'''    )
         __lowerCamelCase		=  ''''''.join([c if c in accepted else '''_''' for c in text.lower()]    )
         __lowerCamelCase		=  pattern.sub('''_'''  ,				lowerCAmelCase__    ).strip('''_'''    )
         return text






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]  ,				a		:		Optional[int]    ):





         """simple docstring"""



         return " ".join(lowerCAmelCase__    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]  ,				a		:		Tuple  ,				a		:		Union[str, Any] = None  ,				a		:		List[str] = False    ):





         """simple docstring"""



         if not isinstance(lowerCAmelCase__  ,				lowerCAmelCase__    ):
             __lowerCamelCase		=  TensorType(lowerCAmelCase__    )

         # Get a function reference for the correct framework
         if tensor_type == TensorType.TENSORFLOW:
             if not is_tf_available():
                 raise ImportError(
                     '''Unable to convert output to TensorFlow tensors format, TensorFlow is not installed.'''    )
             import tensorflow as tf

             __lowerCamelCase		=  tf.constant
             __lowerCamelCase		=  tf.is_tensor
         elif tensor_type == TensorType.PYTORCH:
             if not is_torch_available():
                 raise ImportError('''Unable to convert output to PyTorch tensors format, PyTorch is not installed.'''    )
             import torch

             __lowerCamelCase		=  torch.tensor
             __lowerCamelCase		=  torch.is_tensor
         elif tensor_type == TensorType.JAX:
             if not is_flax_available():
                 raise ImportError('''Unable to convert output to JAX tensors format, JAX is not installed.'''    )
             import jax.numpy as jnp  # noqa: F811

             __lowerCamelCase		=  jnp.array
             __lowerCamelCase		=  _is_jax
         else:
             __lowerCamelCase		=  np.asarray
             __lowerCamelCase		=  _is_numpy

         # Do the tensor conversion in batch

         try:
             if prepend_batch_axis:
                 __lowerCamelCase		=  [inputs]

             if not is_tensor(lowerCAmelCase__    ):
                 __lowerCamelCase		=  as_tensor(lowerCAmelCase__    )
         except:  # noqa E722
             raise ValueError(
                 '''Unable to create tensor, you should probably activate truncation and/or padding '''
                 '''with \'padding=True\' \'truncation=True\' to have batched tensors with the same length.'''    )

         return inputs






     def __call__( self		:		Optional[Any]  ,				a		:		Union[str, Any]  ,				a		:		int  ,				a		:		Any=""  ,				a		:		int="pt"    ):





         """simple docstring"""



         __lowerCamelCase		=  [0, 0, 0]
         __lowerCamelCase		=  [artist] * len(self.version    )
         __lowerCamelCase		=  [genres] * len(self.version    )

         __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase		=  self.tokenize(lowerCAmelCase__  ,				lowerCAmelCase__  ,				lowerCAmelCase__    )
         __lowerCamelCase	,  __lowerCamelCase	,  __lowerCamelCase		=  self._convert_token_to_id(lowerCAmelCase__  ,				lowerCAmelCase__  ,				lowerCAmelCase__    )

         __lowerCamelCase		=  [-INFINITY] * len(full_tokens[-1]    )
         __lowerCamelCase		=  [
             self.convert_to_tensors(
                 [input_ids + [artists_id[i]] + genres_ids[i] + full_tokens[i]]  ,				tensor_type=lowerCAmelCase__    )
             for i in range(len(self.version    )    )
         ]
         return BatchEncoding({'''input_ids''': input_ids, '''attention_masks''': attention_masks}    )






     def    SCREAMING_SNAKE_CASE__   ( self		:		int  ,				a		:		Any  ,				a		:		Any = None    ):





         """simple docstring"""



         if not os.path.isdir(lowerCAmelCase__    ):
             logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""    )
             return

         __lowerCamelCase		=  os.path.join(
             lowerCAmelCase__  ,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''artists_file''']    )
         with open(lowerCAmelCase__  ,				'''w'''  ,				encoding='''utf-8'''    ) as f:
             f.write(json.dumps(self.artists_encoder  ,				ensure_ascii=lowerCAmelCase__    )    )

         __lowerCamelCase		=  os.path.join(
             lowerCAmelCase__  ,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''genres_file''']    )
         with open(lowerCAmelCase__  ,				'''w'''  ,				encoding='''utf-8'''    ) as f:
             f.write(json.dumps(self.genres_encoder  ,				ensure_ascii=lowerCAmelCase__    )    )

         __lowerCamelCase		=  os.path.join(
             lowerCAmelCase__  ,				(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''lyrics_file''']    )
         with open(lowerCAmelCase__  ,				'''w'''  ,				encoding='''utf-8'''    ) as f:
             f.write(json.dumps(self.lyrics_encoder  ,				ensure_ascii=lowerCAmelCase__    )    )

         return (artists_file, genres_file, lyrics_file)






     def    SCREAMING_SNAKE_CASE__   ( self		:		Optional[Any]  ,				a		:		Union[str, Any]  ,				a		:		int  ,				a		:		Optional[Any]    ):





         """simple docstring"""



         __lowerCamelCase		=  self.artists_decoder.get(lowerCAmelCase__    )
         __lowerCamelCase		=  [self.genres_decoder.get(lowerCAmelCase__    ) for genre in genres_index]
         __lowerCamelCase		=  [self.lyrics_decoder.get(lowerCAmelCase__    ) for character in lyric_index]
         return artist, genres, lyrics

import os
import pickle
import unittest

from transformers import AutoTokenizer
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.models.bert_japanese.tokenization_bert_japanese import (
    VOCAB_FILES_NAMES,
    BertJapaneseTokenizer,
    CharacterTokenizer,
    JumanppTokenizer,
    MecabTokenizer,
    SudachiTokenizer,
    WordpieceTokenizer,
)
from transformers.testing_utils import custom_tokenizers, require_jumanpp, require_sudachi

from ...test_tokenization_common import TokenizerTesterMixin




@custom_tokenizers
class    _UpperCamelCase      (						_UpperCAmelCase						,unittest.TestCase ):


			"""simple docstring"""






			__a  : List[Any]			 =						BertJapaneseTokenizer
			__a  : Any			 =						False
			__a  : Optional[int]			 =						True





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

							'''simple docstring'''


							super().setUp()

							__lowercase 			=							[
							    '''[UNK]''',
							    '''[CLS]''',
							    '''[SEP]''',
							    '''こんにちは''',
							    '''こん''',
							    '''にちは''',
							    '''ばんは''',
							    '''##こん''',
							    '''##にちは''',
							    '''##ばんは''',
							    '''世界''',
							    '''##世界''',
							    '''、''',
							    '''##、''',
							    '''。''',
							    '''##。''',
							]

							__lowercase 			=							os.path.join(self.tmpdirname      ,   VOCAB_FILES_NAMES['''vocab_file''']						)
							with open(self.vocab_file      ,   '''w'''      ,   encoding='''utf-8'''						) as vocab_writer:
											vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]						)						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					str:

							'''simple docstring'''


							__lowercase 			=							'''こんにちは、世界。 \nこんばんは、世界。'''
							__lowercase 			=							'''こんにちは 、 世界 。 こんばんは 、 世界 。'''
							return input_text, output_text





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					Dict:

							'''simple docstring'''


							__lowercase			,     __lowercase 			=							self.get_input_output_texts(lowerCAmelCase__						)
							__lowercase 			=							tokenizer.encode(lowerCAmelCase__      ,   add_special_tokens=lowerCAmelCase__						)
							__lowercase 			=							tokenizer.decode(lowerCAmelCase__      ,   clean_up_tokenization_spaces=lowerCAmelCase__						)
							return text, ids





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

							'''simple docstring'''


							pass  # TODO add if relevant





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

							'''simple docstring'''


							pass  # TODO add if relevant





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							pass  # TODO add if relevant





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

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class(self.vocab_file						)

							__lowercase 			=							tokenizer.tokenize('''こんにちは、世界。\nこんばんは、世界。'''						)
							self.assertListEqual(lowerCAmelCase__      ,   ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']						)
							self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__						)      ,   [3, 12, 10, 14, 4, 9, 12, 10, 14]						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class(self.vocab_file      ,   word_tokenizer_type='''mecab'''						)
							self.assertIsNotNone(lowerCAmelCase__						)

							__lowercase 			=							'''こんにちは、世界。\nこんばんは、世界。'''
							__lowercase 			=							tokenizer.tokenize(lowerCAmelCase__						)
							self.assertListEqual(lowerCAmelCase__      ,   ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']						)
							self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__						)      ,   [3, 12, 10, 14, 4, 9, 12, 10, 14]						)

							__lowercase 			=							os.path.join(self.tmpdirname      ,   '''tokenizer.bin'''						)
							with open(lowerCAmelCase__      ,   '''wb'''						) as handle:
											pickle.dump(lowerCAmelCase__      ,   lowerCAmelCase__						)

							with open(lowerCAmelCase__      ,   '''rb'''						) as handle:
											__lowercase 			=							pickle.load(lowerCAmelCase__						)

							__lowercase 			=							tokenizer_new.tokenize(lowerCAmelCase__						)

							self.assertListEqual(lowerCAmelCase__      ,   lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Dict:

							'''simple docstring'''


							__lowercase 			=							MecabTokenizer(mecab_dic='''ipadic'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップルストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']      ,   )





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


							try:
											__lowercase 			=							MecabTokenizer(mecab_dic='''unidic_lite'''						)
							except ModuleNotFoundError:
											return

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']      ,   )





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

							'''simple docstring'''


							try:
											__lowercase 			=							MecabTokenizer(mecab_dic='''unidic'''						)
							except ModuleNotFoundError:
											return

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']      ,   )





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[int]:

							'''simple docstring'''


							__lowercase 			=							MecabTokenizer(do_lower_case=lowerCAmelCase__      ,   mecab_dic='''ipadic'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップルストア''', '''で''', '''iphone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']      ,   )





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					str:

							'''simple docstring'''


							try:
											__lowercase 			=							MecabTokenizer(
											    do_lower_case=lowerCAmelCase__      ,   normalize_text=lowerCAmelCase__      ,   mecab_option='''-d /usr/local/lib/mecab/dic/jumandic'''						)
							except RuntimeError:
											# if dict doesn't exist in the system, previous code raises this error.
											return

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''ｱｯﾌﾟﾙストア''', '''で''', '''iPhone''', '''８''', '''が''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']      ,   )





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

							'''simple docstring'''


							__lowercase 			=							MecabTokenizer(normalize_text=lowerCAmelCase__      ,   mecab_dic='''ipadic'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''ｱｯﾌﾟﾙストア''', '''で''', '''iPhone''', '''８''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''　''', '''。''']      ,   )





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Dict:

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class(self.vocab_file      ,   word_tokenizer_type='''sudachi'''						)
							self.assertIsNotNone(lowerCAmelCase__						)

							__lowercase 			=							'''こんにちは、世界。\nこんばんは、世界。'''
							__lowercase 			=							tokenizer.tokenize(lowerCAmelCase__						)
							self.assertListEqual(lowerCAmelCase__      ,   ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']						)
							self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__						)      ,   [3, 12, 10, 14, 4, 9, 12, 10, 14]						)

							__lowercase 			=							os.path.join(self.tmpdirname      ,   '''tokenizer.bin'''						)
							with open(lowerCAmelCase__      ,   '''wb'''						) as handle:
											pickle.dump(lowerCAmelCase__      ,   lowerCAmelCase__						)

							with open(lowerCAmelCase__      ,   '''rb'''						) as handle:
											__lowercase 			=							pickle.load(lowerCAmelCase__						)

							__lowercase 			=							tokenizer_new.tokenize(lowerCAmelCase__						)

							self.assertListEqual(lowerCAmelCase__      ,   lowerCAmelCase__						)





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Union[str, Any]:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(sudachi_dict_type='''core'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   [''' ''', '''\t''', '''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', ''' ''', '''が''', ''' ''', ''' ''', '''\n ''', '''発売''', '''さ''', '''れ''', '''た''', ''' ''', '''。''', ''' ''', ''' ''']      ,   )





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[int]:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(sudachi_dict_type='''core'''      ,   sudachi_split_mode='''A'''						)

							self.assertListEqual(tokenizer.tokenize('''外国人参政権'''						)      ,   ['''外国''', '''人''', '''参政''', '''権''']						)





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					str:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(sudachi_dict_type='''core'''      ,   sudachi_split_mode='''B'''						)

							self.assertListEqual(tokenizer.tokenize('''外国人参政権'''						)      ,   ['''外国人''', '''参政権''']						)





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(sudachi_dict_type='''core'''      ,   sudachi_split_mode='''C'''						)

							self.assertListEqual(tokenizer.tokenize('''外国人参政権'''						)      ,   ['''外国人参政権''']						)





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					List[Any]:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(do_lower_case=lowerCAmelCase__      ,   sudachi_dict_type='''core'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   [''' ''', '''\t''', '''アップル''', '''ストア''', '''で''', '''iphone''', '''8''', ''' ''', '''が''', ''' ''', ''' ''', '''\n ''', '''発売''', '''さ''', '''れ''', '''た''', ''' ''', '''。''', ''' ''', ''' ''']      ,   )





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Any:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(normalize_text=lowerCAmelCase__      ,   sudachi_dict_type='''core'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   [''' ''', '''\t''', '''ｱｯﾌﾟﾙ''', '''ストア''', '''で''', '''iPhone''', '''８''', ''' ''', '''が''', ''' ''', ''' ''', '''\n ''', '''発売''', '''さ''', '''れ''', '''た''', '''\u3000''', '''。''', ''' ''', ''' ''']      ,   )





			@require_sudachi
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Any:

							'''simple docstring'''


							__lowercase 			=							SudachiTokenizer(trim_whitespace=lowerCAmelCase__      ,   sudachi_dict_type='''core'''						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れ''', '''た''', '''。''']      ,   )





			@require_jumanpp
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					List[Any]:

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class(self.vocab_file      ,   word_tokenizer_type='''jumanpp'''						)
							self.assertIsNotNone(lowerCAmelCase__						)

							__lowercase 			=							'''こんにちは、世界。\nこんばんは、世界。'''
							__lowercase 			=							tokenizer.tokenize(lowerCAmelCase__						)
							self.assertListEqual(lowerCAmelCase__      ,   ['''こんにちは''', '''、''', '''世界''', '''。''', '''こん''', '''##ばんは''', '''、''', '''世界''', '''。''']						)
							self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__						)      ,   [3, 12, 10, 14, 4, 9, 12, 10, 14]						)

							__lowercase 			=							os.path.join(self.tmpdirname      ,   '''tokenizer.bin'''						)
							with open(lowerCAmelCase__      ,   '''wb'''						) as handle:
											pickle.dump(lowerCAmelCase__      ,   lowerCAmelCase__						)

							with open(lowerCAmelCase__      ,   '''rb'''						) as handle:
											__lowercase 			=							pickle.load(lowerCAmelCase__						)

							__lowercase 			=							tokenizer_new.tokenize(lowerCAmelCase__						)

							self.assertListEqual(lowerCAmelCase__      ,   lowerCAmelCase__						)





			@require_jumanpp
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					List[str]:

							'''simple docstring'''


							__lowercase 			=							JumanppTokenizer()

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''\u3000''', '''が''', '''\u3000''', '''\u3000''', '''\u3000''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']      ,   )





			@require_jumanpp
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					List[str]:

							'''simple docstring'''


							__lowercase 			=							JumanppTokenizer(do_lower_case=lowerCAmelCase__						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップル''', '''ストア''', '''で''', '''iphone''', '''8''', '''\u3000''', '''が''', '''\u3000''', '''\u3000''', '''\u3000''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']      ,   )





			@require_jumanpp
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					int:

							'''simple docstring'''


							__lowercase 			=							JumanppTokenizer(normalize_text=lowerCAmelCase__						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''ｱ''', '''ｯ''', '''ﾌ''', '''ﾟ''', '''ﾙ''', '''ストア''', '''で''', '''iPhone''', '''８''', '''\u3000''', '''が''', '''\u3000''', '''\u3000''', '''\u3000''', '''発売''', '''さ''', '''れた''', '''\u3000''', '''。''']      ,   )





			@require_jumanpp
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[int]:

							'''simple docstring'''


							__lowercase 			=							JumanppTokenizer(trim_whitespace=lowerCAmelCase__						)

							self.assertListEqual(
							    tokenizer.tokenize(''' \tｱｯﾌﾟﾙストアでiPhone８ が  \n 発売された　。  '''						)      ,   ['''アップル''', '''ストア''', '''で''', '''iPhone''', '''8''', '''が''', '''発売''', '''さ''', '''れた''', '''。''']      ,   )





			@require_jumanpp
			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							JumanppTokenizer()

							self.assertListEqual(
							    tokenizer.tokenize('''ありがとうございますm(_ _)ｍ見つけるのが大変です。'''						)      ,   ['''ありがとう''', '''ございます''', '''m(_ _)m''', '''見つける''', '''の''', '''が''', '''大変です''', '''。''']      ,   )





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Any:

							'''simple docstring'''


							__lowercase 			=							['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こんにちは''', '''こん''', '''にちは''', '''ばんは''', '''##こん''', '''##にちは''', '''##ばんは''']

							__lowercase 			=							{}
							for i, token in enumerate(lowerCAmelCase__						):
											__lowercase 			=							i
							__lowercase 			=							WordpieceTokenizer(vocab=lowerCAmelCase__      ,   unk_token='''[UNK]'''						)

							self.assertListEqual(tokenizer.tokenize(''''''						)      ,   []						)

							self.assertListEqual(tokenizer.tokenize('''こんにちは'''						)      ,   ['''こんにちは''']						)

							self.assertListEqual(tokenizer.tokenize('''こんばんは'''						)      ,   ['''こん''', '''##ばんは''']						)

							self.assertListEqual(tokenizer.tokenize('''こんばんは こんばんにちは こんにちは'''						)      ,   ['''こん''', '''##ばんは''', '''[UNK]''', '''こんにちは''']						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							BertJapaneseTokenizer.from_pretrained('''nlp-waseda/roberta-base-japanese-with-auto-jumanpp'''						)
							__lowercase 			=							tokenizer.subword_tokenizer

							__lowercase 			=							subword_tokenizer.tokenize('''国境 の 長い トンネル を 抜ける と 雪国 であった 。'''						)
							self.assertListEqual(lowerCAmelCase__      ,   ['''▁国境''', '''▁の''', '''▁長い''', '''▁トンネル''', '''▁を''', '''▁抜ける''', '''▁と''', '''▁雪''', '''国''', '''▁であった''', '''▁。''']						)

							__lowercase 			=							subword_tokenizer.tokenize('''こんばんは こんばん にち は こんにちは'''						)
							self.assertListEqual(lowerCAmelCase__      ,   ['''▁こん''', '''ばん''', '''は''', '''▁こん''', '''ばん''', '''▁に''', '''ち''', '''▁は''', '''▁こんにちは''']						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Optional[int]:

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese'''						)

							__lowercase 			=							tokenizer.encode('''ありがとう。'''      ,   add_special_tokens=lowerCAmelCase__						)
							__lowercase 			=							tokenizer.encode('''どういたしまして。'''      ,   add_special_tokens=lowerCAmelCase__						)

							__lowercase 			=							tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__						)
							__lowercase 			=							tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__      ,   lowerCAmelCase__						)

							# 2 is for "[CLS]", 3 is for "[SEP]"
							assert encoded_sentence == [2] + text + [3]
							assert encoded_pair == [2] + text + [3] + text_a + [3]




@custom_tokenizers
class    _UpperCamelCase      (						_UpperCAmelCase						,unittest.TestCase ):


			"""simple docstring"""






			__a  : Union[str, Any]			 =						BertJapaneseTokenizer
			__a  : Tuple			 =						False





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					str:

							'''simple docstring'''


							super().setUp()

							__lowercase 			=							['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こ''', '''ん''', '''に''', '''ち''', '''は''', '''ば''', '''世''', '''界''', '''、''', '''。''']

							__lowercase 			=							os.path.join(self.tmpdirname      ,   VOCAB_FILES_NAMES['''vocab_file''']						)
							with open(self.vocab_file      ,   '''w'''      ,   encoding='''utf-8'''						) as vocab_writer:
											vocab_writer.write(''''''.join([x + '''\n''' for x in vocab_tokens]						)						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   **lowerCAmelCase__						)     ->					Dict:

							'''simple docstring'''


							return BertJapaneseTokenizer.from_pretrained(self.tmpdirname      ,   subword_tokenizer_type='''character'''      ,   **lowerCAmelCase__						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__						)     ->					List[str]:

							'''simple docstring'''


							__lowercase 			=							'''こんにちは、世界。 \nこんばんは、世界。'''
							__lowercase 			=							'''こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'''
							return input_text, output_text





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

							'''simple docstring'''


							pass  # TODO add if relevant





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

							'''simple docstring'''


							pass  # TODO add if relevant





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

							'''simple docstring'''


							pass  # TODO add if relevant





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

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class(self.vocab_file      ,   subword_tokenizer_type='''character'''						)

							__lowercase 			=							tokenizer.tokenize('''こんにちは、世界。 \nこんばんは、世界。'''						)
							self.assertListEqual(
							    lowerCAmelCase__      ,   ['''こ''', '''ん''', '''に''', '''ち''', '''は''', '''、''', '''世''', '''界''', '''。''', '''こ''', '''ん''', '''ば''', '''ん''', '''は''', '''、''', '''世''', '''界''', '''。''']						)
							self.assertListEqual(
							    tokenizer.convert_tokens_to_ids(lowerCAmelCase__						)      ,   [3, 4, 5, 6, 7, 11, 9, 10, 12, 3, 4, 8, 4, 7, 11, 9, 10, 12]						)





			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Dict:

							'''simple docstring'''


							__lowercase 			=							['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こ''', '''ん''', '''に''', '''ち''', '''は''', '''ば''', '''世''', '''界''', '''、''', '''。''']

							__lowercase 			=							{}
							for i, token in enumerate(lowerCAmelCase__						):
											__lowercase 			=							i
							__lowercase 			=							CharacterTokenizer(vocab=lowerCAmelCase__      ,   unk_token='''[UNK]'''						)

							self.assertListEqual(tokenizer.tokenize(''''''						)      ,   []						)

							self.assertListEqual(tokenizer.tokenize('''こんにちは'''						)      ,   ['''こ''', '''ん''', '''に''', '''ち''', '''は''']						)

							self.assertListEqual(tokenizer.tokenize('''こんにちほ'''						)      ,   ['''こ''', '''ん''', '''に''', '''ち''', '''[UNK]''']						)





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

							'''simple docstring'''


							__lowercase 			=							self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese-char'''						)

							__lowercase 			=							tokenizer.encode('''ありがとう。'''      ,   add_special_tokens=lowerCAmelCase__						)
							__lowercase 			=							tokenizer.encode('''どういたしまして。'''      ,   add_special_tokens=lowerCAmelCase__						)

							__lowercase 			=							tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__						)
							__lowercase 			=							tokenizer.build_inputs_with_special_tokens(lowerCAmelCase__      ,   lowerCAmelCase__						)

							# 2 is for "[CLS]", 3 is for "[SEP]"
							assert encoded_sentence == [2] + text + [3]
							assert encoded_pair == [2] + text + [3] + text_a + [3]




@custom_tokenizers
class    _UpperCamelCase      (						unittest.TestCase ):


			"""simple docstring"""






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

							'''simple docstring'''


							__lowercase 			=							'''cl-tohoku/bert-base-japanese'''
							__lowercase 			=							AutoTokenizer.from_pretrained(lowerCAmelCase__						)
							self.assertIsInstance(lowerCAmelCase__      ,   lowerCAmelCase__						)




class    _UpperCamelCase      (						unittest.TestCase ):


			"""simple docstring"""






			def        _SCREAMING_SNAKE_CASE			(   self						)     ->					Tuple:

							'''simple docstring'''


							__lowercase 			=							'''cl-tohoku/bert-base-japanese'''
							with self.assertLogs('''transformers'''      ,   level='''WARNING'''						) as cm:
											BertTokenizer.from_pretrained(lowerCAmelCase__						)
											self.assertTrue(
											    cm.records[0].message.startswith(
											        '''The tokenizer class you load from this checkpoint is not the same type as the class this function'''
											        ''' is called from.'''						)						)
							__lowercase 			=							'''bert-base-cased'''
							with self.assertLogs('''transformers'''      ,   level='''WARNING'''						) as cm:
											BertJapaneseTokenizer.from_pretrained(lowerCAmelCase__						)
											self.assertTrue(
											    cm.records[0].message.startswith(
											        '''The tokenizer class you load from this checkpoint is not the same type as the class this function'''
											        ''' is called from.'''						)						)