


'''simple docstring'''







import json
import os
import re
import unicodedata
from typing import Optional, Tuple

from ...tokenization_utils import PreTrainedTokenizer, _is_control, _is_punctuation, _is_whitespace
from ...utils import logging


a__  : Tuple				=	logging.get_logger(__name__)

a__  : Tuple				=	{
    'vocab_file': 'vocab.json',
    'merges_file': 'merges.txt',
}

a__  : List[Any]				=	{
    'vocab_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/vocab.json'},
    'merges_file': {'openai-gpt': 'https://huggingface.co/openai-gpt/resolve/main/merges.txt'},
}

a__  : Optional[Any]				=	{
    'openai-gpt': 5_1_2,
}







def _UpperCamelCase	(					__A   )							->		Any:


      '''simple docstring'''



      UpperCamelCase__  =    text.strip()
      if not text:
            return []
      UpperCamelCase__  =    text.split()
      return tokens
class  lowercase_					(   __UpperCAmelCase       ):


    def __init__(					self  , a=True  , a=None  , a=True  , a=None  , a=True  , ):



          if never_split is None:
                UpperCamelCase__  =    []
          UpperCamelCase__  =    do_lower_case
          UpperCamelCase__  =    set(lowerCamelCase__   )
          UpperCamelCase__  =    tokenize_chinese_chars
          UpperCamelCase__  =    strip_accents
          UpperCamelCase__  =    do_split_on_punc


    def        __a							(					self  , a  , a=None   ):
          UpperCamelCase__  =    self.never_split.union(set(lowerCamelCase__   )   ) if never_split else self.never_split
          UpperCamelCase__  =    self._clean_text(lowerCamelCase__   )

          # This was added on November 1st, 2018 for the multilingual and Chinese
          # models. This is also applied to the English models now, but it doesn't
          # matter since the English models were not trained on any Chinese data
          # and generally don't have any Chinese data in them (there are Chinese
          # characters in the vocabulary because Wikipedia does have some Chinese
          # words in the English Wikipedia.).
          if self.tokenize_chinese_chars:
                UpperCamelCase__  =    self._tokenize_chinese_chars(lowerCamelCase__   )
          # prevents treating the same character with different unicode codepoints as different characters
          UpperCamelCase__  =    unicodedata.normalize("NFC"  , lowerCamelCase__   )
          UpperCamelCase__  =    whitespace_tokenize(lowerCamelCase__   )
          UpperCamelCase__  =    []
          for token in orig_tokens:
                if token not in never_split:
                      if self.do_lower_case:
                            UpperCamelCase__  =    token.lower()
                            if self.strip_accents is not False:
                                  UpperCamelCase__  =    self._run_strip_accents(lowerCamelCase__   )
                      elif self.strip_accents:
                            UpperCamelCase__  =    self._run_strip_accents(lowerCamelCase__   )
                split_tokens.extend(self._run_split_on_punc(lowerCamelCase__  , lowerCamelCase__   )   )

          UpperCamelCase__  =    whitespace_tokenize(" ".join(lowerCamelCase__   )   )
          return output_tokens


    def        __a							(					self  , a   ):
          UpperCamelCase__  =    unicodedata.normalize("NFD"  , lowerCamelCase__   )
          UpperCamelCase__  =    []
          for char in text:
                UpperCamelCase__  =    unicodedata.category(lowerCamelCase__   )
                if cat == "Mn":
                      continue
                output.append(lowerCamelCase__   )
          return "".join(lowerCamelCase__   )


    def        __a							(					self  , a  , a=None   ):



          if not self.do_split_on_punc or (never_split is not None and text in never_split):
                return [text]
          UpperCamelCase__  =    list(lowerCamelCase__   )
          UpperCamelCase__  =    0
          UpperCamelCase__  =    True
          UpperCamelCase__  =    []
          while i < len(lowerCamelCase__   ):
                UpperCamelCase__  =    chars[i]
                if _is_punctuation(lowerCamelCase__   ):
                      output.append([char]   )
                      UpperCamelCase__  =    True
                else:
                      if start_new_word:
                            output.append([]   )
                      UpperCamelCase__  =    False
                      output[-1].append(lowerCamelCase__   )
                i += 1

          return ["".join(lowerCamelCase__   ) for x in output]


    def        __a							(					self  , a   ):
          UpperCamelCase__  =    []
          for char in text:
                UpperCamelCase__  =    ord(lowerCamelCase__   )
                if self._is_chinese_char(lowerCamelCase__   ):
                      output.append(" "   )
                      output.append(lowerCamelCase__   )
                      output.append(" "   )
                else:
                      output.append(lowerCamelCase__   )
          return "".join(lowerCamelCase__   )


    def        __a							(					self  , a   ):



          if (
              (cp >= 0X4e_00 and cp <= 0X9f_ff)
              or (cp >= 0X34_00 and cp <= 0X4d_bf)  #
              or (cp >= 0X2_00_00 and cp <= 0X2_a6_df)  #
              or (cp >= 0X2_a7_00 and cp <= 0X2_b7_3f)  #
              or (cp >= 0X2_b7_40 and cp <= 0X2_b8_1f)  #
              or (cp >= 0X2_b8_20 and cp <= 0X2_ce_af)  #
              or (cp >= 0Xf9_00 and cp <= 0Xfa_ff)
              or (cp >= 0X2_f8_00 and cp <= 0X2_fa_1f)  #
          ):  #
                return True

          return False


    def        __a							(					self  , a   ):
          UpperCamelCase__  =    []
          for char in text:
                UpperCamelCase__  =    ord(lowerCamelCase__   )
                if cp == 0 or cp == 0Xff_fd or _is_control(lowerCamelCase__   ):
                      continue
                if _is_whitespace(lowerCamelCase__   ):
                      output.append(" "   )
                else:
                      output.append(lowerCamelCase__   )
          return "".join(lowerCamelCase__   )







def _UpperCamelCase	(					__A   )							->		int:


      '''simple docstring'''



      UpperCamelCase__  =    set()
      UpperCamelCase__  =    word[0]
      for char in word[1:]:
            pairs.add((prev_char, char)   )
            UpperCamelCase__  =    char
      return pairs







def _UpperCamelCase	(					__A   )							->		int:


      '''simple docstring'''



      UpperCamelCase__  =    text.replace("—"				,      "-"   )
      UpperCamelCase__  =    text.replace("–"				,      "-"   )
      UpperCamelCase__  =    text.replace("―"				,      "-"   )
      UpperCamelCase__  =    text.replace("…"				,      "..."   )
      UpperCamelCase__  =    text.replace("´"				,      "'"   )
      UpperCamelCase__  =    re.sub(R"(-+|~+|!+|\"+|;+|\?+|\++|,+|\)+|\(+|\\+|\/+|\*+|\[+|\]+|}+|{+|\|+|_+)"				,      R" \1 "				,      lowercase__   )
      UpperCamelCase__  =    re.sub(R"\s*\n\s*"				,      " \n "				,      lowercase__   )
      UpperCamelCase__  =    re.sub(R"[^\S\n]+"				,      " "				,      lowercase__   )
      return text.strip()



class  lowercase_					(   __UpperCAmelCase       ):
    __UpperCAmelCase             =     VOCAB_FILES_NAMES
    __UpperCAmelCase             =     PRETRAINED_VOCAB_FILES_MAP
    __UpperCAmelCase             =     PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
    __UpperCAmelCase             =     ["""input_ids""", """attention_mask"""]


    def __init__(					self  , a  , a  , a="<unk>"  , **a   ):
          super().__init__(unk_token=lowerCamelCase__  , **lowerCamelCase__   )

          try:
                import ftfy
                from spacy.lang.en import English

                UpperCamelCase__  =    English()
                UpperCamelCase__  =    _nlp.tokenizer
                UpperCamelCase__  =    ftfy.fix_text
          except ImportError:
                logger.warning("ftfy or spacy is not installed using BERT BasicTokenizer instead of SpaCy & ftfy."   )
                UpperCamelCase__  =    BasicTokenizer(do_lower_case=lowerCamelCase__   )
                UpperCamelCase__  =    None

          with open(lowerCamelCase__  , encoding="utf-8"   ) as vocab_handle:
                UpperCamelCase__  =    json.load(lowerCamelCase__   )
          UpperCamelCase__  =    {v: k for k, v in self.encoder.items()}
          with open(lowerCamelCase__  , encoding="utf-8"   ) as merges_handle:
                UpperCamelCase__  =    merges_handle.read().split("\n"   )[1:-1]
          UpperCamelCase__  =    [tuple(merge.split()   ) for merge in merges]
          UpperCamelCase__  =    dict(zip(lowerCamelCase__  , range(len(lowerCamelCase__   )   )   )   )
          UpperCamelCase__  =    {}


    @property
    def        __a							(					self   ):
          return True


    @property
    def        __a							(					self   ):
          return len(self.encoder   )


    def        __a							(					self   ):
          return dict(self.encoder  , **self.added_tokens_encoder   )


    def        __a							(					self  , a   ):
          UpperCamelCase__  =    tuple(token[:-1]   ) + (token[-1] + "</w>",)
          if token in self.cache:
                return self.cache[token]
          UpperCamelCase__  =    get_pairs(lowerCamelCase__   )

          if not pairs:
                return token + "</w>"

          while True:
                UpperCamelCase__  =    min(lowerCamelCase__  , key=lambda a   : self.bpe_ranks.get(lowerCamelCase__  , float("inf"   )   )   )
                if bigram not in self.bpe_ranks:
                      break
                UpperCamelCase__ ,     UpperCamelCase__  =    bigram
                UpperCamelCase__  =    []
                UpperCamelCase__  =    0
                while i < len(lowerCamelCase__   ):
                      try:
                            UpperCamelCase__  =    word.index(lowerCamelCase__  , lowerCamelCase__   )
                      except ValueError:
                            new_word.extend(word[i:]   )
                            break
                      else:
                            new_word.extend(word[i:j]   )
                            UpperCamelCase__  =    j

                      if word[i] == first and i < len(lowerCamelCase__   ) - 1 and word[i + 1] == second:
                            new_word.append(first + second   )
                            i += 2
                      else:
                            new_word.append(word[i]   )
                            i += 1
                UpperCamelCase__  =    tuple(lowerCamelCase__   )
                UpperCamelCase__  =    new_word
                if len(lowerCamelCase__   ) == 1:
                      break
                else:
                      UpperCamelCase__  =    get_pairs(lowerCamelCase__   )
          UpperCamelCase__  =    " ".join(lowerCamelCase__   )
          if word == "\n  </w>":
                UpperCamelCase__  =    "\n</w>"
          UpperCamelCase__  =    word
          return word


    def        __a							(					self  , a   ):
          UpperCamelCase__  =    []
          if self.fix_text is None:
                # Using BERT's BasicTokenizer
                UpperCamelCase__  =    self.nlp.tokenize(lowerCamelCase__   )
                for token in text:
                      split_tokens.extend(list(self.bpe(lowerCamelCase__   ).split(" "   )   )   )
          else:
                # Using SpaCy & ftfy (original tokenization process of OpenAI GPT)
                UpperCamelCase__  =    self.nlp(text_standardize(self.fix_text(lowerCamelCase__   )   )   )
                for token in text:
                      split_tokens.extend(list(self.bpe(token.text.lower()   ).split(" "   )   )   )
          return split_tokens


    def        __a							(					self  , a   ):
          return self.encoder.get(lowerCamelCase__  , self.encoder.get(self.unk_token   )   )


    def        __a							(					self  , a   ):
          return self.decoder.get(lowerCamelCase__  , self.unk_token   )


    def        __a							(					self  , a   ):
          UpperCamelCase__  =    "".join(lowerCamelCase__   ).replace("</w>"  , " "   ).strip()
          return out_string


    def        __a							(					self  , a  , a = None   ):



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

          with open(lowerCamelCase__  , "w"  , encoding="utf-8"   ) as f:
                f.write(json.dumps(self.encoder  , indent=2  , sort_keys=lowerCamelCase__  , ensure_ascii=lowerCamelCase__   ) + "\n"   )

          UpperCamelCase__  =    0
          with open(lowerCamelCase__  , "w"  , encoding="utf-8"   ) as writer:
                writer.write("#version: 0.2\n"   )
                for bpe_tokens, token_index in sorted(self.bpe_ranks.items()  , key=lambda a   : kv[1]   ):
                      if index != token_index:
                            logger.warning(
                                f'''Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'''
                                " Please check that the tokenizer is not corrupted!"   )
                            UpperCamelCase__  =    token_index
                      writer.write(" ".join(lowerCamelCase__   ) + "\n"   )
                      index += 1

          return vocab_file, merge_file







'''simple docstring'''







def _UpperCamelCase	(					__A   )							->		int:


      '''simple docstring'''



      if number != int(__A   ):
            raise ValueError("factorial() only accepts integral values"   )
      if number < 0:
            raise ValueError("factorial() not defined for negative values"   )
      UpperCamelCase__  =    1
      for i in range(1				,      number + 1   ):
            value *= i
      return value







def _UpperCamelCase	(					__A   )							->		int:


      '''simple docstring'''



      if not isinstance(__A				,      __A   ):
            raise ValueError("factorial() only accepts integral values"   )
      if n < 0:
            raise ValueError("factorial() not defined for negative values"   )
      return 1 if n == 0 or n == 1 else n * factorial(n - 1   )


if __name__ == "__main__":
  import doctest

  doctest.testmod()

  a__  : str				=	int(input('Enter a positive integer: ').strip() or 0)
  print(F"""factorial{n} is {factorial(n)}""")





