


'''simple docstring'''



from __future__ import annotations

from collections.abc import Callable
from typing import Generic, TypeVar

__UpperCAmelCase      :Any			    =       TypeVar("T")
__UpperCAmelCase      :str			    =       TypeVar("U")



class      a    (		Generic[T, U]	):


     """simple docstring"""






     def __init__(    self					:		Optional[int]							,			snake_case					:		T | None							,			snake_case					:		U | None      )						->							Tuple:
          __UpperCAmelCase     :			str  							=      key
          __UpperCAmelCase     :			Optional[Any]  							=      val
          __UpperCAmelCase     :			DoubleLinkedListNode[T, U] | None  							=      None
          __UpperCAmelCase     :			DoubleLinkedListNode[T, U] | None  							=      None






     def __repr__(    self					:		int      )						->							str:
          return (
              f'Node: key: {self.key}, val: {self.val}, '
              f'has next: {bool(self.next      )}, has prev: {bool(self.prev      )}'
          )



class      a    (		Generic[T, U]	):


     """simple docstring"""






     def __init__(    self					:		Optional[int]      )						->							None:
          __UpperCAmelCase     :			DoubleLinkedListNode[T, U]  							=      DoubleLinkedListNode(snake_case							,			snake_case      )
          __UpperCAmelCase     :			DoubleLinkedListNode[T, U]  							=      DoubleLinkedListNode(snake_case							,			snake_case      )
          __UpperCAmelCase							,       __UpperCAmelCase     :			Optional[Any]  							=      self.rear, self.head

     def __repr__(    self					:		Tuple      )						->							str:
          __UpperCAmelCase     :			Optional[int]  							=      ['''DoubleLinkedList''']
          __UpperCAmelCase     :			List[str]  							=      self.head
          while node.next is not None:
               rep.append(str(snake_case      )      )
               __UpperCAmelCase     :			Optional[int]  							=      node.next
          rep.append(str(self.rear      )      )
          return ",\n    ".join(snake_case      )

     def 			lowerCamelCase__			(    self					:		Any							,			snake_case					:		DoubleLinkedListNode[T, U]      )						->							None:
          __UpperCAmelCase     :			List[Any]  							=      self.rear.prev

          # All nodes other than self.head are guaranteed to have non-None previous
          assert previous is not None

          __UpperCAmelCase     :			Tuple  							=      node
          __UpperCAmelCase     :			List[str]  							=      previous
          __UpperCAmelCase     :			Union[str, Any]  							=      node
          __UpperCAmelCase     :			List[str]  							=      self.rear






     def 			lowerCamelCase__			(    self					:		Tuple							,			snake_case					:		DoubleLinkedListNode[T, U]      )						->							DoubleLinkedListNode[T, U] | None:

          if node.prev is None or node.next is None:
               return None

          __UpperCAmelCase     :			List[Any]  							=      node.next
          __UpperCAmelCase     :			Optional[Any]  							=      node.prev
          __UpperCAmelCase     :			List[Any]  							=      None
          __UpperCAmelCase     :			Any  							=      None
          return node



class      a    (		Generic[T, U]	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			dict[Callable[[T], U], LRUCache[T, U]]							       =       {}

     def __init__(    self					:		List[str]							,			snake_case					:		int      )						->							List[str]:
          __UpperCAmelCase     :			DoubleLinkedList[T, U]  							=      DoubleLinkedList()
          __UpperCAmelCase     :			int  							=      capacity
          __UpperCAmelCase     :			int  							=      0
          __UpperCAmelCase     :			Any  							=      0
          __UpperCAmelCase     :			Optional[int]  							=      0
          __UpperCAmelCase     :			dict[T, DoubleLinkedListNode[T, U]]  							=      {}

     def __repr__(    self					:		List[str]      )						->							str:
          return (
              f'CacheInfo(hits={self.hits}, misses={self.miss}, '
              f'capacity={self.capacity}, current size={self.num_keys})'
          )

     def __contains__(    self					:		Union[str, Any]							,			snake_case					:		T      )						->							bool:
          return key in self.cache

     def 			lowerCamelCase__			(    self					:		Optional[int]							,			snake_case					:		T      )						->							U | None:
          # Note: pythonic interface would throw KeyError rather than return None

          if key in self.cache:
               self.hits += 1
               __UpperCAmelCase     :			DoubleLinkedListNode[T, U]  							=      self.cache[key]
               __UpperCAmelCase     :			List[str]  							=      self.list.remove(self.cache[key]      )
               assert node == value_node

               # node is guaranteed not None because it is in self.cache
               assert node is not None
               self.list.add(snake_case      )
               return node.val
          self.miss += 1
          return None

     def 			lowerCamelCase__			(    self					:		Optional[int]							,			snake_case					:		T							,			snake_case					:		U      )						->							None:

          if key not in self.cache:
               if self.num_keys >= self.capacity:
                    # delete first node (oldest) when over capacity
                    __UpperCAmelCase     :			List[str]  							=      self.list.head.next

                    # guaranteed to have a non-None first node when num_keys > 0
                    # explain to type checker via assertions
                    assert first_node is not None
                    assert first_node.key is not None
                    assert (
                        self.list.remove(snake_case      ) is not None
                    )  # node guaranteed to be in list assert node.key is not None

                    del self.cache[first_node.key]
                    self.num_keys -= 1
               __UpperCAmelCase     :			Optional[Any]  							=      DoubleLinkedListNode(snake_case							,			snake_case      )
               self.list.add(self.cache[key]      )
               self.num_keys += 1

          else:
               # bump node to the end of the list, update value
               __UpperCAmelCase     :			Any  							=      self.list.remove(self.cache[key]      )
               assert node is not None  # node guaranteed to be in list
               __UpperCAmelCase     :			Dict  							=      value
               self.list.add(snake_case      )






     @classmethod
     def 			lowerCamelCase__			(    cls					:		Dict							,			snake_case					:		int = 128      )						->							Callable[[Callable[[T], U]], Callable[..., U]]:

          def cache_decorator_inner(snake_case					:		Callable[[T], U]      ) -> Callable[..., U]:
               def cache_decorator_wrapper(*snake_case					:		T      ) -> U:
                    if func not in cls.decorator_function_to_instance_map:
                         __UpperCAmelCase     :			Optional[int]  							=      LRUCache(snake_case      )

                    __UpperCAmelCase     :			str  							=      cls.decorator_function_to_instance_map[func].get(args[0]      )
                    if result is None:
                         __UpperCAmelCase     :			int  							=      func(*snake_case      )
                         cls.decorator_function_to_instance_map[func].put(args[0]							,			snake_case      )
                    return result

               def cache_info() -> LRUCache[T, U]:
                    return cls.decorator_function_to_instance_map[func]

               setattr(snake_case							,			'''cache_info'''							,			snake_case      )  # noqa: B010

               return cache_decorator_wrapper

          return cache_decorator_inner


if __name__ == "__main__":
      import doctest

      doctest.testmod()



'''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_bert import BertTokenizer


__UpperCAmelCase      :Dict			    =       logging.get_logger(__name__)

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

__UpperCAmelCase      :Optional[int]			    =       {
    "vocab_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/vocab.txt",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/vocab.txt",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/vocab.txt",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/vocab.txt",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/vocab.txt"
        ),
        "bert-base-multilingual-cased": "https://huggingface.co/bert-base-multilingual-cased/resolve/main/vocab.txt",
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/vocab.txt",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/vocab.txt",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/vocab.txt"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/vocab.txt"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/vocab.txt"
        ),
        "bert-base-german-dbmdz-cased": "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/vocab.txt",
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/vocab.txt"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/vocab.txt"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/vocab.txt"
        ),
    },
    "tokenizer_file": {
        "bert-base-uncased": "https://huggingface.co/bert-base-uncased/resolve/main/tokenizer.json",
        "bert-large-uncased": "https://huggingface.co/bert-large-uncased/resolve/main/tokenizer.json",
        "bert-base-cased": "https://huggingface.co/bert-base-cased/resolve/main/tokenizer.json",
        "bert-large-cased": "https://huggingface.co/bert-large-cased/resolve/main/tokenizer.json",
        "bert-base-multilingual-uncased": (
            "https://huggingface.co/bert-base-multilingual-uncased/resolve/main/tokenizer.json"
        ),
        "bert-base-multilingual-cased": (
            "https://huggingface.co/bert-base-multilingual-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-chinese": "https://huggingface.co/bert-base-chinese/resolve/main/tokenizer.json",
        "bert-base-german-cased": "https://huggingface.co/bert-base-german-cased/resolve/main/tokenizer.json",
        "bert-large-uncased-whole-word-masking": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking": (
            "https://huggingface.co/bert-large-cased-whole-word-masking/resolve/main/tokenizer.json"
        ),
        "bert-large-uncased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-uncased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-large-cased-whole-word-masking-finetuned-squad": (
            "https://huggingface.co/bert-large-cased-whole-word-masking-finetuned-squad/resolve/main/tokenizer.json"
        ),
        "bert-base-cased-finetuned-mrpc": (
            "https://huggingface.co/bert-base-cased-finetuned-mrpc/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-cased": (
            "https://huggingface.co/bert-base-german-dbmdz-cased/resolve/main/tokenizer.json"
        ),
        "bert-base-german-dbmdz-uncased": (
            "https://huggingface.co/bert-base-german-dbmdz-uncased/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-cased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-cased-v1/resolve/main/tokenizer.json"
        ),
        "TurkuNLP/bert-base-finnish-uncased-v1": (
            "https://huggingface.co/TurkuNLP/bert-base-finnish-uncased-v1/resolve/main/tokenizer.json"
        ),
        "wietsedv/bert-base-dutch-cased": (
            "https://huggingface.co/wietsedv/bert-base-dutch-cased/resolve/main/tokenizer.json"
        ),
    },
}

__UpperCAmelCase      :Union[str, Any]			    =       {
    "bert-base-uncased": 5_1_2,
    "bert-large-uncased": 5_1_2,
    "bert-base-cased": 5_1_2,
    "bert-large-cased": 5_1_2,
    "bert-base-multilingual-uncased": 5_1_2,
    "bert-base-multilingual-cased": 5_1_2,
    "bert-base-chinese": 5_1_2,
    "bert-base-german-cased": 5_1_2,
    "bert-large-uncased-whole-word-masking": 5_1_2,
    "bert-large-cased-whole-word-masking": 5_1_2,
    "bert-large-uncased-whole-word-masking-finetuned-squad": 5_1_2,
    "bert-large-cased-whole-word-masking-finetuned-squad": 5_1_2,
    "bert-base-cased-finetuned-mrpc": 5_1_2,
    "bert-base-german-dbmdz-cased": 5_1_2,
    "bert-base-german-dbmdz-uncased": 5_1_2,
    "TurkuNLP/bert-base-finnish-cased-v1": 5_1_2,
    "TurkuNLP/bert-base-finnish-uncased-v1": 5_1_2,
    "wietsedv/bert-base-dutch-cased": 5_1_2,
}

__UpperCAmelCase      :str			    =       {
    "bert-base-uncased": {"do_lower_case": True},
    "bert-large-uncased": {"do_lower_case": True},
    "bert-base-cased": {"do_lower_case": False},
    "bert-large-cased": {"do_lower_case": False},
    "bert-base-multilingual-uncased": {"do_lower_case": True},
    "bert-base-multilingual-cased": {"do_lower_case": False},
    "bert-base-chinese": {"do_lower_case": False},
    "bert-base-german-cased": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking": {"do_lower_case": False},
    "bert-large-uncased-whole-word-masking-finetuned-squad": {"do_lower_case": True},
    "bert-large-cased-whole-word-masking-finetuned-squad": {"do_lower_case": False},
    "bert-base-cased-finetuned-mrpc": {"do_lower_case": False},
    "bert-base-german-dbmdz-cased": {"do_lower_case": False},
    "bert-base-german-dbmdz-uncased": {"do_lower_case": True},
    "TurkuNLP/bert-base-finnish-cased-v1": {"do_lower_case": False},
    "TurkuNLP/bert-base-finnish-uncased-v1": {"do_lower_case": True},
    "wietsedv/bert-base-dutch-cased": {"do_lower_case": False},
}



class      a    (		_a	):


     """simple docstring"""






     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       VOCAB_FILES_NAMES
     SCREAMING_SNAKE_CASE	:			List[Any]							       =       PRETRAINED_VOCAB_FILES_MAP
     SCREAMING_SNAKE_CASE	:			Tuple							       =       PRETRAINED_INIT_CONFIGURATION
     SCREAMING_SNAKE_CASE	:			Optional[int]							       =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     SCREAMING_SNAKE_CASE	:			Optional[Any]							       =       BertTokenizer

     def __init__(    self					:		Optional[int]							,			snake_case					:		Union[str, Any]=None							,			snake_case					:		str=None							,			snake_case					:		Any=True							,			snake_case					:		Tuple="[UNK]"							,			snake_case					:		int="[SEP]"							,			snake_case					:		Optional[Any]="[PAD]"							,			snake_case					:		int="[CLS]"							,			snake_case					:		Optional[Any]="[MASK]"							,			snake_case					:		Union[str, Any]=True							,			snake_case					:		List[Any]=None							,			**snake_case					:		int							,			)						->							str:
          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							,			)

          __UpperCAmelCase     :			List[str]  							=      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
          ):
               __UpperCAmelCase     :			List[Any]  							=      getattr(snake_case							,			normalizer_state.pop('''type'''      )      )
               __UpperCAmelCase     :			List[Any]  							=      do_lower_case
               __UpperCAmelCase     :			List[Any]  							=      strip_accents
               __UpperCAmelCase     :			str  							=      tokenize_chinese_chars
               __UpperCAmelCase     :			List[str]  							=      normalizer_class(**snake_case      )

          __UpperCAmelCase     :			Optional[int]  							=      do_lower_case

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