


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

import sentencepiece as spm

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


snake_case				:    Optional[int]       				=     logging.get_logger(__name__)
snake_case				:    Any       				=     {'''vocab_file''': '''spiece.model'''}

snake_case				:    List[Any]       				=     {
    '''vocab_file''': {
        '''albert-base-v1''': '''https://huggingface.co/albert-base-v1/resolve/main/spiece.model''',
        '''albert-large-v1''': '''https://huggingface.co/albert-large-v1/resolve/main/spiece.model''',
        '''albert-xlarge-v1''': '''https://huggingface.co/albert-xlarge-v1/resolve/main/spiece.model''',
        '''albert-xxlarge-v1''': '''https://huggingface.co/albert-xxlarge-v1/resolve/main/spiece.model''',
        '''albert-base-v2''': '''https://huggingface.co/albert-base-v2/resolve/main/spiece.model''',
        '''albert-large-v2''': '''https://huggingface.co/albert-large-v2/resolve/main/spiece.model''',
        '''albert-xlarge-v2''': '''https://huggingface.co/albert-xlarge-v2/resolve/main/spiece.model''',
        '''albert-xxlarge-v2''': '''https://huggingface.co/albert-xxlarge-v2/resolve/main/spiece.model''',
    }
}

snake_case				:    int       				=     {
    '''albert-base-v1''': 5_12,
    '''albert-large-v1''': 5_12,
    '''albert-xlarge-v1''': 5_12,
    '''albert-xxlarge-v1''': 5_12,
    '''albert-base-v2''': 5_12,
    '''albert-large-v2''': 5_12,
    '''albert-xlarge-v2''': 5_12,
    '''albert-xxlarge-v2''': 5_12,
}

snake_case				:    List[Any]       				=     '''▁'''







class 		_snake_case  (      _snake_case							):
 SCREAMING_SNAKE_CASE__      =       VOCAB_FILES_NAMES
 SCREAMING_SNAKE_CASE__      =       PRETRAINED_VOCAB_FILES_MAP
 SCREAMING_SNAKE_CASE__      =       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES




 def __init__(		self					,  _lowerCamelCase					,  _lowerCamelCase=True					,  _lowerCamelCase=True					,  _lowerCamelCase=False					,  _lowerCamelCase="[CLS]"					,  _lowerCamelCase="[SEP]"					,  _lowerCamelCase="<unk>"					,  _lowerCamelCase="[SEP]"					,  _lowerCamelCase="<pad>"					,  _lowerCamelCase="[CLS]"					,  _lowerCamelCase="[MASK]"					,  _lowerCamelCase = None					,  **_lowerCamelCase					,  ):
       # Mask token behave like a normal word, i.e. include the space before it and
       # is included in the raw text, there should be a match in a non-normalized sentence.
       a						:str 							=       (
           AddedToken(_lowerCamelCase					,  lstrip=_lowerCamelCase					,  rstrip=_lowerCamelCase					,  normalized=_lowerCamelCase    )
           if isinstance(_lowerCamelCase					,  _lowerCamelCase    )
           else mask_token
       )

       a						:str 							=       {} if sp_model_kwargs is None else sp_model_kwargs

       super().__init__(
           do_lower_case=_lowerCamelCase					,  remove_space=_lowerCamelCase					,  keep_accents=_lowerCamelCase					,  bos_token=_lowerCamelCase					,  eos_token=_lowerCamelCase					,  unk_token=_lowerCamelCase					,  sep_token=_lowerCamelCase					,  pad_token=_lowerCamelCase					,  cls_token=_lowerCamelCase					,  mask_token=_lowerCamelCase					,  sp_model_kwargs=self.sp_model_kwargs					,  **_lowerCamelCase					,  )

       a						:List[Any] 							=       do_lower_case
       a						:int 							=       remove_space
       a						:List[Any] 							=       keep_accents
       a						:Optional[int] 							=       vocab_file

       a						:Tuple 							=       spm.SentencePieceProcessor(**self.sp_model_kwargs    )
       self.sp_model.Load(_lowerCamelCase    )




 @property
 def        SCREAMING_SNAKE_CASE__				(		self    ):
       return len(self.sp_model    )




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       a						:Optional[Any] 							=       {self.convert_ids_to_tokens(_lowerCamelCase    ): i for i in range(self.vocab_size    )}
       vocab.update(self.added_tokens_encoder    )
       return vocab




 def __getstate__(		self    ):
       a						:Optional[int] 							=       self.__dict__.copy()
       a						:int 							=       None
       return state




 def __setstate__(		self					,  _lowerCamelCase    ):
       a						:Union[str, Any] 							=       d

       # for backward compatibility
       if not hasattr(self					,  '''sp_model_kwargs'''    ):
             a						:Any 							=       {}

       a						:List[Any] 							=       spm.SentencePieceProcessor(**self.sp_model_kwargs    )
       self.sp_model.Load(self.vocab_file    )




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase    ):
       if self.remove_space:
             a						:int 							=       ''' '''.join(inputs.strip().split()    )
       else:
             a						:Tuple 							=       inputs
       a						:Tuple 							=       outputs.replace('''``'''					,  '''"'''    ).replace('''\'\''''					,  '''"'''    )

       if not self.keep_accents:
             a						:List[str] 							=       unicodedata.normalize('''NFKD'''					,  _lowerCamelCase    )
             a						:List[str] 							=       ''''''.join([c for c in outputs if not unicodedata.combining(_lowerCamelCase    )]    )
       if self.do_lower_case:
             a						:Tuple 							=       outputs.lower()

       return outputs




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase    ):
       a						:Optional[Any] 							=       self.preprocess_text(_lowerCamelCase    )
       a						:int 							=       self.sp_model.encode(_lowerCamelCase					,  out_type=_lowerCamelCase    )
       a						:Tuple 							=       []
       for piece in pieces:
             if len(_lowerCamelCase    ) > 1 and piece[-1] == str(''','''    ) and piece[-2].isdigit():
                   a						:int 							=       self.sp_model.EncodeAsPieces(piece[:-1].replace(_lowerCamelCase					,  ''''''    )    )
                   if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                         if len(cur_pieces[0]    ) == 1:
                               a						:List[str] 							=       cur_pieces[1:]
                         else:
                               a						:Optional[Any] 							=       cur_pieces[0][1:]
                   cur_pieces.append(piece[-1]    )
                   new_pieces.extend(_lowerCamelCase    )
             else:
                   new_pieces.append(_lowerCamelCase    )

       return new_pieces




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase    ):
       return self.sp_model.PieceToId(_lowerCamelCase    )




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase    ):
       return self.sp_model.IdToPiece(_lowerCamelCase    )




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase    ):
       a						:Dict 							=       []
       a						:List[Any] 							=       ''''''
       a						:str 							=       False
       for token in tokens:
             # make sure that special tokens are not decoded using sentencepiece model
             if token in self.all_special_tokens:
                   if not prev_is_special:
                         out_string += " "
                   out_string += self.sp_model.decode(_lowerCamelCase    ) + token
                   a						:Optional[int] 							=       True
                   a						:str 							=       []
             else:
                   current_sub_tokens.append(_lowerCamelCase    )
                   a						:Optional[int] 							=       False
       out_string += self.sp_model.decode(_lowerCamelCase    )
       return out_string.strip()




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase = None    ):
       a						:str 							=       [self.sep_token_id]
       a						:str 							=       [self.cls_token_id]
       if token_ids_a is None:
             return cls + token_ids_a + sep
       return cls + token_ids_a + sep + token_ids_a + sep




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase = None					,  _lowerCamelCase = False    ):

       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 not None:
             return [1] + ([0] * len(_lowerCamelCase    )) + [1] + ([0] * len(_lowerCamelCase    )) + [1]
       return [1] + ([0] * len(_lowerCamelCase    )) + [1]




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase = None    ):
       a						:Union[str, Any] 							=       [self.sep_token_id]
       a						:Optional[int] 							=       [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    ) * [0] + len(token_ids_a + sep    ) * [1]




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase = None    ):
       if not os.path.isdir(_lowerCamelCase    ):
             logger.error(F'''Vocabulary path ({save_directory}) should be a directory'''    )
             return
       a						:Dict 							=       os.path.join(
           _lowerCamelCase					,  (filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']    )

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

       return (out_vocab_file,)









import math







class 		_snake_case  :




 def __init__(		self					,  _lowerCamelCase=0    ):  # a graph with Node 0,1,...,N-1
       a						:Optional[int] 							=       n
       a						:Union[str, Any] 							=       [
           [math.inf for j in range(0					,  _lowerCamelCase    )] for i in range(0					,  _lowerCamelCase    )
       ]  # adjacency matrix for weight
       a						:List[Any] 							=       [
           [math.inf for j in range(0					,  _lowerCamelCase    )] for i in range(0					,  _lowerCamelCase    )
       ]  # dp[i][j] stores minimum distance from i to j




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase					,  _lowerCamelCase    ):
       a						:Tuple 							=       w




 def        SCREAMING_SNAKE_CASE__				(		self    ):
       for k in range(0					,  self.n    ):
             for i in range(0					,  self.n    ):
                   for j in range(0					,  self.n    ):
                         a						:Union[str, Any] 							=       min(self.dp[i][j]					,  self.dp[i][k] + self.dp[k][j]    )




 def        SCREAMING_SNAKE_CASE__				(		self					,  _lowerCamelCase					,  _lowerCamelCase    ):
       return self.dp[u][v]


if __name__ == "__main__":
     snake_case				:    str       				=     Graph(5)
     graph.add_edge(0, 2, 9)
     graph.add_edge(0, 4, 10)
     graph.add_edge(1, 3, 5)
     graph.add_edge(2, 3, 7)
     graph.add_edge(3, 0, 10)
     graph.add_edge(3, 1, 2)
     graph.add_edge(3, 2, 1)
     graph.add_edge(3, 4, 6)
     graph.add_edge(4, 1, 3)
     graph.add_edge(4, 2, 4)
     graph.add_edge(4, 3, 9)
     graph.floyd_warshall()
     graph.show_min(1, 4)
     graph.show_min(0, 3)





