





import json
from typing import List, Optional, Tuple

from tokenizers import normalizers

from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_layoutlm import LayoutLMTokenizer


__lowercase													=			logging.get_logger(__name__)

__lowercase													=			{"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

__lowercase													=			{
    """vocab_file""": {
        """microsoft/layoutlm-base-uncased""": (
            """https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/vocab.txt"""
        ),
        """microsoft/layoutlm-large-uncased""": (
            """https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/vocab.txt"""
        ),
    },
    """tokenizer_file""": {
        """microsoft/layoutlm-base-uncased""": (
            """https://huggingface.co/microsoft/layoutlm-base-uncased/resolve/main/tokenizer.json"""
        ),
        """microsoft/layoutlm-large-uncased""": (
            """https://huggingface.co/microsoft/layoutlm-large-uncased/resolve/main/tokenizer.json"""
        ),
    },
}

__lowercase													=			{
    """microsoft/layoutlm-base-uncased""": 512,
    """microsoft/layoutlm-large-uncased""": 512,
}

__lowercase													=			{
    """microsoft/layoutlm-base-uncased""": {"""do_lower_case""": True},
    """microsoft/layoutlm-large-uncased""": {"""do_lower_case""": True},
}

class   __snake_case				(			_a   ):






    '''simple docstring'''
    _lowerCAmelCase     =	VOCAB_FILES_NAMES
    _lowerCAmelCase     =	PRETRAINED_VOCAB_FILES_MAP
    _lowerCAmelCase     =	PRETRAINED_INIT_CONFIGURATION
    _lowerCAmelCase     =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    _lowerCAmelCase     =	LayoutLMTokenizer





    def __init__(   self						:		Union[str, Any]			,						snake_case						:		Optional[Any]=None			,						snake_case						:		Tuple=None			,						snake_case						:		List[Any]=True			,						snake_case						:		Tuple="[UNK]"			,						snake_case						:		List[str]="[SEP]"			,						snake_case						:		Optional[Any]="[PAD]"			,						snake_case						:		Dict="[CLS]"			,						snake_case						:		List[Any]="[MASK]"			,						snake_case						:		int=True			,						snake_case						:		Any=None			,						**snake_case						:		str			,						):

      """simple docstring"""





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

      __lowerCAmelCase			=				json.loads(self.backend_tokenizer.normalizer.__getstate__()							)
      if (
          normalizer_state.get('''lowercase'''			,						snake_case							) != do_lower_case
          or normalizer_state.get('''strip_accents'''			,						snake_case							) != strip_accents
          or normalizer_state.get('''handle_chinese_chars'''			,						snake_case							) != tokenize_chinese_chars
      ):
        __lowerCAmelCase			=				getattr(snake_case			,						normalizer_state.pop('''type'''							)							)
        __lowerCAmelCase			=				do_lower_case
        __lowerCAmelCase			=				strip_accents
        __lowerCAmelCase			=				tokenize_chinese_chars
        __lowerCAmelCase			=				normalizer_class(**snake_case							)

      __lowerCAmelCase			=				do_lower_case





    def 	A		(   self						:		Any			,						snake_case						:		List[str]			,						snake_case						:		Optional[Any]=None							):

      """simple docstring"""





      __lowerCAmelCase			=				[self.cls_token_id] + token_ids_a + [self.sep_token_id]

      if token_ids_a:
        output += token_ids_a + [self.sep_token_id]

      return output





    def 	A		(   self						:		List[Any]			,						snake_case						:		List[int]			,						snake_case						:		Optional[List[int]] = None							):

      """simple docstring"""





      __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							) * [0] + len(token_ids_a + sep							) * [1]





    def 	A		(   self						:		Dict			,						snake_case						:		str			,						snake_case						:		Optional[str] = None							):

      """simple docstring"""





      __lowerCAmelCase			=				self._tokenizer.model.save(snake_case			,						name=snake_case							)
      return tuple(snake_case							)







class   __snake_case				:






    '''simple docstring'''





    def __init__(   self						:		Any							):

      """simple docstring"""





      __lowerCAmelCase			=				{}
      # indexmap keys are an index and it's values are the number at that index
      __lowerCAmelCase			=				{}





    def 	A		(   self						:		List[Any]			,						snake_case						:		list | str | range			,						snake_case						:		int							):

      """simple docstring"""





      if isinstance(snake_case			,						(range, str)							):
        __lowerCAmelCase			=				list(snake_case							)
      elif not isinstance(snake_case			,						snake_case							):
        raise TypeError(
            '''binary_search_delete() only accepts either a list, range or str'''							)

      __lowerCAmelCase			=				0
      __lowerCAmelCase			=				len(snake_case							) - 1

      while low <= high:
        __lowerCAmelCase			=				(low + high) // 2
        if array[mid] == item:
          array.pop(snake_case							)
          return array
        elif array[mid] < item:
          __lowerCAmelCase			=				mid + 1
        else:
          __lowerCAmelCase			=				mid - 1
      raise ValueError(
          '''Either the item is not in the array or the array was unsorted'''							)





    def 	A		(   self						:		Tuple			,						snake_case						:		list | str | range			,						snake_case						:		int							):

      """simple docstring"""





      if isinstance(snake_case			,						(range, str)							):
        __lowerCAmelCase			=				list(snake_case							)
      elif not isinstance(snake_case			,						snake_case							):
        raise TypeError(
            '''binary_search_insert() only accepts either a list, range or str'''							)

      __lowerCAmelCase			=				0
      __lowerCAmelCase			=				len(snake_case							) - 1

      while low <= high:
        __lowerCAmelCase			=				(low + high) // 2
        if array[mid] == index:
          # If the item already exists in the array,
          # insert it after the existing item
          array.insert(mid + 1			,						snake_case							)
          return array
        elif array[mid] < index:
          __lowerCAmelCase			=				mid + 1
        else:
          __lowerCAmelCase			=				mid - 1

        # If the item doesn't exist in the array, insert it at the appropriate position
      array.insert(snake_case			,						snake_case							)
      return array





    def 	A		(   self						:		Tuple			,						snake_case						:		int			,						snake_case						:		int							):

      """simple docstring"""





      if index in self.indexmap:
        __lowerCAmelCase			=				self.indexmap[index]
        if len(self.numbermap[n]							) == 1:
          del self.numbermap[n]
        else:
          __lowerCAmelCase			=				self.binary_search_delete(self.numbermap[n]			,						snake_case							)

        # Set new index
      __lowerCAmelCase			=				number

      # Number not seen before or empty so insert number value
      if number not in self.numbermap:
        __lowerCAmelCase			=				[index]

      # Here we need to perform a binary search insertion in order to insert
      # The item in the correct place
      else:
        __lowerCAmelCase			=				self.binary_search_insert(
            self.numbermap[number]			,						snake_case							)





    def 	A		(   self						:		List[str]			,						snake_case						:		int							):

      """simple docstring"""





      return self.numbermap.get(snake_case			,						[-1]							)[0]


if __name__ == "__main__":
      import doctest

      doctest.testmod()
