





'''simple docstring'''






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 SPIECE_UNDERLINE, logging


A__				:   Any      =logging.get_logger(__name__)

A__				:   Optional[Any]      ={'''vocab_file''': '''spiece.model'''}

A__				:   str      ={
    '''vocab_file''': {
        '''TsinghuaAI/CPM-Generate''': '''https://huggingface.co/TsinghuaAI/CPM-Generate/resolve/main/spiece.model''',
    }
}




class  UpperCAmelCase     (			A_   ):




      def __init__(			self			: str			,			__snake_case			: Tuple			,			__snake_case			: int=False			,			__snake_case			: Union[str, Any]=True			,			__snake_case			: List[Any]=False			,			__snake_case			: Dict="<s>"			,			__snake_case			: Optional[Any]="</s>"			,			__snake_case			: List[str]="<unk>"			,			__snake_case			: int="<sep>"			,			__snake_case			: List[Any]="<pad>"			,			__snake_case			: Union[str, Any]="<cls>"			,			__snake_case			: str="<mask>"			,			__snake_case			: int=["<eop>", "<eod>"]			,			__snake_case			: Optional[Dict[str, Any]] = None			,			**__snake_case			: Optional[int]			,			)				->      None:
            _lowerCAmelCase							     =							AddedToken(_snake_case			,			lstrip=_snake_case			,			rstrip=_snake_case  ) if isinstance(_snake_case			,			_snake_case  ) else mask_token

            _lowerCAmelCase							     =							{} if sp_model_kwargs is None else sp_model_kwargs

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

            _lowerCAmelCase							     =							3

            _lowerCAmelCase							     =							do_lower_case
            _lowerCAmelCase							     =							remove_space
            _lowerCAmelCase							     =							keep_accents
            _lowerCAmelCase							     =							vocab_file

            _lowerCAmelCase							     =							spm.SentencePieceProcessor(**self.sp_model_kwargs  )
            self.sp_model.Load(_snake_case  )

            try:
                  import jieba
            except ModuleNotFoundError as error:
                  raise error.__class__(
                      """You need to install jieba to use CpmTokenizer or CpmTokenizerFast. """
                      """See https://pypi.org/project/jieba/ for installation."""  )
            _lowerCAmelCase							     =							jieba
            _lowerCAmelCase							     =							str.maketrans(""" \n"""			,			"""\u2582\u2583"""  )




      @property
      # Copied from transformers.models.xlnet.tokenization_xlnet.XLNetTokenizer.vocab_size
      def 				lowercase__    (			self			: Tuple  )				->      Optional[Any]:
            return len(self.sp_model  )




      def 				lowercase__    (			self			: Optional[Any]  )				->      Dict:
            _lowerCAmelCase							     =							{self.convert_ids_to_tokens(_snake_case  ): i for i in range(self.vocab_size  )}
            vocab.update(self.added_tokens_encoder  )
            return vocab




      def __getstate__(			self			: Optional[int]  )				->      Tuple:
            _lowerCAmelCase							     =							self.__dict__.copy()
            _lowerCAmelCase							     =							None
            return state




      def __setstate__(			self			: List[str]			,			__snake_case			: int  )				->      Union[str, Any]:
            _lowerCAmelCase							     =							d

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

            _lowerCAmelCase							     =							spm.SentencePieceProcessor(**self.sp_model_kwargs  )
            self.sp_model.Load(self.vocab_file  )




      def 				lowercase__    (			self			: List[str]			,			__snake_case			: Optional[Any]  )				->      Optional[Any]:



            if self.remove_space:
                  _lowerCAmelCase							     =							''' '''.join(inputs.strip().split()  )
            else:
                  _lowerCAmelCase							     =							inputs
            _lowerCAmelCase							     =							outputs.replace("""``"""			,			"""\""""  ).replace("""\'\'"""			,			"""\""""  )

            if not self.keep_accents:
                  _lowerCAmelCase							     =							unicodedata.normalize("""NFKD"""			,			_snake_case  )
                  _lowerCAmelCase							     =							''''''.join([c for c in outputs if not unicodedata.combining(_snake_case  )]  )
            if self.do_lower_case:
                  _lowerCAmelCase							     =							outputs.lower()

            return outputs




      def 				lowercase__    (			self			: int			,			__snake_case			: str  )				->      List[str]:
            _lowerCAmelCase							     =							self.preprocess_text(_snake_case  )
            _lowerCAmelCase							     =							self.sp_model.encode(_snake_case			,			out_type=_snake_case  )
            _lowerCAmelCase							     =							[]
            for piece in pieces:
                  if len(_snake_case  ) > 1 and piece[-1] == str(""","""  ) and piece[-2].isdigit():
                        _lowerCAmelCase							     =							self.sp_model.EncodeAsPieces(piece[:-1].replace(_snake_case			,			""""""  )  )
                        if piece[0] != SPIECE_UNDERLINE and cur_pieces[0][0] == SPIECE_UNDERLINE:
                              if len(cur_pieces[0]  ) == 1:
                                    _lowerCAmelCase							     =							cur_pieces[1:]
                              else:
                                    _lowerCAmelCase							     =							cur_pieces[0][1:]
                        cur_pieces.append(piece[-1]  )
                        new_pieces.extend(_snake_case  )
                  else:
                        new_pieces.append(_snake_case  )

            return new_pieces




      def 				lowercase__    (			self			: List[str]			,			__snake_case			: List[Any]  )				->      Union[str, Any]:
            return self.sp_model.PieceToId(_snake_case  )




      def 				lowercase__    (			self			: List[Any]			,			__snake_case			: Optional[Any]  )				->      Tuple:
            return self.sp_model.IdToPiece(_snake_case  )




      def 				lowercase__    (			self			: Dict			,			__snake_case			: int  )				->      Tuple:
            _lowerCAmelCase							     =							''''''.join(_snake_case  ).replace(_snake_case			,			""" """  ).strip()
            return out_string




      def 				lowercase__    (			self			: Tuple			,			__snake_case			: List[int]			,			__snake_case			: Optional[List[int]] = None  )				->      List[int]:
            _lowerCAmelCase							     =							[self.sep_token_id]
            _lowerCAmelCase							     =							[self.cls_token_id]
            if token_ids_a is None:
                  return token_ids_a + sep + cls
            return token_ids_a + sep + token_ids_a + sep + cls




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



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

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




      def 				lowercase__    (			self			: List[Any]			,			__snake_case			: List[int]			,			__snake_case			: Optional[List[int]] = None  )				->      List[int]:
            _lowerCAmelCase							     =							[self.sep_token_id]
            _lowerCAmelCase							     =							[2]

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




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



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

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

            return (out_vocab_file,)




      def 				lowercase__    (			self			: List[Any]			,			*__snake_case			: List[Any]			,			**__snake_case			: List[str]  )				->      Dict:
            _lowerCAmelCase							     =							super()._decode(*_snake_case			,			**_snake_case  )
            _lowerCAmelCase							     =							text.replace(""" """			,			""""""  ).replace("""\u2582"""			,			""" """  ).replace("""\u2583"""			,			"""\n"""  )
            return text











"""simple docstring"""







def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase	)							->      List[Any]:
		print('''\nThe shortest path matrix using Floyd Warshall algorithm\n'''	)
		for i in range(__lowerCamelCase	):
				for j in range(__lowerCamelCase	):
						if dist[i][j] != float('''inf'''	):
								print(int(dist[i][j]	)						,     end='''\t'''	)
						else:
								print('''INF'''						,     end='''\t'''	)
				print()



def      __UpperCAmelCase      (    __lowerCamelCase						,     __lowerCamelCase	)							->      Optional[Any]:
		lowercase__   :    str				=			[[float('''inf'''	) for _ in range(__lowerCamelCase	)] for _ in range(__lowerCamelCase	)]

		for i in range(__lowerCamelCase	):
				for j in range(__lowerCamelCase	):
						lowercase__   :    List[str]				=			graph[i][j]

						# check vertex k against all other vertices (i, j)
		for k in range(__lowerCamelCase	):
				# looping through rows of graph array
				for i in range(__lowerCamelCase	):
						# looping through columns of graph array
						for j in range(__lowerCamelCase	):
								if (
								    dist[i][k] != float('''inf'''	)
								    and dist[k][j] != float('''inf'''	)
								    and dist[i][k] + dist[k][j] < dist[i][j]
								):
										lowercase__   :    str				=			dist[i][k] + dist[k][j]

		_print_dist(__lowerCamelCase						,     __lowerCamelCase	)
		return dist, v


if __name__ == "__main__":
							lowerCAmelCase_   						=   int(input('Enter number of vertices: '))
							lowerCAmelCase_   						=   int(input('Enter number of edges: '))

							lowerCAmelCase_   						=   [[float('inf') for i in range(v)] for j in range(v)]

							for i in range(v):
														lowerCAmelCase_   						=   0.0

														# src and dst are indices that must be within the array size graph[e][v]
														# failure to follow this will result in an error
							for i in range(e):
														print('\nEdge ', i + 1)
														lowerCAmelCase_   						=   int(input('Enter source:'))
														lowerCAmelCase_   						=   int(input('Enter destination:'))
														lowerCAmelCase_   						=   float(input('Enter weight:'))
														lowerCAmelCase_   						=   weight

							floyd_warshall(graph, v)

							# Example Input
							# Enter number of vertices: 3
							# Enter number of edges: 2

							# # generated graph from vertex and edge inputs
							# [[inf, inf, inf], [inf, inf, inf], [inf, inf, inf]]
							# [[0.0, inf, inf], [inf, 0.0, inf], [inf, inf, 0.0]]

							# specify source, destination and weight for edge #1
							# Edge  1
							# Enter source:1
							# Enter destination:2
							# Enter weight:2

							# specify source, destination and weight for edge #2
							# Edge  2
							# Enter source:2
							# Enter destination:1
							# Enter weight:1

							# # Expected Output from the vertice, edge and src, dst, weight inputs!!
							# 0		INF	INF
							# INF	0	2
							# INF	1	0
