





"""simple docstring"""





import os
from shutil import copyfile
from typing import List, Optional, Tuple

from tokenizers import processors

from ...tokenization_utils import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
						from .tokenization_mbart import MBartTokenizer
else:
						lowerCAmelCase__     			=			None


lowerCAmelCase__     			=			logging.get_logger(__name__)


lowerCAmelCase__     			=			{'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

lowerCAmelCase__     			=			{
    '''vocab_file''': {
        '''facebook/mbart-large-en-ro''': (
            '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/sentencepiece.bpe.model'''
        ),
        '''facebook/mbart-large-cc25''': (
            '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/mbart-large-en-ro''': '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/tokenizer.json''',
        '''facebook/mbart-large-cc25''': '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/tokenizer.json''',
    },
}

lowerCAmelCase__     			=			{
    '''facebook/mbart-large-en-ro''': 1_024,
    '''facebook/mbart-large-cc25''': 1_024,
}

# fmt: off
lowerCAmelCase__     			=			['''ar_AR''', '''cs_CZ''', '''de_DE''', '''en_XX''', '''es_XX''', '''et_EE''', '''fi_FI''', '''fr_XX''', '''gu_IN''', '''hi_IN''', '''it_IT''', '''ja_XX''', '''kk_KZ''', '''ko_KR''', '''lt_LT''', '''lv_LV''', '''my_MM''', '''ne_NP''', '''nl_XX''', '''ro_RO''', '''ru_RU''', '''si_LK''', '''tr_TR''', '''vi_VN''', '''zh_CN''']





class        _lowerCamelCase      (       _lowercase ):
						UpperCAmelCase_ =			VOCAB_FILES_NAMES
						UpperCAmelCase_ =			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						UpperCAmelCase_ =			PRETRAINED_VOCAB_FILES_MAP
						UpperCAmelCase_ =			["input_ids", "attention_mask"]
						UpperCAmelCase_ =			MBartTokenizer

						UpperCAmelCase_ =			[]
						UpperCAmelCase_ =			[]


						def __init__(self   ,							__a=None   ,							__a=None   ,							__a="<s>"   ,							__a="</s>"   ,							__a="</s>"   ,							__a="<s>"   ,							__a="<unk>"   ,							__a="<pad>"   ,							__a="<mask>"   ,							__a=None   ,							__a=None   ,							__a=None   ,							**__a   ,							) ->   Tuple:
								# Mask token behave like a normal word, i.e. include the space before it
								UpperCamelCase   =	AddedToken(__a   ,							lstrip=__a   ,							rstrip=__a		) if isinstance(__a   ,							__a		) else mask_token

								super().__init__(
								    vocab_file=__a   ,							tokenizer_file=__a   ,							bos_token=__a   ,							eos_token=__a   ,							sep_token=__a   ,							cls_token=__a   ,							unk_token=__a   ,							pad_token=__a   ,							mask_token=__a   ,							src_lang=__a   ,							tgt_lang=__a   ,							additional_special_tokens=__a   ,							**__a   ,							)

								UpperCamelCase   =	vocab_file
								UpperCamelCase   =	False if not self.vocab_file else True

								UpperCamelCase   =	FAIRSEQ_LANGUAGE_CODES.copy()

								if additional_special_tokens is not None:
										# Only add those special tokens if they are not already there.
										_additional_special_tokens.extend(
										    [t for t in additional_special_tokens if t not in _additional_special_tokens]		)

								self.add_special_tokens({"additional_special_tokens": _additional_special_tokens}		)
								UpperCamelCase   =	{
								    lang_code: self.convert_tokens_to_ids(__a		) for lang_code in FAIRSEQ_LANGUAGE_CODES
								}

								UpperCamelCase   =	src_lang if src_lang is not None else "en_XX"
								UpperCamelCase   =	self.convert_tokens_to_ids(self._src_lang		)
								UpperCamelCase   =	tgt_lang
								self.set_src_lang_special_tokens(self._src_lang		)


						@property
						def     snake_case_   (self		) ->   str:
								return self._src_lang


						@src_lang.setter
						def     snake_case_   (self   ,							__a		) ->   None:
								UpperCamelCase   =	new_src_lang
								self.set_src_lang_special_tokens(self._src_lang		)


						def     snake_case_   (self   ,							__a   ,							__a = None		) ->   List[int]:
								if token_ids_a is None:
										return self.prefix_tokens + token_ids_a + self.suffix_tokens
								# We don't expect to process pairs, but leave the pair logic for API consistency
								return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens


						def     snake_case_   (self   ,							__a   ,							__a = None		) ->   List[int]:
								UpperCamelCase   =	[self.sep_token_id]
								UpperCamelCase   =	[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]


						def     snake_case_   (self   ,							__a   ,							__a   ,							__a   ,							__a   ,							**__a		) ->   Optional[Any]:
								if src_lang is None or tgt_lang is None:
										raise ValueError("Translation requires a `src_lang` and a `tgt_lang` for this model"		)
								UpperCamelCase   =	src_lang
								UpperCamelCase   =	self(__a   ,							add_special_tokens=__a   ,							return_tensors=__a   ,							**__a		)
								UpperCamelCase   =	self.convert_tokens_to_ids(__a		)
								UpperCamelCase   =	tgt_lang_id
								return inputs


						def     snake_case_   (self   ,							__a   ,							__a = "en_XX"   ,							__a = None   ,							__a = "ro_RO"   ,							**__a   ,							) ->   BatchEncoding:
								UpperCamelCase   =	src_lang
								UpperCamelCase   =	tgt_lang
								return super().prepare_seqaseq_batch(__a   ,							__a   ,							**__a		)


						def     snake_case_   (self		) ->   Any:
								return self.set_src_lang_special_tokens(self.src_lang		)


						def     snake_case_   (self		) ->   Optional[Any]:
								return self.set_tgt_lang_special_tokens(self.tgt_lang		)


						def     snake_case_   (self   ,							__a		) ->   None:
								UpperCamelCase   =	self.convert_tokens_to_ids(__a		)
								UpperCamelCase   =	[]
								UpperCamelCase   =	[self.eos_token_id, self.cur_lang_code]

								UpperCamelCase   =	self.convert_ids_to_tokens(self.prefix_tokens		)
								UpperCamelCase   =	self.convert_ids_to_tokens(self.suffix_tokens		)

								UpperCamelCase   =	processors.TemplateProcessing(
								    single=prefix_tokens_str + ["$A"] + suffix_tokens_str   ,							pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str   ,							special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str   ,							self.prefix_tokens + self.suffix_tokens		)		)   ,							)


						def     snake_case_   (self   ,							__a		) ->   None:
								UpperCamelCase   =	self.convert_tokens_to_ids(__a		)
								UpperCamelCase   =	[]
								UpperCamelCase   =	[self.eos_token_id, self.cur_lang_code]

								UpperCamelCase   =	self.convert_ids_to_tokens(self.prefix_tokens		)
								UpperCamelCase   =	self.convert_ids_to_tokens(self.suffix_tokens		)

								UpperCamelCase   =	processors.TemplateProcessing(
								    single=prefix_tokens_str + ["$A"] + suffix_tokens_str   ,							pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str   ,							special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str   ,							self.prefix_tokens + self.suffix_tokens		)		)   ,							)




						def     snake_case_   (self   ,							__a   ,							__a = None		) ->   Tuple[str]:
								if not self.can_save_slow_tokenizer:
										raise ValueError(
										    "Your fast tokenizer does not have the necessary information to save the vocabulary for a slow "
										    "tokenizer."		)

								if not os.path.isdir(__a		):
										logger.error(F"Vocabulary path ({save_directory}) should be a directory."		)
										return
								UpperCamelCase   =	os.path.join(
								    __a   ,							(filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]		)

								if os.path.abspath(self.vocab_file		) != os.path.abspath(__a		):
										copyfile(self.vocab_file   ,							__a		)

								return (out_vocab_file,)













"""simple docstring"""





def       a__					(					_SCREAMING_SNAKE_CASE    ):




		"""simple docstring"""


		UpperCamelCase   =	0
		for ch in input_str:
				UpperCamelCase   =	ord(_SCREAMING_SNAKE_CASE    )
				UpperCamelCase   =	pow(2  ,	_SCREAMING_SNAKE_CASE    )

				# If we already turned on bit for current character's unicode
				if bitmap >> ch_unicode & 1 == 1:
						return False
				bitmap |= ch_bit_index_on
		return True


if __name__ == "__main__":
						import doctest

						doctest.testmod()






