

"""simple docstring"""


import tempfile
import unittest
from pathlib import Path
from shutil import copyfile

from transformers import MaMaaaTokenizer, is_torch_available
from transformers.testing_utils import (
    get_tests_dir,
    nested_simplify,
    require_sentencepiece,
    require_tokenizers,
    require_torch,
    slow,
)
from transformers.utils import is_sentencepiece_available


if is_sentencepiece_available():
			from transformers.models.mam_aaa.tokenization_mam_aaa import VOCAB_FILES_NAMES, save_json

from ...test_tokenization_common import TokenizerTesterMixin


if is_sentencepiece_available():
			__A						   =			get_tests_dir("fixtures/test_sentencepiece.model")


if is_torch_available():
			from transformers.models.mam_aaa.modeling_mam_aaa import shift_tokens_right

__A						   =			128022
__A						   =			128028





@require_sentencepiece
class     snake_case	(				__snake_case,							unittest.TestCase  ):
				SCREAMING_SNAKE_CASE_   :      Optional[int]         =  MaMaaaTokenizer
				SCREAMING_SNAKE_CASE_   :      Tuple         =  False
				SCREAMING_SNAKE_CASE_   :      str         =  False
				SCREAMING_SNAKE_CASE_   :      List[str]         =  True

				def 							lowercase_     (	self							:				List[str])->   str:



						'''simple docstring'''


						super().setUp()

						__lowerCAmelCase:       List[str]          =			["</s>", "<unk>", "▁This", "▁is", "▁a", "▁t", "est", "\u0120", "<pad>"]
						__lowerCAmelCase:       List[str]          =			dict(zip(UpperCamelCase__     ,  range(len(UpperCamelCase__))))
						__lowerCAmelCase:       Optional[Any]          =			Path(self.tmpdirname)
						save_json(UpperCamelCase__     ,  save_dir / VOCAB_FILES_NAMES["vocab_file"])
						if not (save_dir / VOCAB_FILES_NAMES["spm_file"]).exists():
								copyfile(UpperCamelCase__     ,  save_dir / VOCAB_FILES_NAMES["spm_file"])

						__lowerCAmelCase:       Optional[int]          =			MaMaaaTokenizer.from_pretrained(self.tmpdirname)
						tokenizer.save_pretrained(self.tmpdirname)

				def 							lowercase_     (	self							:				Optional[int]     ,  **UpperCamelCase__							:				Union[str, Any])->   Optional[int]:



						'''simple docstring'''


						return MaMaaaTokenizer.from_pretrained(self.tmpdirname     ,  **UpperCamelCase__)

				def 							lowercase_     (	self							:				Optional[int]     ,  UpperCamelCase__							:				str)->   List[Any]:



						'''simple docstring'''


						return (
						    "This is a test",
						    "This is a test",
						)

				def 							lowercase_     (	self							:				Union[str, Any])->   str:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[int]          =			"</s>"
						__lowerCAmelCase:       Dict          =			0

						self.assertEqual(self.get_tokenizer()._convert_token_to_id(UpperCamelCase__)     ,  UpperCamelCase__)
						self.assertEqual(self.get_tokenizer()._convert_id_to_token(UpperCamelCase__)     ,  UpperCamelCase__)

				def 							lowercase_     (	self							:				str)->   Dict:



						'''simple docstring'''


						__lowerCAmelCase:       List[str]          =			self.get_tokenizer()
						__lowerCAmelCase:       int          =			list(tokenizer.get_vocab().keys())

						self.assertEqual(vocab_keys[0]     ,  "</s>")
						self.assertEqual(vocab_keys[1]     ,  "<unk>")
						self.assertEqual(vocab_keys[-1]     ,  "<s>")
						self.assertEqual(len(UpperCamelCase__)     ,  tokenizer.vocab_size + len(tokenizer.get_added_vocab()))

				@unittest.skip("Skip this test while all models are still to be uploaded.")
				def 							lowercase_     (	self							:				Optional[Any])->   Any:



						'''simple docstring'''


						pass

				def 							lowercase_     (	self							:				Optional[int])->   List[Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			self.get_tokenizer()

						__lowerCAmelCase:       str          =			tokenizer.tokenize("This is a test")
						self.assertListEqual(UpperCamelCase__     ,  ["▁This", "▁is", "▁a", "▁t", "est"])

						self.assertListEqual(
						    tokenizer.convert_tokens_to_ids(UpperCamelCase__)     ,  [2, 3, 4, 5, 6]     ,  )

						__lowerCAmelCase:       Union[str, Any]          =			tokenizer.convert_ids_to_tokens([2, 3, 4, 5, 6])
						self.assertListEqual(UpperCamelCase__     ,  ["▁This", "▁is", "▁a", "▁t", "est"])

						__lowerCAmelCase:       Tuple          =			tokenizer.convert_tokens_to_string(UpperCamelCase__)
						self.assertEqual(UpperCamelCase__     ,  "This is a test")




				@slow
				def 							lowercase_     (	self							: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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]}  # noqa: E501
						# fmt: on

						self.tokenizer_integration_test_util(
						    expected_encoding=UpperCamelCase__     ,  model_name="facebook/m2m100_418M"     ,  revision="c168bae485c864188cf9aa0e4108b0b6934dc91e"     ,  )





@require_torch
@require_sentencepiece
@require_tokenizers
class     snake_case	(				unittest.TestCase  ):
				SCREAMING_SNAKE_CASE_   :      List[str]         =  """facebook/m2m100_418M"""
				SCREAMING_SNAKE_CASE_   :      List[str]         =  [
				    """In my opinion, there are two levels of response from the French government.""",
				    """NSA Affair Emphasizes Complete Lack of Debate on Intelligence""",
				]
				SCREAMING_SNAKE_CASE_   :      Tuple         =  [
				    """Selon moi, il y a deux niveaux de réponse de la part du gouvernement français.""",
				    """L'affaire NSA souligne l'absence totale de débat sur le renseignement""",
				]

				# fmt: off
				SCREAMING_SNAKE_CASE_   :      Any         =  [EN_CODE, 5_93, 19_49, 11_57_81, 4, 7_15_86, 42_34, 6_06_33, 12_62_33, 4_32, 12_38_08, 1_55_92, 11_97, 11_71_32, 12_06_18, 5, 2]

				@classmethod
				def 							lowercase_     (	cls							:				int)->   str:



						'''simple docstring'''


						__lowerCAmelCase:       MaMaaaTokenizer          =			MaMaaaTokenizer.from_pretrained(
						    cls.checkpoint_name     ,  src_lang="en"     ,  tgt_lang="fr")
						__lowerCAmelCase:       Any          =			1
						return cls

				def 							lowercase_     (	self							:				int)->   Optional[int]:



						'''simple docstring'''


						self.assertEqual(self.tokenizer.get_lang_id("ar")     ,  1_2_8_0_0_6)
						self.assertEqual(self.tokenizer.get_lang_id("en")     ,  1_2_8_0_2_2)
						self.assertEqual(self.tokenizer.get_lang_id("ro")     ,  1_2_8_0_7_6)
						self.assertEqual(self.tokenizer.get_lang_id("mr")     ,  1_2_8_0_6_3)

				def 							lowercase_     (	self							:				int)->   int:



						'''simple docstring'''


						__lowerCAmelCase:       str          =			self.tokenizer.get_vocab()
						self.assertEqual(len(UpperCamelCase__)     ,  self.tokenizer.vocab_size)
						self.assertEqual(vocab["<unk>"]     ,  3)
						self.assertIn(self.tokenizer.get_lang_token("en")     ,  UpperCamelCase__)

				def 							lowercase_     (	self							:				Optional[int])->   Dict:



						'''simple docstring'''


						__lowerCAmelCase:       List[Any]          =			"en"
						__lowerCAmelCase:       Union[str, Any]          =			self.tokenizer.batch_encode_plus(self.src_text).input_ids[0]
						self.assertListEqual(self.expected_src_tokens     ,  UpperCamelCase__)

				def 							lowercase_     (	self							:				str)->   Tuple:



						'''simple docstring'''


						self.assertIn(UpperCamelCase__     ,  self.tokenizer.all_special_ids)
						# fmt: off
						__lowerCAmelCase:       Optional[Any]          =			[FR_CODE, 5_3_6_4, 8_2, 8_6_4_2, 4, 2_9_4, 4_7, 8, 1_4_0_2_8, 1_3_6, 3_2_8_6, 9_7_0_6, 6, 9_0_7_9_7, 6, 1_4_4_0_1_2, 1_6_2, 8_8_1_2_8, 3_0_0_6_1, 5, 2]
						# fmt: on
						__lowerCAmelCase:       Optional[Any]          =			self.tokenizer.decode(UpperCamelCase__     ,  skip_special_tokens=UpperCamelCase__)
						__lowerCAmelCase:       List[Any]          =			self.tokenizer.decode(generated_ids[1:]     ,  skip_special_tokens=UpperCamelCase__)
						self.assertEqual(UpperCamelCase__     ,  UpperCamelCase__)
						self.assertNotIn(self.tokenizer.eos_token     ,  UpperCamelCase__)

				def 							lowercase_     (	self							:				Any)->   Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[Any]          =			tempfile.mkdtemp()
						__lowerCAmelCase:       Union[str, Any]          =			self.tokenizer.lang_token_to_id
						self.tokenizer.save_pretrained(UpperCamelCase__)
						__lowerCAmelCase:       Tuple          =			MaMaaaTokenizer.from_pretrained(UpperCamelCase__)
						self.assertDictEqual(new_tok.lang_token_to_id     ,  UpperCamelCase__)

				@require_torch
				def 							lowercase_     (	self							:				List[str])->   str:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			"en"
						__lowerCAmelCase:       str          =			"fr"

						__lowerCAmelCase:       Optional[int]          =			self.tokenizer(self.src_text     ,  text_target=self.tgt_text     ,  padding=UpperCamelCase__     ,  return_tensors="pt")

						__lowerCAmelCase:       Optional[Any]          =			shift_tokens_right(
						    batch["labels"]     ,  self.tokenizer.pad_token_id     ,  self.tokenizer.eos_token_id)

						for k in batch:
								__lowerCAmelCase:       Tuple          =			batch[k].tolist()
						# batch = {k: v.tolist() for k,v in batch.items()}
						# fairseq batch: https://gist.github.com/sshleifer/cba08bc2109361a74ac3760a7e30e4f4
						# batch.decoder_inputs_ids[0][0] ==
						assert batch.input_ids[1][0] == EN_CODE
						assert batch.input_ids[1][-1] == 2
						assert batch.labels[1][0] == FR_CODE
						assert batch.labels[1][-1] == 2
						assert batch.decoder_input_ids[1][:2] == [2, FR_CODE]

				@require_torch
				def 							lowercase_     (	self							:				Dict)->   Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase:       List[Any]          =			"mr"
						self.assertListEqual(self.tokenizer.prefix_tokens     ,  [self.tokenizer.get_lang_id("mr")])
						self.assertListEqual(self.tokenizer.suffix_tokens     ,  [self.tokenizer.eos_token_id])

						__lowerCAmelCase:       List[Any]          =			"zh"
						self.assertListEqual(self.tokenizer.prefix_tokens     ,  [self.tokenizer.get_lang_id("zh")])
						self.assertListEqual(self.tokenizer.suffix_tokens     ,  [self.tokenizer.eos_token_id])

				@require_torch
				def 							lowercase_     (	self							:				Optional[int])->   Any:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			"mr"
						self.tokenizer._switch_to_target_mode()
						self.assertListEqual(self.tokenizer.prefix_tokens     ,  [self.tokenizer.get_lang_id("mr")])
						self.assertListEqual(self.tokenizer.suffix_tokens     ,  [self.tokenizer.eos_token_id])
						self.tokenizer._switch_to_input_mode()
						self.assertListEqual(self.tokenizer.prefix_tokens     ,  [self.tokenizer.get_lang_id(self.tokenizer.src_lang)])

						__lowerCAmelCase:       List[str]          =			"zh"
						self.tokenizer._switch_to_target_mode()
						self.assertListEqual(self.tokenizer.prefix_tokens     ,  [self.tokenizer.get_lang_id("zh")])
						self.assertListEqual(self.tokenizer.suffix_tokens     ,  [self.tokenizer.eos_token_id])
						self.tokenizer._switch_to_input_mode()
						self.assertListEqual(self.tokenizer.prefix_tokens     ,  [self.tokenizer.get_lang_id(self.tokenizer.src_lang)])




				@require_torch
				def 							lowercase_     (	self							:				Union[str, Any])->   Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			self.tokenizer._build_translation_inputs("A test"     ,  return_tensors="pt"     ,  src_lang="en"     ,  tgt_lang="ar")

						self.assertEqual(
						    nested_simplify(UpperCamelCase__)     ,  {
						        # en_XX, A, test, EOS
						        "input_ids": [[1_2_8_0_2_2, 5_8, 4_1_8_3, 2]],
						        "attention_mask": [[1, 1, 1, 1]],
						        # ar_AR
						        "forced_bos_token_id": 1_2_8_0_0_6,
						    }     ,  )





"""simple docstring"""


import json
import os
import unittest

from transformers.models.roc_bert.tokenization_roc_bert import (
    VOCAB_FILES_NAMES,
    RoCBertBasicTokenizer,
    RoCBertTokenizer,
    RoCBertWordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.testing_utils import require_tokenizers, slow

from ...test_tokenization_common import TokenizerTesterMixin, filter_non_english





@require_tokenizers
class     snake_case	(				__snake_case,							unittest.TestCase  ):
				SCREAMING_SNAKE_CASE_   :      List[Any]         =  RoCBertTokenizer
				SCREAMING_SNAKE_CASE_   :      Any         =  None
				SCREAMING_SNAKE_CASE_   :      Any         =  False
				SCREAMING_SNAKE_CASE_   :      Dict         =  True
				SCREAMING_SNAKE_CASE_   :      Optional[int]         =  filter_non_english

				def 							lowercase_     (	self							:				Optional[Any])->   Any:



						'''simple docstring'''


						super().setUp()

						__lowerCAmelCase:       Optional[Any]          =			["[UNK]", "[CLS]", "[SEP]", "[PAD]", "[MASK]", "你", "好", "是", "谁", "a", "b", "c", "d"]
						__lowerCAmelCase:       List[Any]          =			{}
						__lowerCAmelCase:       Dict          =			{}
						for i, value in enumerate(UpperCamelCase__):
								__lowerCAmelCase:       List[Any]          =			i
								__lowerCAmelCase:       Union[str, Any]          =			i
						__lowerCAmelCase:       List[str]          =			os.path.join(self.tmpdirname     ,  VOCAB_FILES_NAMES["vocab_file"])
						__lowerCAmelCase:       int          =			os.path.join(self.tmpdirname     ,  VOCAB_FILES_NAMES["word_shape_file"])
						__lowerCAmelCase:       int          =			os.path.join(self.tmpdirname     ,  VOCAB_FILES_NAMES["word_pronunciation_file"])
						with open(self.vocab_file     ,  "w"     ,  encoding="utf-8") as vocab_writer:
								vocab_writer.write("".join([x + "\n" for x in vocab_tokens]))
						with open(self.word_shape_file     ,  "w"     ,  encoding="utf-8") as word_shape_writer:
								json.dump(UpperCamelCase__     ,  UpperCamelCase__     ,  ensure_ascii=UpperCamelCase__)
						with open(self.word_pronunciation_file     ,  "w"     ,  encoding="utf-8") as word_pronunciation_writer:
								json.dump(UpperCamelCase__     ,  UpperCamelCase__     ,  ensure_ascii=UpperCamelCase__)

				def 							lowercase_     (	self							:				Any)->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			self.tokenizer_class(self.vocab_file     ,  self.word_shape_file     ,  self.word_pronunciation_file)

						__lowerCAmelCase:       Union[str, Any]          =			tokenizer.tokenize("你好[SEP]你是谁")
						self.assertListEqual(UpperCamelCase__     ,  ["你", "好", "[SEP]", "你", "是", "谁"])
						self.assertListEqual(tokenizer.convert_tokens_to_ids(UpperCamelCase__)     ,  [5, 6, 2, 5, 7, 8])
						self.assertListEqual(tokenizer.convert_tokens_to_shape_ids(UpperCamelCase__)     ,  [5, 6, 2, 5, 7, 8])
						self.assertListEqual(tokenizer.convert_tokens_to_pronunciation_ids(UpperCamelCase__)     ,  [5, 6, 2, 5, 7, 8])

				def 							lowercase_     (	self							:				Optional[Any])->   List[str]:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			RoCBertBasicTokenizer()

						self.assertListEqual(tokenizer.tokenize("ah\u535A\u63A8zz")     ,  ["ah", "\u535A", "\u63A8", "zz"])

				def 							lowercase_     (	self							:				str)->   Dict:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  ")     ,  ["hello", "!", "how", "are", "you", "?"])
						self.assertListEqual(tokenizer.tokenize("H\u00E9llo")     ,  ["hello"])

				def 							lowercase_     (	self							:				Optional[int])->   List[Any]:



						'''simple docstring'''


						__lowerCAmelCase:       Union[str, Any]          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__     ,  strip_accents=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")     ,  ["hällo", "!", "how", "are", "you", "?"])
						self.assertListEqual(tokenizer.tokenize("H\u00E9llo")     ,  ["h\u00E9llo"])

				def 							lowercase_     (	self							:				Optional[Any])->   Any:



						'''simple docstring'''


						__lowerCAmelCase:       Tuple          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__     ,  strip_accents=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")     ,  ["hallo", "!", "how", "are", "you", "?"])
						self.assertListEqual(tokenizer.tokenize("H\u00E9llo")     ,  ["hello"])

				def 							lowercase_     (	self							:				str)->   List[str]:



						'''simple docstring'''


						__lowerCAmelCase:       List[str]          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")     ,  ["hallo", "!", "how", "are", "you", "?"])
						self.assertListEqual(tokenizer.tokenize("H\u00E9llo")     ,  ["hello"])

				def 							lowercase_     (	self							:				Any)->   Any:



						'''simple docstring'''


						__lowerCAmelCase:       Union[str, Any]          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU?  ")     ,  ["HeLLo", "!", "how", "Are", "yoU", "?"])

				def 							lowercase_     (	self							:				Optional[int])->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[int]          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__     ,  strip_accents=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")     ,  ["HäLLo", "!", "how", "Are", "yoU", "?"])

				def 							lowercase_     (	self							:				Optional[Any])->   Tuple:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[Any]          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__     ,  strip_accents=UpperCamelCase__)

						self.assertListEqual(
						    tokenizer.tokenize(" \tHäLLo!how  \n Are yoU?  ")     ,  ["HaLLo", "!", "how", "Are", "yoU", "?"])

				def 							lowercase_     (	self							:				Tuple)->   str:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[Any]          =			RoCBertBasicTokenizer(do_lower_case=UpperCamelCase__     ,  never_split=["[UNK]"])

						self.assertListEqual(
						    tokenizer.tokenize(" \tHeLLo!how  \n Are yoU? [UNK]")     ,  ["HeLLo", "!", "how", "Are", "yoU", "?", "[UNK]"])

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



						'''simple docstring'''


						__lowerCAmelCase:       List[str]          =			["[UNK]", "[CLS]", "[SEP]", "want", "##want", "##ed", "wa", "un", "runn", "##ing"]

						__lowerCAmelCase:       int          =			{}
						for i, token in enumerate(UpperCamelCase__):
								__lowerCAmelCase:       Optional[Any]          =			i
						__lowerCAmelCase:       str          =			RoCBertWordpieceTokenizer(vocab=UpperCamelCase__     ,  unk_token="[UNK]")

						self.assertListEqual(tokenizer.tokenize("")     ,  [])

						self.assertListEqual(tokenizer.tokenize("unwanted running")     ,  ["un", "##want", "##ed", "runn", "##ing"])

						self.assertListEqual(tokenizer.tokenize("unwantedX running")     ,  ["[UNK]", "runn", "##ing"])

				def 							lowercase_     (	self							:				Optional[Any])->   Dict:



						'''simple docstring'''


						self.assertTrue(_is_whitespace(" "))
						self.assertTrue(_is_whitespace("\t"))
						self.assertTrue(_is_whitespace("\r"))
						self.assertTrue(_is_whitespace("\n"))
						self.assertTrue(_is_whitespace("\u00A0"))

						self.assertFalse(_is_whitespace("A"))
						self.assertFalse(_is_whitespace("-"))

				def 							lowercase_     (	self							:				Dict)->   Optional[int]:



						'''simple docstring'''


						self.assertTrue(_is_control("\u0005"))

						self.assertFalse(_is_control("A"))
						self.assertFalse(_is_control(" "))
						self.assertFalse(_is_control("\t"))
						self.assertFalse(_is_control("\r"))

				def 							lowercase_     (	self							:				Union[str, Any])->   str:



						'''simple docstring'''


						self.assertTrue(_is_punctuation("-"))
						self.assertTrue(_is_punctuation("$"))
						self.assertTrue(_is_punctuation("`"))
						self.assertTrue(_is_punctuation("."))

						self.assertFalse(_is_punctuation("A"))
						self.assertFalse(_is_punctuation(" "))

				def 							lowercase_     (	self							:				Dict)->   int:



						'''simple docstring'''


						__lowerCAmelCase:       Any          =			self.get_tokenizer()

						# Example taken from the issue https://github.com/huggingface/tokenizers/issues/340
						self.assertListEqual([tokenizer.tokenize(UpperCamelCase__) for t in ["Test", "\xad", "test"]]     ,  [["[UNK]"], [], ["[UNK]"]])

						if self.test_rust_tokenizer:
								__lowerCAmelCase:       Any          =			self.get_rust_tokenizer()
								self.assertListEqual(
								    [rust_tokenizer.tokenize(UpperCamelCase__) for t in ["Test", "\xad", "test"]]     ,  [["[UNK]"], [], ["[UNK]"]])

				def 							lowercase_     (	self							:				Dict)->   Any:



						'''simple docstring'''


						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
								with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"):
										__lowerCAmelCase:       str          =			self.rust_tokenizer_class.from_pretrained(UpperCamelCase__     ,  **UpperCamelCase__)

										__lowerCAmelCase:       Optional[Any]          =			f"A, naïve {tokenizer_r.mask_token} AllenNLP sentence."
										__lowerCAmelCase:       Tuple          =			tokenizer_r.encode_plus(
										    UpperCamelCase__     ,  return_attention_mask=UpperCamelCase__     ,  return_token_type_ids=UpperCamelCase__     ,  return_offsets_mapping=UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__     ,  )

										__lowerCAmelCase:       str          =			tokenizer_r.do_lower_case if hasattr(UpperCamelCase__     ,  "do_lower_case") else False
										__lowerCAmelCase:       List[Any]          =			(
										    [
										        ((0, 0), tokenizer_r.cls_token),
										        ((0, 1), "A"),
										        ((1, 2), ","),
										        ((3, 5), "na"),
										        ((5, 6), "##ï"),
										        ((6, 8), "##ve"),
										        ((9, 1_5), tokenizer_r.mask_token),
										        ((1_6, 2_1), "Allen"),
										        ((2_1, 2_3), "##NL"),
										        ((2_3, 2_4), "##P"),
										        ((2_5, 3_3), "sentence"),
										        ((3_3, 3_4), "."),
										        ((0, 0), tokenizer_r.sep_token),
										    ]
										    if not do_lower_case
										    else [
										        ((0, 0), tokenizer_r.cls_token),
										        ((0, 1), "a"),
										        ((1, 2), ","),
										        ((3, 8), "naive"),
										        ((9, 1_5), tokenizer_r.mask_token),
										        ((1_6, 2_1), "allen"),
										        ((2_1, 2_3), "##nl"),
										        ((2_3, 2_4), "##p"),
										        ((2_5, 3_3), "sentence"),
										        ((3_3, 3_4), "."),
										        ((0, 0), tokenizer_r.sep_token),
										    ]
										)

										self.assertEqual(
										    [e[1] for e in expected_results]     ,  tokenizer_r.convert_ids_to_tokens(tokens["input_ids"]))
										self.assertEqual([e[0] for e in expected_results]     ,  tokens["offset_mapping"])

				def 							lowercase_     (	self							:				Union[str, Any])->   Optional[int]:



						'''simple docstring'''


						__lowerCAmelCase:       Optional[Any]          =			["的", "人", "有"]
						__lowerCAmelCase:       int          =			"".join(UpperCamelCase__)
						for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
								with self.subTest(f"{tokenizer.__class__.__name__} ({pretrained_name})"):
										__lowerCAmelCase:       Tuple          =			True
										__lowerCAmelCase:       str          =			self.tokenizer_class.from_pretrained(UpperCamelCase__     ,  **UpperCamelCase__)
										__lowerCAmelCase:       Dict          =			self.rust_tokenizer_class.from_pretrained(UpperCamelCase__     ,  **UpperCamelCase__)

										__lowerCAmelCase:       Union[str, Any]          =			tokenizer_p.encode(UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__)
										__lowerCAmelCase:       List[Any]          =			tokenizer_r.encode(UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__)

										__lowerCAmelCase:       Any          =			tokenizer_r.convert_ids_to_tokens(UpperCamelCase__)
										__lowerCAmelCase:       List[str]          =			tokenizer_p.convert_ids_to_tokens(UpperCamelCase__)

										# it is expected that each Chinese character is not preceded by "##"
										self.assertListEqual(UpperCamelCase__     ,  UpperCamelCase__)
										self.assertListEqual(UpperCamelCase__     ,  UpperCamelCase__)

										__lowerCAmelCase:       int          =			False
										__lowerCAmelCase:       Any          =			self.rust_tokenizer_class.from_pretrained(UpperCamelCase__     ,  **UpperCamelCase__)
										__lowerCAmelCase:       Union[str, Any]          =			self.tokenizer_class.from_pretrained(UpperCamelCase__     ,  **UpperCamelCase__)

										__lowerCAmelCase:       str          =			tokenizer_r.encode(UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__)
										__lowerCAmelCase:       str          =			tokenizer_p.encode(UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__)

										__lowerCAmelCase:       str          =			tokenizer_r.convert_ids_to_tokens(UpperCamelCase__)
										__lowerCAmelCase:       Tuple          =			tokenizer_p.convert_ids_to_tokens(UpperCamelCase__)

										# it is expected that only the first Chinese character is not preceded by "##".
										__lowerCAmelCase:       Dict          =			[
										    f"##{token}" if idx != 0 else token for idx, token in enumerate(UpperCamelCase__)
										]
										self.assertListEqual(UpperCamelCase__     ,  UpperCamelCase__)
										self.assertListEqual(UpperCamelCase__     ,  UpperCamelCase__)

				@slow
				def 							lowercase_     (	self							:				Optional[Any])->   Any:



						'''simple docstring'''


						__lowerCAmelCase:       str          =			self.tokenizer_class(self.vocab_file     ,  self.word_shape_file     ,  self.word_pronunciation_file)

						__lowerCAmelCase:       Dict          =			tokenizer.encode("你好"     ,  add_special_tokens=UpperCamelCase__)
						__lowerCAmelCase:       Union[str, Any]          =			tokenizer.encode("你是谁"     ,  add_special_tokens=UpperCamelCase__)

						__lowerCAmelCase:       Tuple          =			tokenizer.build_inputs_with_special_tokens(UpperCamelCase__)
						__lowerCAmelCase:       List[Any]          =			tokenizer.build_inputs_with_special_tokens(UpperCamelCase__     ,  UpperCamelCase__)

						assert encoded_sentence == [1] + text + [2]
						assert encoded_pair == [1] + text + [2] + text_a + [2]




				def 							lowercase_     (	self							:				Tuple)->   Optional[Any]:



						'''simple docstring'''


						__lowerCAmelCase:       int          =			self.get_tokenizers(do_lower_case=UpperCamelCase__)
						for tokenizer in tokenizers:
								with self.subTest(f"{tokenizer.__class__.__name__}"):
										__lowerCAmelCase:       str          =			"你好，你是谁"
										__lowerCAmelCase:       Dict          =			tokenizer.tokenize(UpperCamelCase__)
										__lowerCAmelCase:       Union[str, Any]          =			tokenizer.convert_tokens_to_ids(UpperCamelCase__)
										__lowerCAmelCase:       Optional[Any]          =			tokenizer.convert_tokens_to_shape_ids(UpperCamelCase__)
										__lowerCAmelCase:       Tuple          =			tokenizer.convert_tokens_to_pronunciation_ids(UpperCamelCase__)
										__lowerCAmelCase:       Dict          =			tokenizer.prepare_for_model(
										    UpperCamelCase__     ,  UpperCamelCase__     ,  UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__)

										__lowerCAmelCase:       Optional[Any]          =			tokenizer.encode_plus(UpperCamelCase__     ,  add_special_tokens=UpperCamelCase__)

										self.assertEqual(UpperCamelCase__     ,  UpperCamelCase__)


