

"""simple docstring"""






import os
import unittest

from transformers.models.phobert.tokenization_phobert import VOCAB_FILES_NAMES, PhobertTokenizer

from ...test_tokenization_common import TokenizerTesterMixin







class 	__UpperCamelCase    (    a__							,							unittest.TestCase						):
		_UpperCAmelCase          =		PhobertTokenizer
		_UpperCAmelCase          =		False

		def __lowerCamelCase		(		self      ):
						'''simple docstring'''

						super().setUp()

						# Adapted from Sennrich et al. 2015 and https://github.com/rsennrich/subword-nmt
						_lowerCAmelCase       :   Optional[int]  =    ["T@@", "i", "I", "R@@", "r", "e@@"]
						_lowerCAmelCase       :   str  =    dict(zip(lowerCAmelCase__    ,range(len(lowerCAmelCase__      )      )      )      )
						_lowerCAmelCase       :   Any  =    ["#version: 0.2", "l à</w>"]
						_lowerCAmelCase       :   Dict  =    {"unk_token": "<unk>"}

						_lowerCAmelCase       :   Dict  =    os.path.join(self.tmpdirname    ,VOCAB_FILES_NAMES['vocab_file']      )
						_lowerCAmelCase       :   Dict  =    os.path.join(self.tmpdirname    ,VOCAB_FILES_NAMES['merges_file']      )

						with open(self.vocab_file    ,'w'    ,encoding='utf-8'      ) as fp:
										for token in vocab_tokens:
														fp.write(F"""{token} {vocab_tokens[token]}\n"""      )
						with open(self.merges_file    ,'w'    ,encoding='utf-8'      ) as fp:
										fp.write('\n'.join(lowerCAmelCase__      )      )

		def __lowerCamelCase		(		self    ,**_A      ):
						'''simple docstring'''

						kwargs.update(self.special_tokens_map      )
						return PhobertTokenizer.from_pretrained(self.tmpdirname    ,**lowerCAmelCase__      )

		def __lowerCamelCase		(		self    ,_A      ):
						'''simple docstring'''

						_lowerCAmelCase       :   Union[str, Any]  =    "Tôi là VinAI Research"
						_lowerCAmelCase       :   int  =    "T<unk> i <unk> <unk> <unk> <unk> <unk> <unk> I Re<unk> e<unk> <unk> <unk> <unk>"
						return input_text, output_text







		def __lowerCamelCase		(		self      ):
						'''simple docstring'''

						_lowerCAmelCase       :   Tuple  =    PhobertTokenizer(self.vocab_file    ,self.merges_file    ,**self.special_tokens_map      )
						_lowerCAmelCase       :   str  =    "Tôi là VinAI Research"
						_lowerCAmelCase       :   str  =    "T@@ ô@@ i l@@ à V@@ i@@ n@@ A@@ I R@@ e@@ s@@ e@@ a@@ r@@ c@@ h".split()
						_lowerCAmelCase       :   str  =    tokenizer.tokenize(lowerCAmelCase__      )
						print(lowerCAmelCase__      )
						self.assertListEqual(lowerCAmelCase__    ,lowerCAmelCase__      )

						_lowerCAmelCase       :   Union[str, Any]  =    tokens + [tokenizer.unk_token]

						_lowerCAmelCase       :   int  =    [4, 3, 5, 3, 3, 3, 3, 3, 3, 6, 7, 9, 3, 9, 3, 3, 3, 3, 3]
						self.assertListEqual(tokenizer.convert_tokens_to_ids(lowerCAmelCase__      )    ,lowerCAmelCase__      )








"""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


_lowerCAmelCase						=		logging.get_logger(__name__)

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

_lowerCAmelCase						=		{
    """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"""
        ),
    },
}

_lowerCAmelCase						=		{
    """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,
}

_lowerCAmelCase						=		{
    """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 	__UpperCamelCase    (    a__						):
  _UpperCAmelCase          =		VOCAB_FILES_NAMES
  _UpperCAmelCase          =		PRETRAINED_VOCAB_FILES_MAP
  _UpperCAmelCase          =		PRETRAINED_INIT_CONFIGURATION
  _UpperCAmelCase          =		PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  _UpperCAmelCase          =		BertTokenizer

  def __init__(		self    ,_A=None    ,_A=None    ,_A=True    ,_A="[UNK]"    ,_A="[SEP]"    ,_A="[PAD]"    ,_A="[CLS]"    ,_A="[MASK]"    ,_A=True    ,_A=None    ,**_A    ,):
      '''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    ,**_A    ,)

      _lowerCAmelCase       :   Tuple  =    json.loads(self.backend_tokenizer.normalizer.__getstate__()      )
      if (
          normalizer_state.get('lowercase'    ,_A      ) != do_lower_case
          or normalizer_state.get('strip_accents'    ,_A      ) != strip_accents
          or normalizer_state.get('handle_chinese_chars'    ,_A      ) != tokenize_chinese_chars
      ):
          _lowerCAmelCase       :   Dict  =    getattr(_A    ,normalizer_state.pop('type'      )      )
          _lowerCAmelCase       :   Dict  =    do_lower_case
          _lowerCAmelCase       :   Optional[int]  =    strip_accents
          _lowerCAmelCase       :   Union[str, Any]  =    tokenize_chinese_chars
          _lowerCAmelCase       :   Dict  =    normalizer_class(**_A      )

      _lowerCAmelCase       :   Union[str, Any]  =    do_lower_case

  def __lowerCamelCase		(		self    ,_A    ,_A=None      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Tuple  =    [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    ,_A    ,_A = None      ):
      '''simple docstring'''

      _lowerCAmelCase       :   Union[str, Any]  =    [self.sep_token_id]
      _lowerCAmelCase       :   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 __lowerCamelCase		(		self    ,_A    ,_A = None      ):
      '''simple docstring'''

      _lowerCAmelCase       :   str  =    self._tokenizer.model.save(_A    ,name=_A      )
      return tuple(_A      )





