






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:
				__A      =				None


__A      =				logging.get_logger(__name__)


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

__A      =				{
    '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',
    },
}

__A      =				{
    'facebook/mbart-large-en-ro': 1024,
    'facebook/mbart-large-cc25': 1024,
}

# fmt: off
__A      =				['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 						SCREAMING_SNAKE_CASE				( snake_case					):





							"""simple docstring"""

							A_						  =					VOCAB_FILES_NAMES
							A_						  =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							A_						  =					PRETRAINED_VOCAB_FILES_MAP
							A_						  =					["input_ids", "attention_mask"]
							A_						  =					MBartTokenizer

							A_						  =					[]
							A_						  =					[]

							def __init__(  self:   str		,     __A:   Optional[int]=None		,     __A:   List[str]=None		,     __A:   Optional[int]="<s>"		,     __A:   Tuple="</s>"		,     __A:   List[str]="</s>"		,     __A:   Tuple="<s>"		,     __A:   Dict="<unk>"		,     __A:   Optional[Any]="<pad>"		,     __A:   str="<mask>"		,     __A:   List[Any]=None		,     __A:   Any=None		,     __A:   Union[str, Any]=None		,     **__A:   int		,     )    ->				str:
												# Mask token behave like a normal word, i.e. include the space before it
												_A								= 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		,     )

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

												_A								= 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}   )
												_A								= {
												    lang_code: self.convert_tokens_to_ids(__A   ) for lang_code in FAIRSEQ_LANGUAGE_CODES
												}

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

							@property
							def       __A (  self:   Union[str, Any]   )    ->				str:
												return self._src_lang

							@src_lang.setter
							def       __A (  self:   List[Any]		,     __A:   str   )    ->				None:
												_A								= new_src_lang
												self.set_src_lang_special_tokens(self._src_lang   )

							def       __A (  self:   Union[str, Any]		,     __A:   List[int]		,     __A:   Optional[List[int]] = 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       __A (  self:   str		,     __A:   List[int]		,     __A:   Optional[List[int]] = None   )    ->				List[int]:
												_A								= [self.sep_token_id]
												_A								= [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       __A (  self:   List[Any]		,     __A:   List[Any]		,     __A:   str		,     __A:   Optional[str]		,     __A:   Optional[str]		,     **__A:   Any   )    ->				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'''   )
												_A								= src_lang
												_A								= self(__A		,     add_special_tokens=__A		,     return_tensors=__A		,     **__A   )
												_A								= self.convert_tokens_to_ids(__A   )
												_A								= tgt_lang_id
												return inputs

							def       __A (  self:   List[str]		,     __A:   List[str]		,     __A:   str = "en_XX"		,     __A:   Optional[List[str]] = None		,     __A:   str = "ro_RO"		,     **__A:   int		,     )    ->				BatchEncoding:
												_A								= src_lang
												_A								= tgt_lang
												return super().prepare_seqaseq_batch(__A		,     __A		,     **__A   )

							def       __A (  self:   List[Any]   )    ->				Any:
												return self.set_src_lang_special_tokens(self.src_lang   )

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

							def       __A (  self:   Tuple		,     __A:   List[Any]   )    ->				None:
												_A								= self.convert_tokens_to_ids(__A   )
												_A								= []
												_A								= [self.eos_token_id, self.cur_lang_code]

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

												_A								= 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       __A (  self:   Optional[int]		,     __A:   str   )    ->				None:
												_A								= self.convert_tokens_to_ids(__A   )
												_A								= []
												_A								= [self.eos_token_id, self.cur_lang_code]

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

												_A								= 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       __A (  self:   List[str]		,     __A:   str		,     __A:   Optional[str] = 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
												_A								= 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,)











from __future__ import annotations




def      __A					(     _lowercase					,			_lowercase					,			_lowercase					,			_lowercase ):  # noqa: E741

					'''simple docstring'''







					while r - l > 1:
										_A								= (l + r) // 2
										if v[m] >= key:
															_A								= m
										else:
															_A								= m  # noqa: E741
					return r




def      __A					(     _lowercase ):

					'''simple docstring'''







					if len(_lowercase ) == 0:
										return 0

					_A								= [0] * len(_lowercase )
					_A								= 1

					_A								= v[0]

					for i in range(1					,			len(_lowercase ) ):
										if v[i] < tail[0]:
															_A								= v[i]
										elif v[i] > tail[length - 1]:
															_A								= v[i]
															length += 1
										else:
															_A								= v[i]

					return length


if __name__ == "__main__":
				import doctest

				doctest.testmod()



