





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


UpperCAmelCase_       : Any							=    logging.get_logger(__name__)

UpperCAmelCase_       : List[str]							=    {"""vocab_file""": """vocab.txt""", """tokenizer_file""": """tokenizer.json"""}

UpperCAmelCase_       : int							=    {
    """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"""
        ),
    },
}

UpperCAmelCase_       : int							=    {
    """microsoft/layoutlm-base-uncased""": 5_12,
    """microsoft/layoutlm-large-uncased""": 5_12,
}

UpperCAmelCase_       : Optional[Any]							=    {
    """microsoft/layoutlm-base-uncased""": {"""do_lower_case""": True},
    """microsoft/layoutlm-large-uncased""": {"""do_lower_case""": True},
}





class   lowercase__     (				__A	):
  __UpperCamelCase						  =	VOCAB_FILES_NAMES
  __UpperCamelCase						  =	PRETRAINED_VOCAB_FILES_MAP
  __UpperCamelCase						  =	PRETRAINED_INIT_CONFIGURATION
  __UpperCamelCase						  =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  __UpperCamelCase						  =	LayoutLMTokenizer







  def __init__(						self     ,    _lowercase=None     ,    _lowercase=None     ,    _lowercase=True     ,    _lowercase="[UNK]"     ,    _lowercase="[SEP]"     ,    _lowercase="[PAD]"     ,    _lowercase="[CLS]"     ,    _lowercase="[MASK]"     ,    _lowercase=True     ,    _lowercase=None     ,    **_lowercase     ,    ):
       super().__init__(
           _lowercase     ,    tokenizer_file=_lowercase     ,    do_lower_case=_lowercase     ,    unk_token=_lowercase     ,    sep_token=_lowercase     ,    pad_token=_lowercase     ,    cls_token=_lowercase     ,    mask_token=_lowercase     ,    tokenize_chinese_chars=_lowercase     ,    strip_accents=_lowercase     ,    **_lowercase     ,    )

       lowerCAmelCase_       :							Tuple			 =		json.loads(self.backend_tokenizer.normalizer.__getstate__()    )
       if (
           normalizer_state.get("""lowercase"""     ,    _lowercase    ) != do_lower_case
           or normalizer_state.get("""strip_accents"""     ,    _lowercase    ) != strip_accents
           or normalizer_state.get("""handle_chinese_chars"""     ,    _lowercase    ) != tokenize_chinese_chars
       ):
            lowerCAmelCase_       :							Optional[Any]			 =		getattr(_lowercase     ,    normalizer_state.pop("""type"""    )    )
            lowerCAmelCase_       :							Optional[Any]			 =		do_lower_case
            lowerCAmelCase_       :							Any			 =		strip_accents
            lowerCAmelCase_       :							Optional[int]			 =		tokenize_chinese_chars
            lowerCAmelCase_       :							Optional[int]			 =		normalizer_class(**_lowercase    )

       lowerCAmelCase_       :							List[Any]			 =		do_lower_case







  def 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase=None    ):
       lowerCAmelCase_       :							List[Any]			 =		[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 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase = None    ):
       lowerCAmelCase_       :							List[str]			 =		[self.sep_token_id]
       lowerCAmelCase_       :							List[str]			 =		[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 						UpperCAmelCase__		(						self     ,    _lowercase     ,    _lowercase = None    ):
       lowerCAmelCase_       :							Optional[int]			 =		self._tokenizer.model.save(_lowercase     ,    name=_lowercase    )
       return tuple(_lowercase    )








"""simple docstring"""





class   _lowercase			:


      def __init__(     self					:						Optional[Any]				, a					:						Union[str, Any]    ):





            """simple docstring"""







            __snake_case   :     Union[str, Any]	      =data
            __snake_case   :     Optional[Any]	      =None
            __snake_case   :     Any	      =None







      def __str__(     self					:						Any    ):





            """simple docstring"""







            return f'''{self.data}'''



class   _lowercase			:


      def __init__(     self					:						Optional[int]    ):





            """simple docstring"""







            __snake_case   :     Any	      =None
            __snake_case   :     int	      =None


      def __iter__(     self					:						int    ):





            """simple docstring"""







            __snake_case   :     List[str]	      =self.head
            while node:
                  yield node.data
                  __snake_case   :     str	      =node.next


      def __str__(     self					:						Optional[int]    ):





            """simple docstring"""







            return "->".join([str(a    ) for item in self]    )


      def __len__(     self					:						str    ):





            """simple docstring"""







            return sum(1 for _ in self    )


      def _UpperCamelCase    (     self					:						int				, a					:						List[Any]    ):





            """simple docstring"""







            self.insert_at_nth(0				, a    )


      def _UpperCamelCase    (     self					:						str				, a					:						Optional[int]    ):





            """simple docstring"""







            self.insert_at_nth(len(self    )				, a    )


      def _UpperCamelCase    (     self					:						Optional[Any]				, a					:						int				, a					:						Tuple    ):





            """simple docstring"""







            __snake_case   :     List[str]	      =len(self    )

            if not 0 <= index <= length:
                  raise IndexError('''list index out of range'''    )
            __snake_case   :     List[Any]	      =Node(a    )
            if self.head is None:
                  __snake_case   :     Dict	      =new_node
            elif index == 0:
                  __snake_case   :     Union[str, Any]	      =new_node
                  __snake_case   :     Any	      =self.head
                  __snake_case   :     List[Any]	      =new_node
            elif index == length:
                  __snake_case   :     int	      =new_node
                  __snake_case   :     Optional[Any]	      =self.tail
                  __snake_case   :     Optional[Any]	      =new_node
            else:
                  __snake_case   :     Any	      =self.head
                  for _ in range(0				, a    ):
                        __snake_case   :     Optional[Any]	      =temp.next
                  __snake_case   :     Optional[Any]	      =new_node
                  __snake_case   :     Union[str, Any]	      =temp.previous
                  __snake_case   :     List[Any]	      =temp
                  __snake_case   :     str	      =new_node


      def _UpperCamelCase    (     self					:						List[str]    ):





            """simple docstring"""







            return self.delete_at_nth(0    )


      def _UpperCamelCase    (     self					:						List[Any]    ):





            """simple docstring"""







            return self.delete_at_nth(len(self    ) - 1    )


      def _UpperCamelCase    (     self					:						Optional[int]				, a					:						int    ):





            """simple docstring"""







            __snake_case   :     Tuple	      =len(self    )

            if not 0 <= index <= length - 1:
                  raise IndexError('''list index out of range'''    )
            __snake_case   :     str	      =self.head  # default first node
            if length == 1:
                  __snake_case   :     List[Any]	      =None
            elif index == 0:
                  __snake_case   :     List[Any]	      =self.head.next
                  __snake_case   :     Optional[int]	      =None
            elif index == length - 1:
                  __snake_case   :     str	      =self.tail
                  __snake_case   :     Union[str, Any]	      =self.tail.previous
                  __snake_case   :     Optional[Any]	      =None
            else:
                  __snake_case   :     Optional[int]	      =self.head
                  for _ in range(0				, a    ):
                        __snake_case   :     List[Any]	      =temp.next
                  __snake_case   :     Union[str, Any]	      =temp
                  __snake_case   :     Optional[int]	      =temp.previous
                  __snake_case   :     int	      =temp.next
            return delete_node.data


      def _UpperCamelCase    (     self					:						List[Any]				, a					:						Any    ):





            """simple docstring"""







            __snake_case   :     Optional[int]	      =self.head

            while current.data != data:  # Find the position to delete
                  if current.next:
                        __snake_case   :     Dict	      =current.next
                  else:  # We have reached the end an no value matches
                        raise ValueError('''No data matching given value'''    )

            if current == self.head:
                  self.delete_head()

            elif current == self.tail:
                  self.delete_tail()

            else:  # Before: 1 <--> 2(current) <--> 3
                  __snake_case   :     Tuple	      =current.next  # 1 --> 3
                  __snake_case   :     Optional[Any]	      =current.previous  # 1 <--> 3
            return data







      def _UpperCamelCase    (     self					:						int    ):





            """simple docstring"""







            return len(self    ) == 0



def      __lowercase       (     )       ->       None:
      __snake_case   :     List[str]	      =DoublyLinkedList()
      assert linked_list.is_empty() is True
      assert str(a			) == ""

      try:
            linked_list.delete_head()
            raise AssertionError  # This should not happen.
      except IndexError:
            assert True  # This should happen.

      try:
            linked_list.delete_tail()
            raise AssertionError  # This should not happen.
      except IndexError:
            assert True  # This should happen.

      for i in range(10			):
            assert len(a			) == i
            linked_list.insert_at_nth(a							,		i + 1			)
      assert str(a			) == "->".join(str(a			) for i in range(1							,		11			)			)

      linked_list.insert_at_head(0			)
      linked_list.insert_at_tail(11			)
      assert str(a			) == "->".join(str(a			) for i in range(0							,		12			)			)

      assert linked_list.delete_head() == 0
      assert linked_list.delete_at_nth(9			) == 10
      assert linked_list.delete_tail() == 11
      assert len(a			) == 9
      assert str(a			) == "->".join(str(a			) for i in range(1							,		10			)			)


if __name__ == "__main__":
    from doctest import testmod

    testmod()


