





'''simple docstring'''




import json
import os
from functools import lru_cache
from typing import List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


_SCREAMING_SNAKE_CASE							     =			logging.get_logger(__name__)


_SCREAMING_SNAKE_CASE							     =			{"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt"""}

# See all BART models at https://huggingface.co/models?filter=bart
_SCREAMING_SNAKE_CASE							     =			{
    """vocab_file""": {
        """facebook/bart-base""": """https://huggingface.co/facebook/bart-base/resolve/main/vocab.json""",
        """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/vocab.json""",
        """facebook/bart-large-mnli""": """https://huggingface.co/facebook/bart-large-mnli/resolve/main/vocab.json""",
        """facebook/bart-large-cnn""": """https://huggingface.co/facebook/bart-large-cnn/resolve/main/vocab.json""",
        """facebook/bart-large-xsum""": """https://huggingface.co/facebook/bart-large-xsum/resolve/main/vocab.json""",
        """yjernite/bart_eli5""": """https://huggingface.co/yjernite/bart_eli5/resolve/main/vocab.json""",
    },
    """merges_file""": {
        """facebook/bart-base""": """https://huggingface.co/facebook/bart-base/resolve/main/merges.txt""",
        """facebook/bart-large""": """https://huggingface.co/facebook/bart-large/resolve/main/merges.txt""",
        """facebook/bart-large-mnli""": """https://huggingface.co/facebook/bart-large-mnli/resolve/main/merges.txt""",
        """facebook/bart-large-cnn""": """https://huggingface.co/facebook/bart-large-cnn/resolve/main/merges.txt""",
        """facebook/bart-large-xsum""": """https://huggingface.co/facebook/bart-large-xsum/resolve/main/merges.txt""",
        """yjernite/bart_eli5""": """https://huggingface.co/yjernite/bart_eli5/resolve/main/merges.txt""",
    },
}

_SCREAMING_SNAKE_CASE							     =			{
    """facebook/bart-base""": 1024,
    """facebook/bart-large""": 1024,
    """facebook/bart-large-mnli""": 1024,
    """facebook/bart-large-cnn""": 1024,
    """facebook/bart-large-xsum""": 1024,
    """yjernite/bart_eli5""": 1024,
}





@lru_cache()
def 	__lowerCamelCase			(      )		->  Any:
   snake_case 						=   (
       list(range(ord("""!"""		)      ,    ord("""~"""		) + 1		)		) + list(range(ord("""¡"""		)      ,    ord("""¬"""		) + 1		)		) + list(range(ord("""®"""		)      ,    ord("""ÿ"""		) + 1		)		)
   )
   snake_case 						=   bs[:]
   snake_case 						=   0
   for b in range(2**8		):
      if b not in bs:
         bs.append(UpperCamelCase__		)
         cs.append(2**8 + n		)
         n += 1
   snake_case 						=   [chr(UpperCamelCase__		) for n in cs]
   return dict(zip(UpperCamelCase__      ,    UpperCamelCase__		)		)





def 	__lowerCamelCase			(      __lowerCAmelCase       :							Any		)		->  int:
   snake_case 						=   set()
   snake_case 						=   word[0]
   for char in word[1:]:
      pairs.add((prev_char, char)		)
      snake_case 						=   char
   return pairs


class 			_lowerCAmelCase		(			__lowercase	):






     """simple docstring"""






     snake_case_						      =   VOCAB_FILES_NAMES
     snake_case_						      =   PRETRAINED_VOCAB_FILES_MAP
     snake_case_						      =   PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
     snake_case_						      =   ['''input_ids''', '''attention_mask''']



     def __init__(   self							:			Dict   ,       __snake_case							:			str   ,       __snake_case							:			Tuple   ,       __snake_case							:			Union[str, Any]="replace"   ,       __snake_case							:			str="<s>"   ,       __snake_case							:			Optional[int]="</s>"   ,       __snake_case							:			int="</s>"   ,       __snake_case							:			Optional[Any]="<s>"   ,       __snake_case							:			Optional[int]="<unk>"   ,       __snake_case							:			Any="<pad>"   ,       __snake_case							:			Optional[int]="<mask>"   ,       __snake_case							:			Optional[Any]=False   ,       **__snake_case							:			Dict   ,       )->	Any:
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else bos_token
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else eos_token
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else sep_token
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else cls_token
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else unk_token
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else pad_token

        # Mask token behave like a normal word, i.e. include the space before it
        snake_case 						=   AddedToken(_lowerCAmelCase   ,       lstrip=_lowerCAmelCase   ,       rstrip=_lowerCAmelCase						) if isinstance(_lowerCAmelCase   ,       _lowerCAmelCase						) else mask_token

        super().__init__(
            errors=_lowerCAmelCase   ,       bos_token=_lowerCAmelCase   ,       eos_token=_lowerCAmelCase   ,       unk_token=_lowerCAmelCase   ,       sep_token=_lowerCAmelCase   ,       cls_token=_lowerCAmelCase   ,       pad_token=_lowerCAmelCase   ,       mask_token=_lowerCAmelCase   ,       add_prefix_space=_lowerCAmelCase   ,       **_lowerCAmelCase   ,       )

        with open(_lowerCAmelCase   ,       encoding="""utf-8"""						) as vocab_handle:
           snake_case 						=   json.load(_lowerCAmelCase						)
        snake_case 						=   {v: k for k, v in self.encoder.items()}
        snake_case 						=   errors  # how to handle errors in decoding
        snake_case 						=   bytes_to_unicode()
        snake_case 						=   {v: k for k, v in self.byte_encoder.items()}
        with open(_lowerCAmelCase   ,       encoding="""utf-8"""						) as merges_handle:
           snake_case 						=   merges_handle.read().split("""\n"""						)[1:-1]
        snake_case 						=   [tuple(merge.split()						) for merge in bpe_merges]
        snake_case 						=   dict(zip(_lowerCAmelCase   ,       range(len(_lowerCAmelCase						)						)						)						)
        snake_case 						=   {}
        snake_case 						=   add_prefix_space

        # Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
        snake_case 						=   re.compile(r"""\'s|\'t|\'re|\'ve|\'m|\'ll|\'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"""						)



     @property
     def      lowerCAmelCase			(   self							:			Union[str, Any]						)->	Optional[Any]:
        return len(self.encoder						)



     def      lowerCAmelCase			(   self							:			Dict						)->	List[str]:
        return dict(self.encoder   ,       **self.added_tokens_encoder						)



     def      lowerCAmelCase			(   self							:			List[str]   ,       __snake_case							:			Tuple						)->	Any:




        if token in self.cache:
           return self.cache[token]
        snake_case 						=   tuple(_lowerCAmelCase						)
        snake_case 						=   get_pairs(_lowerCAmelCase						)

        if not pairs:
           return token

        while True:
           snake_case 						=   min(_lowerCAmelCase   ,       key=lambda __snake_case						: self.bpe_ranks.get(_lowerCAmelCase   ,       float("""inf"""						)						)						)
           if bigram not in self.bpe_ranks:
              break
           snake_case 						=   bigram
           snake_case 						=   []
           snake_case 						=   0
           while i < len(_lowerCAmelCase						):
              try:
                 snake_case 						=   word.index(_lowerCAmelCase   ,       _lowerCAmelCase						)
              except ValueError:
                 new_word.extend(word[i:]						)
                 break
              else:
                 new_word.extend(word[i:j]						)
                 snake_case 						=   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
           snake_case 						=   tuple(_lowerCAmelCase						)
           snake_case 						=   new_word
           if len(_lowerCAmelCase						) == 1:
              break
           else:
              snake_case 						=   get_pairs(_lowerCAmelCase						)
        snake_case 						=   ''' '''.join(_lowerCAmelCase						)
        snake_case 						=   word
        return word



     def      lowerCAmelCase			(   self							:			Dict   ,       __snake_case							:			List[str]						)->	Optional[int]:
        snake_case 						=   []
        for token in re.findall(self.pat   ,       _lowerCAmelCase						):
           snake_case 						=   ''''''.join(
               self.byte_encoder[b] for b in token.encode("""utf-8"""						)						)  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
           bpe_tokens.extend(bpe_token for bpe_token in self.bpe(_lowerCAmelCase						).split(""" """						)						)
        return bpe_tokens



     def      lowerCAmelCase			(   self							:			int   ,       __snake_case							:			str						)->	Tuple:
        return self.encoder.get(_lowerCAmelCase   ,       self.encoder.get(self.unk_token						)						)



     def      lowerCAmelCase			(   self							:			List[Any]   ,       __snake_case							:			Union[str, Any]						)->	List[Any]:
        return self.decoder.get(_lowerCAmelCase						)



     def      lowerCAmelCase			(   self							:			Optional[Any]   ,       __snake_case							:			Tuple						)->	Optional[int]:
        snake_case 						=   ''''''.join(_lowerCAmelCase						)
        snake_case 						=   bytearray([self.byte_decoder[c] for c in text]						).decode("""utf-8"""   ,       errors=self.errors						)
        return text



     def      lowerCAmelCase			(   self							:			Any   ,       __snake_case							:			List[str]   ,       __snake_case							:			List[str] = None						)->	Any:




        if not os.path.isdir(_lowerCAmelCase						):
           logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''						)
           return
        snake_case 						=   os.path.join(
            _lowerCAmelCase   ,       (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]						)
        snake_case 						=   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"""						)

        snake_case 						=   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 __snake_case						: 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!"""						)
                 snake_case 						=   token_index
              writer.write(""" """.join(_lowerCAmelCase						) + """\n"""						)
              index += 1

        return vocab_file, merge_file



     def      lowerCAmelCase			(   self							:			int   ,       __snake_case							:			Optional[int]   ,       __snake_case							:			Optional[Any] = None						)->	Optional[int]:




        if token_ids_a is None:
           return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
        snake_case 						=   [self.cls_token_id]
        snake_case 						=   [self.sep_token_id]
        return cls + token_ids_a + sep + sep + token_ids_a + sep



     def      lowerCAmelCase			(   self							:			List[str]   ,       __snake_case							:			List[str]   ,       __snake_case							:			Optional[Any] = None   ,       __snake_case							:			int = False						)->	str:




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

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



     def      lowerCAmelCase			(   self							:			Optional[Any]   ,       __snake_case							:			Union[str, Any]   ,       __snake_case							:			Any = None						)->	Dict:
        snake_case 						=   [self.sep_token_id]
        snake_case 						=   [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 + sep + token_ids_a + sep						) * [0]



     def      lowerCAmelCase			(   self							:			Optional[Any]   ,       __snake_case							:			Optional[int]   ,       __snake_case							:			Union[str, Any]=False   ,       **__snake_case							:			Union[str, Any]						)->	Any:
        snake_case 						=   kwargs.pop("""add_prefix_space"""   ,       self.add_prefix_space						)
        if (is_split_into_words or add_prefix_space) and (len(_lowerCAmelCase						) > 0 and not text[0].isspace()):
           snake_case 						=   ''' ''' + text
        return (text, kwargs)








import re






def 		lowerCAmelCase  (	UpperCamelCase__   :   str					)      ->    bool:

						"""simple docstring"""





						__SCREAMING_SNAKE_CASE:				Optional[int]           =   re.compile(
						    R'''^(?:0|94|\+94|0{2}94)''' R'''7(0|1|2|4|5|6|7|8)''' R'''(-| |)''' R'''\d{7}$'''					)

						return bool(re.search(UpperCamelCase__       ,			UpperCamelCase__					)					)


if __name__ == "__main__":
							lowerCAmelCase							:       str					 =	"""0094702343221"""

							print(is_sri_lankan_phone_number(phone))



