





import os
import string
import sys


__A									=				1 << 8

__A									=				{
    "tab": ord("\t"),
    "newline": ord("\r"),
    "esc": 27,
    "up": 65 + ARROW_KEY_FLAG,
    "down": 66 + ARROW_KEY_FLAG,
    "right": 67 + ARROW_KEY_FLAG,
    "left": 68 + ARROW_KEY_FLAG,
    "mod_int": 91,
    "undefined": sys.maxsize,
    "interrupt": 3,
    "insert": 50,
    "delete": 51,
    "pg_up": 53,
    "pg_down": 54,
}

__A									=				KEYMAP["up"]
__A									=				KEYMAP["left"]

if sys.platform == "win32":
     __A									=				[]
     __A									=				{
         b"\xe0H": KEYMAP["up"] - ARROW_KEY_FLAG,
         b"\x00H": KEYMAP["up"] - ARROW_KEY_FLAG,
         b"\xe0P": KEYMAP["down"] - ARROW_KEY_FLAG,
         b"\x00P": KEYMAP["down"] - ARROW_KEY_FLAG,
         b"\xe0M": KEYMAP["right"] - ARROW_KEY_FLAG,
         b"\x00M": KEYMAP["right"] - ARROW_KEY_FLAG,
         b"\xe0K": KEYMAP["left"] - ARROW_KEY_FLAG,
         b"\x00K": KEYMAP["left"] - ARROW_KEY_FLAG,
     }

for i in range(10):
     __A									=				ord(str(i))





def      lowerCAmelCase_ (       )     ->		Dict:







  """simple docstring"""





  if os.name == "nt":
    import msvcrt

    lowerCamelCase__:      Dict			  ="mbcs"
    # Flush the keyboard buffer
    while msvcrt.kbhit():
      msvcrt.getch()
    if len(__a		) == 0:
      # Read the keystroke
      lowerCamelCase__:      Any			  =msvcrt.getch()

      # If it is a prefix char, get second part
      if ch in (b"\x00", b"\xe0"):
        lowerCamelCase__:      Any			  =ch + msvcrt.getch()
        # Translate actual Win chars to bullet char types
        try:
          lowerCamelCase__:      int			  =chr(WIN_KEYMAP[cha]		)
          WIN_CH_BUFFER.append(chr(KEYMAP["mod_int"]		)		)
          WIN_CH_BUFFER.append(__a		)
          if ord(__a		) in (
              KEYMAP["insert"] - 1 << 9,
              KEYMAP["delete"] - 1 << 9,
              KEYMAP["pg_up"] - 1 << 9,
              KEYMAP["pg_down"] - 1 << 9,
          ):
            WIN_CH_BUFFER.append(chr(126		)		)
          lowerCamelCase__:      Any			  =chr(KEYMAP["esc"]		)
        except KeyError:
          lowerCamelCase__:      Optional[Any]			  =cha[1]
      else:
        lowerCamelCase__:      Dict			  =ch.decode(__a		)
    else:
      lowerCamelCase__:      Tuple			  =WIN_CH_BUFFER.pop(0		)
  elif os.name == "posix":
    import termios
    import tty

    lowerCamelCase__:      List[Any]			  =sys.stdin.fileno()
    lowerCamelCase__:      Dict			  =termios.tcgetattr(__a		)
    try:
      tty.setraw(__a		)
      lowerCamelCase__:      str			  =sys.stdin.read(1		)
    finally:
      termios.tcsetattr(__a	,    termios.TCSADRAIN	,    __a		)
  return ch






def      lowerCAmelCase_ (       )     ->		List[Any]:







  """simple docstring"""





  lowerCamelCase__:      Any			  =get_raw_chars()
  if ord(__a		) in [KEYMAP["interrupt"], KEYMAP["newline"]]:
    return char

  elif ord(__a		) == KEYMAP["esc"]:
    lowerCamelCase__:      Optional[int]			  =get_raw_chars()
    if ord(__a		) == KEYMAP["mod_int"]:
      lowerCamelCase__:      Any			  =get_raw_chars()
      if ord(__a		) >= KEYMAP["arrow_begin"] - ARROW_KEY_FLAG and ord(__a		) <= KEYMAP["arrow_end"] - ARROW_KEY_FLAG:
        return chr(ord(__a		) + ARROW_KEY_FLAG		)
      else:
        return KEYMAP["undefined"]
    else:
      return get_raw_chars()

  else:
    if char in string.printable:
      return char
    else:
      return KEYMAP["undefined"]








import collections
import os
from shutil import copyfile
from typing import Any, Dict, List, Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


__A									=				logging.get_logger(__name__)

__A									=				"▁"

__A									=				{"vocab_file": "prophetnet.tokenizer"}

__A									=				{
    "vocab_file": {
        "microsoft/xprophetnet-large-wiki100-cased": (
            "https://huggingface.co/microsoft/xprophetnet-large-wiki100-cased/resolve/main/prophetnet.tokenizer"
        ),
    }
}

__A									=				{
    "microsoft/xprophetnet-large-wiki100-cased": {"do_lower_case": False},
}

__A									=				{
    "microsoft/xprophetnet-large-wiki100-cased": 512,
}





def      lowerCAmelCase_ (       __a		)     ->		int:







  """simple docstring"""





  lowerCamelCase__:      Optional[Any]			  =collections.OrderedDict()
  with open(__a	,    "r"	,    encoding="utf-8"		) as reader:
    lowerCamelCase__:      int			  =reader.readlines()
  for index, token in enumerate(__a		):
    lowerCamelCase__:      List[str]			  =token.rstrip("\n"		)
    lowerCamelCase__:      List[Any]			  =index
  return vocab






class    _SCREAMING_SNAKE_CASE						(	__SCREAMING_SNAKE_CASE    ):







 '''simple docstring'''
 lowercase_		=			VOCAB_FILES_NAMES
 lowercase_		=			PRETRAINED_VOCAB_FILES_MAP
 lowercase_		=			PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
 lowercase_		=			["input_ids", "attention_mask"]

 def __init__(self				:   Union[str, Any]       , UpperCAmelCase_				:   Union[str, Any]       , UpperCAmelCase_				:   Optional[Any]="[SEP]"       , UpperCAmelCase_				:   List[Any]="[SEP]"       , UpperCAmelCase_				:   Optional[Any]="[SEP]"       , UpperCAmelCase_				:   int="[UNK]"       , UpperCAmelCase_				:   Optional[Any]="[PAD]"       , UpperCAmelCase_				:   Dict="[CLS]"       , UpperCAmelCase_				:   Dict="[MASK]"       , UpperCAmelCase_				:   Optional[Dict[str, Any]] = None       , **UpperCAmelCase_				:   Tuple       , )       ->None:



   '''simple docstring'''



   lowerCamelCase__:      int			  ={} if sp_model_kwargs is None else sp_model_kwargs

   super().__init__(
       bos_token=UpperCAmelCase_       , eos_token=UpperCAmelCase_       , sep_token=UpperCAmelCase_       , unk_token=UpperCAmelCase_       , pad_token=UpperCAmelCase_       , cls_token=UpperCAmelCase_       , mask_token=UpperCAmelCase_       , sp_model_kwargs=self.sp_model_kwargs       , **UpperCAmelCase_       , )

   try:
     import sentencepiece as spm
   except ImportError:
     logger.warning(
         "You need to install SentencePiece to use XLMRobertaTokenizer: https://github.com/google/sentencepiece"
         " pip install sentencepiece")
     raise

   lowerCamelCase__:      Optional[int]			  =spm.SentencePieceProcessor(**self.sp_model_kwargs)
   self.sp_model.Load(str(UpperCAmelCase_))
   lowerCamelCase__:      Optional[int]			  =vocab_file

   # Original fairseq vocab and spm vocab must be "aligned":
   # Vocab    |    0    |    1    |   2    |    3    |  4  |  5  |  6  |   7   |   8   |  9
   # -------- | ------- | ------- | ------ | ------- | --- | --- | --- | ----- | ----- | ----
   # fairseq  | '<s>'   | '<pad>' | '</s>' | '<unk>' | ',' | '.' | '▁' | 's'   | '▁de' | '-'
   # spm      | '<unk>' | '<s>'   | '</s>' | ','     | '.' | '▁' | 's' | '▁de' | '-'   | '▁a'

   # put special tokens and [unused] tokens into the vocab
   lowerCamelCase__:      Optional[int]			  ={"[PAD]": 0, "[CLS]": 1, "[SEP]": 2, "[UNK]": 3, "[MASK]": 4}

   for i in range(10):
     lowerCamelCase__:      Optional[int]			  =F"""[unused{i}]"""
     lowerCamelCase__:      int			  =5 + i

   # The first "real" token "," has position 15 in the embedding vocab and position 3 in the spm vocab
   lowerCamelCase__:      int			  =12
   lowerCamelCase__:      Optional[Any]			  ={v: k for k, v in self.fairseq_tokens_to_ids.items()}
   for k in self.fairseq_tokens_to_ids.keys():
     self.unique_no_split_tokens.append(UpperCAmelCase_)

 def __getstate__(self				:   List[str])       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      Optional[int]			  =self.__dict__.copy()
   lowerCamelCase__:      Dict			  =None
   return state

 def __setstate__(self				:   List[str]       , UpperCAmelCase_				:   Union[str, Any])       ->Dict:



   '''simple docstring'''



   lowerCamelCase__:      Tuple			  =d
   try:
     import sentencepiece as spm
   except ImportError:
     logger.warning(
         "You need to install SentencePiece to use XLMRobertaTokenizer: https://github.com/google/sentencepiece"
         " pip install sentencepiece")
     raise

   # for backward compatibility
   if not hasattr(self       , "sp_model_kwargs"):
     lowerCamelCase__:      Dict			  ={}

   lowerCamelCase__:      Tuple			  =spm.SentencePieceProcessor(**self.sp_model_kwargs)
   self.sp_model.Load(self.vocab_file)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str]       , UpperCAmelCase_				:   List[int]       , UpperCAmelCase_				:   Optional[List[int]] = None       , UpperCAmelCase_				:   bool = False)       ->List[int]:



   '''simple docstring'''



   if already_has_special_tokens:
     return super().get_special_tokens_mask(
         token_ids_a=UpperCAmelCase_       , token_ids_a=UpperCAmelCase_       , already_has_special_tokens=UpperCAmelCase_)

   if token_ids_a is None:
     return ([0] * len(UpperCAmelCase_)) + [1]
   return ([0] * len(UpperCAmelCase_)) + [1] + ([0] * len(UpperCAmelCase_)) + [1]

 def 							SCREAMING_SNAKE_CASE_					(self				:   Dict       , UpperCAmelCase_				:   List[int]       , UpperCAmelCase_				:   Optional[List[int]] = None)       ->List[int]:



   '''simple docstring'''



   lowerCamelCase__:      Any			  =[self.sep_token_id]

   if token_ids_a is None:
     return len(token_ids_a + sep) * [0]
   return len(token_ids_a + sep + sep + token_ids_a + sep) * [0]

 @property
 def 							SCREAMING_SNAKE_CASE_					(self				:   str)       ->Dict:



   '''simple docstring'''



   return len(self.sp_model) + self.fairseq_offset

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



   '''simple docstring'''



   lowerCamelCase__:      str			  ={self.convert_ids_to_tokens(UpperCAmelCase_): i for i in range(self.vocab_size)}
   vocab.update(self.added_tokens_encoder)
   return vocab

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



   '''simple docstring'''



   return self.sp_model.encode(UpperCAmelCase_       , out_type=UpperCAmelCase_)

 def 							SCREAMING_SNAKE_CASE_					(self				:   List[Any]       , UpperCAmelCase_				:   List[Any])       ->str:



   '''simple docstring'''



   if token in self.fairseq_tokens_to_ids:
     return self.fairseq_tokens_to_ids[token]
   lowerCamelCase__:      str			  =self.sp_model.PieceToId(UpperCAmelCase_)

   # Need to return unknown token if the SP model returned 0
   return spm_id + self.fairseq_offset if spm_id else self.unk_token_id

 def 							SCREAMING_SNAKE_CASE_					(self				:   str       , UpperCAmelCase_				:   Optional[Any])       ->Optional[int]:



   '''simple docstring'''



   if index in self.fairseq_ids_to_tokens:
     return self.fairseq_ids_to_tokens[index]
   return self.sp_model.IdToPiece(index - self.fairseq_offset)

 def 							SCREAMING_SNAKE_CASE_					(self				:   int       , UpperCAmelCase_				:   Optional[Any])       ->Optional[Any]:



   '''simple docstring'''



   lowerCamelCase__:      Union[str, Any]			  ="".join(UpperCAmelCase_).replace(UpperCAmelCase_       , " ").strip()
   return out_string

 def 							SCREAMING_SNAKE_CASE_					(self				:   Union[str, Any]       , UpperCAmelCase_				:   str       , UpperCAmelCase_				:   Optional[str] = None)       ->Tuple[str]:



   '''simple docstring'''



   if not os.path.isdir(UpperCAmelCase_):
     logger.error(F"""Vocabulary path ({save_directory}) should be a directory""")
     return
   lowerCamelCase__:      List[str]			  =os.path.join(
       UpperCAmelCase_       , (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"])

   if os.path.abspath(self.vocab_file) != os.path.abspath(UpperCAmelCase_) and os.path.isfile(self.vocab_file):
     copyfile(self.vocab_file       , UpperCAmelCase_)
   elif not os.path.isfile(self.vocab_file):
     with open(UpperCAmelCase_       , "wb") as fi:
       lowerCamelCase__:      Dict			  =self.sp_model.serialized_model_proto()
       fi.write(UpperCAmelCase_)

   return (out_vocab_file,)







 def 							SCREAMING_SNAKE_CASE_					(self				:   List[str]       , UpperCAmelCase_				:   List[int]       , UpperCAmelCase_				:   Optional[List[int]] = None)       ->List[int]:



   '''simple docstring'''



   if token_ids_a is None:
     return token_ids_a + [self.sep_token_id]
   lowerCamelCase__:      Union[str, Any]			  =[self.sep_token_id]
   return token_ids_a + sep + token_ids_a + sep

