






'''simple docstring'''


import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE       ,unittest.TestCase	):


			'''simple docstring'''





			__a							:							int					     =					ProphetNetTokenizer
			__a							:							Dict					     =					False






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

									'''simple docstring'''







									super().setUp()

									UpperCamelCase__         = [
									    """[UNK]""",
									    """[CLS]""",
									    """[SEP]""",
									    """[PAD]""",
									    """[MASK]""",
									    """want""",
									    """##want""",
									    """##ed""",
									    """wa""",
									    """un""",
									    """runn""",
									    """##ing""",
									    """,""",
									    """low""",
									    """lowest""",
									]
									UpperCamelCase__         = os.path.join(self.tmpdirname ,      VOCAB_FILES_NAMES["""vocab_file"""]			)
									with open(self.vocab_file ,      """w""" ,      encoding="""utf-8"""			) as vocab_writer:
															vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]			)			)






			def 				A      (   self							:						Optional[Any] ,      lowercase							:						Union[str, Any]			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = """UNwant\u00E9d,running"""
									UpperCamelCase__         = """unwanted, running"""
									return input_text, output_text






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

									'''simple docstring'''







									UpperCamelCase__         = self.tokenizer_class(self.vocab_file			)

									UpperCamelCase__         = tokenizer.tokenize("""UNwant\u00E9d,running"""			)
									self.assertListEqual(lowercase ,      ["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]			)
									self.assertListEqual(tokenizer.convert_tokens_to_ids(lowercase			) ,      [9, 6, 7, 1_2, 1_0, 1_1]			)






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer()

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






			def 				A      (   self							:						str			)							->    Any:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase			)

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






			def 				A      (   self							:						Dict			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

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






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

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






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase			)

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






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase			)

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






			def 				A      (   self							:						List[str]			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

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






			def 				A      (   self							:						Dict			)							->    Dict:

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      strip_accents=lowercase			)

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






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

									'''simple docstring'''







									UpperCamelCase__         = BasicTokenizer(do_lower_case=lowercase ,      never_split=["""[UNK]"""]			)

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






			def 				A      (   self							:						Tuple			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = ["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

									UpperCamelCase__         = {}
									for i, token in enumerate(lowercase			):
															UpperCamelCase__         = i
									UpperCamelCase__         = WordpieceTokenizer(vocab=lowercase ,      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"""]			)






			@require_torch
			def 				A      (   self							:						Tuple			)							->    int:

									'''simple docstring'''







									UpperCamelCase__         = self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""			)

									UpperCamelCase__         = ["""A long paragraph for summarization.""", """Another paragraph for summarization."""]
									UpperCamelCase__         = [1_0_3_7, 2_1_4_6, 2_0_4_2_3, 2_0_0_5, 7_6_8_0, 7_8_4_9, 3_9_8_9, 1_0_1_2, 1_0_2]
									UpperCamelCase__         = tokenizer(lowercase ,      padding=lowercase ,      return_tensors="""pt"""			)
									self.assertIsInstance(lowercase ,      lowercase			)
									UpperCamelCase__         = list(batch.input_ids.numpy()[0]			)
									self.assertListEqual(lowercase ,      lowercase			)

									self.assertEqual((2, 9) ,      batch.input_ids.shape			)
									self.assertEqual((2, 9) ,      batch.attention_mask.shape			)






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

									'''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 				A      (   self							:						List[Any]			)							->    Union[str, Any]:

									'''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 				A      (   self							:						Optional[Any]			)							->    Union[str, Any]:

									'''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(""" """			)			)







			@slow
			def 				A      (   self							:						List[Any]			)							->    Tuple:

									'''simple docstring'''







									UpperCamelCase__         = self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""			)

									UpperCamelCase__         = tokenizer.encode("""sequence builders""" ,      add_special_tokens=lowercase			)
									UpperCamelCase__         = tokenizer.encode("""multi-sequence build""" ,      add_special_tokens=lowercase			)

									UpperCamelCase__         = tokenizer.build_inputs_with_special_tokens(lowercase			)
									UpperCamelCase__         = tokenizer.build_inputs_with_special_tokens(lowercase ,      lowercase			)

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








'''simple docstring'''


from typing import Optional

import pyspark

from .. import Features, NamedSplit
from ..download import DownloadMode
from ..packaged_modules.spark.spark import Spark
from .abc import AbstractDatasetReader
class    _SCREAMING_SNAKE_CASE							(		SCREAMING_SNAKE_CASE	):


			'''simple docstring'''





			def __init__(   self							:						Tuple ,      lowercase							:						pyspark.sql.DataFrame ,      lowercase							:						Optional[NamedSplit] = None ,      lowercase							:						Optional[Features] = None ,      lowercase							:						bool = True ,      lowercase							:						str = None ,      lowercase							:						bool = False ,      lowercase							:						str = None ,      lowercase							:						bool = True ,      lowercase							:						str = "arrow" ,      **lowercase							:						Any ,      )							->    Optional[int]:

									'''simple docstring'''







									super().__init__(
									    split=lowercase ,      features=lowercase ,      cache_dir=lowercase ,      keep_in_memory=lowercase ,      streaming=lowercase ,      **lowercase ,      )
									UpperCamelCase__         = load_from_cache_file
									UpperCamelCase__         = file_format
									UpperCamelCase__         = Spark(
									    df=lowercase ,      features=lowercase ,      cache_dir=lowercase ,      working_dir=lowercase ,      **lowercase ,      )







			def 				A      (   self							:						int			)							->    Any:

									'''simple docstring'''







									if self.streaming:
															return self.builder.as_streaming_dataset(split=self.split			)
									UpperCamelCase__         = None if self._load_from_cache_file else DownloadMode.FORCE_REDOWNLOAD
									self.builder.download_and_prepare(
									    download_mode=lowercase ,      file_format=self._file_format ,      )
									return self.builder.as_dataset(split=self.split			)
