




import json
from typing import List, Optional, Tuple

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_bart import BartTokenizer


UpperCAmelCase_						=logging.get_logger(__name__)


UpperCAmelCase_						={"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt""", """tokenizer_file""": """tokenizer.json"""}

# See all BART models at https://huggingface.co/models?filter=bart
UpperCAmelCase_						={
    """vocab_file""": {
        """facebook/bart-base""": """https://huggingface.co/facebook/bart-base/resolve/main/vocab.json""",
        """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/vocab.json""",
        """facebook/bart-large-mnli""": """https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json""",
        """facebook/bart-large-cnn""": """https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json""",
        """facebook/bart-large-xsum""": """https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json""",
        """yjernite/bart_eli5""": """https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """facebook/bart-base""": """https://huggingface.co/facebook/bart-base/resolve/main/merges.txt""",
        """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/merges.txt""",
        """facebook/bart-large-mnli""": """https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt""",
        """facebook/bart-large-cnn""": """https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt""",
        """facebook/bart-large-xsum""": """https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt""",
        """yjernite/bart_eli5""": """https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt""",
    },
    """tokenizer_file""": {
        """facebook/bart-base""": """https://huggingface.co/facebook/bart-base/resolve/main/tokenizer.json""",
        """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/tokenizer.json""",
        """facebook/bart-large-mnli""": """https://huggingface.co/facebook/bart-large-mnli/resolve/main/tokenizer.json""",
        """facebook/bart-large-cnn""": """https://huggingface.co/facebook/bart-large-cnn/resolve/main/tokenizer.json""",
        """facebook/bart-large-xsum""": """https://huggingface.co/facebook/bart-large-xsum/resolve/main/tokenizer.json""",
        """yjernite/bart_eli5""": """https://huggingface.co/yjernite/bart_eli5/resolve/main/tokenizer.json""",
    },
}

UpperCAmelCase_						={
    """facebook/bart-base""": 1024,
    """facebook/bart-large""": 1024,
    """facebook/bart-large-mnli""": 1024,
    """facebook/bart-large-cnn""": 1024,
    """facebook/bart-large-xsum""": 1024,
    """yjernite/bart_eli5""": 1024,
}


class 							__UpperCamelCase			( __UpperCAmelCase  ):





				'''simple docstring'''



				__a							: Tuple										=VOCAB_FILES_NAMES
				__a							: Optional[int]										=PRETRAINED_VOCAB_FILES_MAP
				__a							: Any										=PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
				__a							: Optional[int]										=["""input_ids""", """attention_mask"""]
				__a							: Tuple										=BartTokenizer



				def __init__( self       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_=None       , UpperCAmelCase_="replace"       , UpperCAmelCase_="<s>"       , UpperCAmelCase_="</s>"       , UpperCAmelCase_="</s>"       , UpperCAmelCase_="<s>"       , UpperCAmelCase_="<unk>"       , UpperCAmelCase_="<pad>"       , UpperCAmelCase_="<mask>"       , UpperCAmelCase_=False       , UpperCAmelCase_=True       , **UpperCAmelCase_       , ):
											super().__init__(
											    UpperCAmelCase_       , UpperCAmelCase_       , tokenizer_file=UpperCAmelCase_       , errors=UpperCAmelCase_       , bos_token=UpperCAmelCase_       , eos_token=UpperCAmelCase_       , sep_token=UpperCAmelCase_       , cls_token=UpperCAmelCase_       , unk_token=UpperCAmelCase_       , pad_token=UpperCAmelCase_       , mask_token=UpperCAmelCase_       , add_prefix_space=UpperCAmelCase_       , trim_offsets=UpperCAmelCase_       , **UpperCAmelCase_       , )

											lowerCAmelCase   =		json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()						)
											if pre_tok_state.get('''add_prefix_space'''       , UpperCAmelCase_						) != add_prefix_space:
																		lowerCAmelCase   =		getattr(UpperCAmelCase_       , pre_tok_state.pop('''type'''						)						)
																		lowerCAmelCase   =		add_prefix_space
																		lowerCAmelCase   =		pre_tok_class(**UpperCAmelCase_						)

											lowerCAmelCase   =		add_prefix_space

											# the pre_tokenizer is already updated in the GPT2TokenizerFast `__init__`
											lowerCAmelCase   =		'''post_processor'''
											lowerCAmelCase   =		getattr(self.backend_tokenizer       , UpperCAmelCase_       , UpperCAmelCase_						)
											if tokenizer_component_instance:
																		lowerCAmelCase   =		json.loads(tokenizer_component_instance.__getstate__()						)

																		# The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
																		if "sep" in state:
																									lowerCAmelCase   =		tuple(state['''sep''']						)
																		if "cls" in state:
																									lowerCAmelCase   =		tuple(state['''cls''']						)

																		lowerCAmelCase   =		False

																		if state.get('''add_prefix_space'''       , UpperCAmelCase_						) != add_prefix_space:
																									lowerCAmelCase   =		add_prefix_space
																									lowerCAmelCase   =		True

																		if state.get('''trim_offsets'''       , UpperCAmelCase_						) != trim_offsets:
																									lowerCAmelCase   =		trim_offsets
																									lowerCAmelCase   =		True

																		if changes_to_apply:
																									lowerCAmelCase   =		getattr(UpperCAmelCase_       , state.pop('''type'''						)						)
																									lowerCAmelCase   =		component_class(**UpperCAmelCase_						)
																									setattr(self.backend_tokenizer       , UpperCAmelCase_       , UpperCAmelCase_						)



				@property
				def       __snake_case		( self						):
											if self._mask_token is None:
																		if self.verbose:
																									logger.error('''Using mask_token, but it is not set yet.'''						)
																		return None
											return str(self._mask_token						)



				@mask_token.setter
				def       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   =		AddedToken(UpperCAmelCase_       , lstrip=UpperCAmelCase_       , rstrip=UpperCAmelCase_						) if isinstance(UpperCAmelCase_       , UpperCAmelCase_						) else value
											lowerCAmelCase   =		value



				def       __snake_case		( self       , *UpperCAmelCase_       , **UpperCAmelCase_						):
											lowerCAmelCase   =		kwargs.get('''is_split_into_words'''       , UpperCAmelCase_						)

											if is_split_into_words and not self.add_prefix_space:
																		raise ValueError(
																		    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
																		    '''to use it with pretokenized inputs.'''						)

											return super()._batch_encode_plus(*UpperCAmelCase_       , **UpperCAmelCase_						)



				def       __snake_case		( self       , *UpperCAmelCase_       , **UpperCAmelCase_						):
											lowerCAmelCase   =		kwargs.get('''is_split_into_words'''       , UpperCAmelCase_						)

											if is_split_into_words and not self.add_prefix_space:
																		raise ValueError(
																		    F"""You need to instantiate {self.__class__.__name__} with add_prefix_space=True """
																		    '''to use it with pretokenized inputs.'''						)

											return super()._encode_plus(*UpperCAmelCase_       , **UpperCAmelCase_						)



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_ = None						):
											lowerCAmelCase   =		self._tokenizer.model.save(UpperCAmelCase_       , name=UpperCAmelCase_						)
											return tuple(UpperCAmelCase_						)



				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_=None						):
											lowerCAmelCase   =		[self.bos_token_id] + token_ids_a + [self.eos_token_id]
											if token_ids_a is None:
																		return output

											return output + [self.eos_token_id] + token_ids_a + [self.eos_token_id]






				def       __snake_case		( self       , UpperCAmelCase_       , UpperCAmelCase_ = None						):
											lowerCAmelCase   =		[self.sep_token_id]
											lowerCAmelCase   =		[self.cls_token_id]

											if token_ids_a is None:
																		return len(cls + token_ids_a + sep						) * [0]
											return len(cls + token_ids_a + sep + sep + token_ids_a + sep						) * [0]









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							: Any										=BertJapaneseTokenizer
				__a							: Optional[int]										=False
				__a							: int										=True



				def       __snake_case		( self						):
											super().setUp()

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

											lowerCAmelCase   =		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       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   =		'''こんにちは、世界。 \nこんばんは、世界。'''
											lowerCAmelCase   =		'''こんにちは 、 世界 。 こんばんは 、 世界 。'''
											return input_text, output_text



				def       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   ,     lowerCAmelCase   =		self.get_input_output_texts(UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.encode(UpperCAmelCase_       , add_special_tokens=UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.decode(UpperCAmelCase_       , clean_up_tokenization_spaces=UpperCAmelCase_						)
											return text, ids



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file						)

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , word_tokenizer_type='''mecab'''						)
											self.assertIsNotNone(UpperCAmelCase_						)

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

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

											with open(UpperCAmelCase_       , '''rb'''						) as handle:
																		lowerCAmelCase   =		pickle.load(UpperCAmelCase_						)

											lowerCAmelCase   =		tokenizer_new.tokenize(UpperCAmelCase_						)

											self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_						)



				def       __snake_case		( self						):
											lowerCAmelCase   =		MecabTokenizer(mecab_dic='''ipadic'''						)

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



				def       __snake_case		( self						):
											try:
																		lowerCAmelCase   =		MecabTokenizer(mecab_dic='''unidic_lite'''						)
											except ModuleNotFoundError:
																		return

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



				def       __snake_case		( self						):
											try:
																		lowerCAmelCase   =		MecabTokenizer(mecab_dic='''unidic'''						)
											except ModuleNotFoundError:
																		return

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		MecabTokenizer(do_lower_case=UpperCAmelCase_       , mecab_dic='''ipadic'''						)

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



				def       __snake_case		( self						):
											try:
																		lowerCAmelCase   =		MecabTokenizer(
																		    do_lower_case=UpperCAmelCase_       , normalize_text=UpperCAmelCase_       , 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       __snake_case		( self						):
											lowerCAmelCase   =		MecabTokenizer(normalize_text=UpperCAmelCase_       , mecab_dic='''ipadic'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , word_tokenizer_type='''sudachi'''						)
											self.assertIsNotNone(UpperCAmelCase_						)

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

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

											with open(UpperCAmelCase_       , '''rb'''						) as handle:
																		lowerCAmelCase   =		pickle.load(UpperCAmelCase_						)

											lowerCAmelCase   =		tokenizer_new.tokenize(UpperCAmelCase_						)

											self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_						)



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''       , sudachi_split_mode='''A'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''       , sudachi_split_mode='''B'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(sudachi_dict_type='''core'''       , sudachi_split_mode='''C'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(do_lower_case=UpperCAmelCase_       , sudachi_dict_type='''core'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(normalize_text=UpperCAmelCase_       , sudachi_dict_type='''core'''						)

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



				@require_sudachi
				def       __snake_case		( self						):
											lowerCAmelCase   =		SudachiTokenizer(trim_whitespace=UpperCAmelCase_       , sudachi_dict_type='''core'''						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , word_tokenizer_type='''jumanpp'''						)
											self.assertIsNotNone(UpperCAmelCase_						)

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

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

											with open(UpperCAmelCase_       , '''rb'''						) as handle:
																		lowerCAmelCase   =		pickle.load(UpperCAmelCase_						)

											lowerCAmelCase   =		tokenizer_new.tokenize(UpperCAmelCase_						)

											self.assertListEqual(UpperCAmelCase_       , UpperCAmelCase_						)



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer()

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer(do_lower_case=UpperCAmelCase_						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer(normalize_text=UpperCAmelCase_						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer(trim_whitespace=UpperCAmelCase_						)

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



				@require_jumanpp
				def       __snake_case		( self						):
											lowerCAmelCase   =		JumanppTokenizer()

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こんにちは''', '''こん''', '''にちは''', '''ばんは''', '''##こん''', '''##にちは''', '''##ばんは''']

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

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

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

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

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		BertJapaneseTokenizer.from_pretrained('''nlp-waseda/roberta-base-japanese-with-auto-jumanpp'''						)
											lowerCAmelCase   =		tokenizer.subword_tokenizer

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

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






				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese'''						)

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

											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_       , UpperCAmelCase_						)

											# 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							: Optional[int]										=False



				def       __snake_case		( self						):
											super().setUp()

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

											lowerCAmelCase   =		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       __snake_case		( self       , **UpperCAmelCase_						):
											return BertJapaneseTokenizer.from_pretrained(self.tmpdirname       , subword_tokenizer_type='''character'''       , **UpperCAmelCase_						)



				def       __snake_case		( self       , UpperCAmelCase_						):
											lowerCAmelCase   =		'''こんにちは、世界。 \nこんばんは、世界。'''
											lowerCAmelCase   =		'''こ ん に ち は 、 世 界 。 こ ん ば ん は 、 世 界 。'''
											return input_text, output_text



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											pass  # TODO add if relevant



				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class(self.vocab_file       , subword_tokenizer_type='''character'''						)

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



				def       __snake_case		( self						):
											lowerCAmelCase   =		['''[UNK]''', '''[CLS]''', '''[SEP]''', '''こ''', '''ん''', '''に''', '''ち''', '''は''', '''ば''', '''世''', '''界''', '''、''', '''。''']

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

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

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

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






				def       __snake_case		( self						):
											lowerCAmelCase   =		self.tokenizer_class.from_pretrained('''cl-tohoku/bert-base-japanese-char'''						)

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

											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_						)
											lowerCAmelCase   =		tokenizer.build_inputs_with_special_tokens(UpperCAmelCase_       , UpperCAmelCase_						)

											# 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       __snake_case		( self						):
											lowerCAmelCase   =		'''cl-tohoku/bert-base-japanese'''
											lowerCAmelCase   =		AutoTokenizer.from_pretrained(UpperCAmelCase_						)
											self.assertIsInstance(UpperCAmelCase_       , UpperCAmelCase_						)




class 							__UpperCamelCase			( unittest.TestCase  ):





				'''simple docstring'''



				def       __snake_case		( self						):
											lowerCAmelCase   =		'''cl-tohoku/bert-base-japanese'''
											with self.assertLogs('''transformers'''       , level='''WARNING'''						) as cm:
																		BertTokenizer.from_pretrained(UpperCAmelCase_						)
																		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.'''						)						)
											lowerCAmelCase   =		'''bert-base-cased'''
											with self.assertLogs('''transformers'''       , level='''WARNING'''						) as cm:
																		BertJapaneseTokenizer.from_pretrained(UpperCAmelCase_						)
																		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.'''						)						)



