


'''simple docstring'''




import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_splinter import SplinterTokenizer


__lowercase	:   List[str]   		=					logging.get_logger(__name__)

__lowercase	:   Optional[int]   		=					{"""vocab_file""": """vocab.txt"""}

__lowercase	:   int   		=					{
    """vocab_file""": {
        """tau/splinter-base""": """https://huggingface.co/tau/splinter-base/resolve/main/vocab.txt""",
        """tau/splinter-base-qass""": """https://huggingface.co/tau/splinter-base-qass/resolve/main/vocab.txt""",
        """tau/splinter-large""": """https://huggingface.co/tau/splinter-large/resolve/main/vocab.txt""",
        """tau/splinter-large-qass""": """https://huggingface.co/tau/splinter-large-qass/resolve/main/vocab.txt""",
    }
}

__lowercase	:   Tuple   		=					{
    """tau/splinter-base""": 5_12,
    """tau/splinter-base-qass""": 5_12,
    """tau/splinter-large""": 5_12,
    """tau/splinter-large-qass""": 5_12,
}

__lowercase	:   List[str]   		=					{
    """tau/splinter-base""": {"""do_lower_case""": False},
    """tau/splinter-base-qass""": {"""do_lower_case""": False},
    """tau/splinter-large""": {"""do_lower_case""": False},
    """tau/splinter-large-qass""": {"""do_lower_case""": False},
}





class _snake_case (			a__ ):
							"""simple docstring"""





							__a				       =  VOCAB_FILES_NAMES
							__a				       =  PRETRAINED_VOCAB_FILES_MAP
							__a				       =  PRETRAINED_INIT_CONFIGURATION
							__a				       =  PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
							__a				       =  SplinterTokenizer







							def __init__( self      ,					__A=None      ,					__A=None      ,					__A=True      ,					__A="[UNK]"      ,					__A="[SEP]"      ,					__A="[PAD]"      ,					__A="[CLS]"      ,					__A="[MASK]"      ,					__A="[QUESTION]"      ,					__A=True      ,					__A=None      ,					**__A      ,					)  ->Any:



											"""simple docstring"""







											super().__init__(
											    __A      ,					tokenizer_file=__A      ,					do_lower_case=__A      ,					unk_token=__A      ,					sep_token=__A      ,					pad_token=__A      ,					cls_token=__A      ,					mask_token=__A      ,					tokenize_chinese_chars=__A      ,					strip_accents=__A      ,					additional_special_tokens=(question_token,)      ,					**__A      ,					)

											__lowerCamelCase		:   Tuple           =       json.loads(self.backend_tokenizer.normalizer.__getstate__()						)
											if (
											    pre_tok_state.get("lowercase"      ,					__A						) != do_lower_case
											    or pre_tok_state.get("strip_accents"      ,					__A						) != strip_accents
											):
															__lowerCamelCase		:   Any           =       getattr(__A      ,					pre_tok_state.pop("type"						)						)
															__lowerCamelCase		:   Union[str, Any]           =       do_lower_case
															__lowerCamelCase		:   Optional[int]           =       strip_accents
															__lowerCamelCase		:   List[Any]           =       pre_tok_class(**__A						)

											__lowerCamelCase		:   Optional[int]           =       do_lower_case







							@property
							def 		__SCREAMING_SNAKE_CASE( self						)  ->Any:



											"""simple docstring"""







											return self.convert_tokens_to_ids(self.question_token						)







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A = None						)  ->List[int]:



											"""simple docstring"""







											if token_ids_a is None:
															return [self.cls_token_id] + token_ids_a + [self.sep_token_id]

											__lowerCamelCase		:   Union[str, Any]           =       [self.cls_token_id]
											__lowerCamelCase		:   str           =       [self.sep_token_id]
											__lowerCamelCase		:   List[str]           =       [self.question_token_id] + [self.convert_tokens_to_ids("."						)]
											if self.padding_side == "right":
															# Input is question-then-context
															return cls + token_ids_a + question_suffix + sep + token_ids_a + sep
											else:
															# Input is context-then-question
															return cls + token_ids_a + sep + token_ids_a + question_suffix + sep







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A = None						)  ->List[int]:



											"""simple docstring"""







											__lowerCamelCase		:   int           =       [self.sep_token_id]
											__lowerCamelCase		:   Any           =       [self.cls_token_id]
											__lowerCamelCase		:   Tuple           =       [self.question_token_id] + [self.convert_tokens_to_ids("."						)]
											if token_ids_a is None:
															return len(cls + token_ids_a + sep						) * [0]

											if self.padding_side == "right":
															# Input is question-then-context
															return len(cls + token_ids_a + question_suffix + sep						) * [0] + len(token_ids_a + sep						) * [1]
											else:
															# Input is context-then-question
															return len(cls + token_ids_a + sep						) * [0] + len(token_ids_a + question_suffix + sep						) * [1]







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A = None						)  ->Tuple[str]:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       self._tokenizer.model.save(__A      ,					name=__A						)
											return tuple(__A						)









'''simple docstring'''




#
# Sort large text files in a minimum amount of memory
#
import argparse
import os





class _snake_case :
							"""simple docstring"""





							__a				       =  '''block_{0}.dat'''







							def __init__( self      ,					__A						)  ->int:



											"""simple docstring"""







											__lowerCamelCase		:   Dict           =       filename
											__lowerCamelCase		:   Union[str, Any]           =       []







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A						)  ->int:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[int]           =       self.BLOCK_FILENAME_FORMAT.format(__A						)
											with open(__A      ,					"w"						) as file:
															file.write(__A						)
											self.block_filenames.append(__A						)







							def 		__SCREAMING_SNAKE_CASE( self						)  ->int:



											"""simple docstring"""







											return self.block_filenames







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A=None						)  ->Dict:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[int]           =       0
											with open(self.filename						) as file:
															while True:
																			__lowerCamelCase		:   Union[str, Any]           =       file.readlines(__A						)

																			if lines == []:
																							break

																			if sort_key is None:
																							lines.sort()
																			else:
																							lines.sort(key=__A						)

																			self.write_block("".join(__A						)      ,					__A						)
																			i += 1







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



											"""simple docstring"""







											map(os.remove      ,					self.block_filenames						)





class _snake_case :
							"""simple docstring"""





							def 		__SCREAMING_SNAKE_CASE( self      ,					__A						)  ->Optional[int]:



											"""simple docstring"""







											__lowerCamelCase		:   Union[str, Any]           =       -1
											__lowerCamelCase		:   Optional[Any]           =       None

											for i in range(len(__A						)						):
															if min_str is None or choices[i] < min_str:
																			__lowerCamelCase		:   Tuple           =       i

											return min_index





class _snake_case :
							"""simple docstring"""





							def __init__( self      ,					__A						)  ->List[Any]:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       files
											__lowerCamelCase		:   Tuple           =       set()
											__lowerCamelCase		:   Optional[Any]           =       len(__A						)
											__lowerCamelCase		:   List[str]           =       {i: None for i in range(self.num_buffers						)}







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Any:



											"""simple docstring"""







											return {
											    i: self.buffers[i] for i in range(self.num_buffers						) if i not in self.empty
											}







							def 		__SCREAMING_SNAKE_CASE( self						)  ->Dict:



											"""simple docstring"""







											for i in range(self.num_buffers						):
															if self.buffers[i] is None and i not in self.empty:
																			__lowerCamelCase		:   Tuple           =       self.files[i].readline()

																			if self.buffers[i] == "":
																							self.empty.add(__A						)
																							self.files[i].close()

											if len(self.empty						) == self.num_buffers:
															return False

											return True







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A						)  ->Any:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       self.buffers[index]
											__lowerCamelCase		:   List[Any]           =       None

											return value





class _snake_case :
							"""simple docstring"""





							def __init__( self      ,					__A						)  ->List[str]:



											"""simple docstring"""







											__lowerCamelCase		:   List[Any]           =       merge_strategy







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A      ,					__A						)  ->Optional[int]:



											"""simple docstring"""







											__lowerCamelCase		:   List[str]           =       FilesArray(self.get_file_handles(__A      ,					__A						)						)
											with open(__A      ,					"w"      ,					__A						) as outfile:
															while buffers.refresh():
																			__lowerCamelCase		:   Optional[Any]           =       self.merge_strategy.select(buffers.get_dict()						)
																			outfile.write(buffers.unshift(__A						)						)







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A						)  ->str:



											"""simple docstring"""







											__lowerCamelCase		:   Union[str, Any]           =       {}

											for i in range(len(__A						)						):
															__lowerCamelCase		:   Tuple           =       open(filenames[i]      ,					"r"      ,					__A						)  # noqa: UP015

											return files





class _snake_case :
							"""simple docstring"""





							def __init__( self      ,					__A						)  ->str:



											"""simple docstring"""







											__lowerCamelCase		:   Tuple           =       block_size







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A=None						)  ->List[str]:



											"""simple docstring"""







											__lowerCamelCase		:   Optional[int]           =       self.get_number_blocks(__A      ,					self.block_size						)
											__lowerCamelCase		:   Optional[int]           =       FileSplitter(__A						)
											splitter.split(self.block_size      ,					__A						)

											__lowerCamelCase		:   List[str]           =       FileMerger(NWayMerge()						)
											__lowerCamelCase		:   str           =       self.block_size / (num_blocks + 1)
											merger.merge(splitter.get_block_filenames()      ,					filename + ".out"      ,					__A						)

											splitter.cleanup()







							def 		__SCREAMING_SNAKE_CASE( self      ,					__A      ,					__A						)  ->List[str]:



											"""simple docstring"""







											return (os.stat(__A						).st_size / block_size) + 1





def 				a_							(    lowercase     )      ->List[Any]:






				'''simple docstring'''

				if string[-1].lower() == "k":
								return int(string[:-1]     ) * 1024
				elif string[-1].lower() == "m":
								return int(string[:-1]     ) * 1024 * 1024
				elif string[-1].lower() == "g":
								return int(string[:-1]     ) * 1024 * 1024 * 1024
				else:
								return int(lowercase     )





def 				a_							(    )      ->Optional[Any]:






				'''simple docstring'''

				__lowerCamelCase		:   List[str]           =       argparse.ArgumentParser()
				parser.add_argument(
				    "-m"				,    "--mem"				,    help="amount of memory to use for sorting"				,    default="100M"     )
				parser.add_argument(
				    "filename"				,    metavar="<filename>"				,    nargs=1				,    help="name of file to sort"     )
				__lowerCamelCase		:   List[str]           =       parser.parse_args()

				__lowerCamelCase		:   Tuple           =       ExternalSort(parse_memory(args.mem     )     )
				sorter.sort(args.filename[0]     )


if __name__ == "__main__":
				main()





