





import io
import os
import unicodedata
from typing import Any, Dict, List, Optional, Tuple

import sentencepiece as spm

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


A_												=     logging.get_logger(__name__)

A_												=     "▁"

A_												=     {"vocab_file": "vocab.txt", "sentencepiece_model_ckpt": "sentencepiece.bpe.model"}

A_												=     {
    "sentencepiece_model_file": "sentencepiece.bpe.model",
    "vocab_file": "vocab.txt",
}

A_												=     {
    "vocab_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/vocab.txt",
    },
    "sentencepiece_model_file": {
        "ernie-m-base": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
        "ernie-m-large": "https://huggingface.co/susnato/ernie-m-base_pytorch/blob/main/sentencepiece.bpe.model",
    },
}

A_												=     {
    "ernie-m-base": 5_1_4,
    "ernie-m-large": 5_1_4,
}

A_												=     {
    "ernie-m-base": {"do_lower_case": False},
    "ernie-m-large": {"do_lower_case": False},
}

class SCREAMING_SNAKE_CASE_ (					lowercase_   ):





					"""simple docstring"""


					A__				 =    ["input_ids"]

					A__				 =    VOCAB_FILES_NAMES
					A__				 =    PRETRAINED_INIT_CONFIGURATION
					A__				 =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
					A__				 =    PRETRAINED_VOCAB_FILES_MAP
					A__				 =    RESOURCE_FILES_NAMES





					def __init__( self	,  _lowerCAmelCase	,  _lowerCAmelCase=None	,  _lowerCAmelCase=False	,  _lowerCAmelCase="utf8"	,  _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.

										lowerCamelCase__       =       {} if sp_model_kwargs is None else sp_model_kwargs
										super().__init__(
										    do_lower_case=_lowerCAmelCase	,  unk_token=_lowerCAmelCase	,  sep_token=_lowerCAmelCase	,  pad_token=_lowerCAmelCase	,  cls_token=_lowerCAmelCase	,  mask_token=_lowerCAmelCase	,  vocab_file=_lowerCAmelCase	,  encoding=_lowerCAmelCase	,  sp_model_kwargs=self.sp_model_kwargs	,  **_lowerCAmelCase	,  )
										lowerCamelCase__       =       do_lower_case
										lowerCamelCase__       =       sentencepiece_model_ckpt
										lowerCamelCase__       =       spm.SentencePieceProcessor(**self.sp_model_kwargs	)
										self.sp_model.Load(_lowerCAmelCase	)

										# to mimic paddlenlp.transformers.ernie_m.tokenizer.ErnieMTokenizer functioning
										if vocab_file is not None:
															lowerCamelCase__       =       self.load_vocab(filepath=_lowerCAmelCase	)
										else:
															lowerCamelCase__       =       {self.sp_model.id_to_piece(_lowerCAmelCase	): id for id in range(self.sp_model.get_piece_size()	)}
										lowerCamelCase__       =       {v: k for k, v in self.vocab.items()}





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										if text is None:
															return None

										lowerCamelCase__       =       self.tokenize(_lowerCAmelCase	)
										lowerCamelCase__    ,		lowerCamelCase__       =       "", []

										for i, ch in enumerate(_lowerCAmelCase	):
															if ch in self.SP_CHAR_MAPPING:
																				lowerCamelCase__       =       self.SP_CHAR_MAPPING.get(_lowerCAmelCase	)
															else:
																				lowerCamelCase__       =       unicodedata.normalize("NFKC"	,  _lowerCAmelCase	)
															if self.is_whitespace(_lowerCAmelCase	):
																				continue
															normalized_text += ch
															char_mapping.extend([i] * len(_lowerCAmelCase	)	)

										lowerCamelCase__    ,		lowerCamelCase__    ,		lowerCamelCase__       =       normalized_text, [], 0

										if self.do_lower_case:
															lowerCamelCase__       =       text.lower()

										for token in split_tokens:
															if token[:1] == "▁":
																				lowerCamelCase__       =       token[1:]
															lowerCamelCase__       =       text[offset:].index(_lowerCAmelCase	) + offset
															lowerCamelCase__       =       start + len(_lowerCAmelCase	)

															token_mapping.append((char_mapping[start], char_mapping[end - 1] + 1)	)
															lowerCamelCase__       =       end
										return token_mapping





					@property
					def 					__magic_name__ ( self	):
										return len(self.vocab	)





					def 					__magic_name__ ( self	):
										return dict(self.vocab	,  **self.added_tokens_encoder	)





					def __getstate__( self	):
										lowerCamelCase__       =       self.__dict__.copy()
										lowerCamelCase__       =       None
										return state





					def __setstate__( self	,  _lowerCAmelCase	):
										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.sentencepiece_model_ckpt	)





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										return "".join((self.SP_CHAR_MAPPING.get(_lowerCAmelCase	,  _lowerCAmelCase	) for c in text)	)





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase=False	,  _lowerCAmelCase=64	,  _lowerCAmelCase=0.1	):

										if self.sp_model_kwargs.get("enable_sampling"	) is True:
															lowerCamelCase__       =       True
										if self.sp_model_kwargs.get("alpha"	) is not None:
															lowerCamelCase__       =       self.sp_model_kwargs.get("alpha"	)
										if self.sp_model_kwargs.get("nbest_size"	) is not None:
															lowerCamelCase__       =       self.sp_model_kwargs.get("nbest_size"	)

										if not enable_sampling:
															lowerCamelCase__       =       self.sp_model.EncodeAsPieces(_lowerCAmelCase	)
										else:
															lowerCamelCase__       =       self.sp_model.SampleEncodeAsPieces(_lowerCAmelCase	,  _lowerCAmelCase	,  _lowerCAmelCase	)
										lowerCamelCase__       =       []
										for pi, piece in enumerate(_lowerCAmelCase	):
															if piece == SPIECE_UNDERLINE:
																				if not pieces[pi + 1].startswith(_lowerCAmelCase	) and pi != 0:
																									new_pieces.append(_lowerCAmelCase	)
																									continue
																				else:
																									continue
															lowerCamelCase__       =       0
															for i, chunk in enumerate(_lowerCAmelCase	):
																				if chunk == SPIECE_UNDERLINE:
																									continue
																				if self.is_ch_char(_lowerCAmelCase	) or self.is_punct(_lowerCAmelCase	):
																									if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																														new_pieces.append(piece[lst_i:i]	)
																									new_pieces.append(_lowerCAmelCase	)
																									lowerCamelCase__       =       i + 1
																				elif chunk.isdigit() and i > 0 and not piece[i - 1].isdigit():
																									if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																														new_pieces.append(piece[lst_i:i]	)
																									lowerCamelCase__       =       i
																				elif not chunk.isdigit() and i > 0 and piece[i - 1].isdigit():
																									if i > lst_i and piece[lst_i:i] != SPIECE_UNDERLINE:
																														new_pieces.append(piece[lst_i:i]	)
																									lowerCamelCase__       =       i
															if len(_lowerCAmelCase	) > lst_i:
																				new_pieces.append(piece[lst_i:]	)
										return new_pieces





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										lowerCamelCase__       =       "".join(_lowerCAmelCase	).replace(_lowerCAmelCase	,  " "	).strip()
										return out_string





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										lowerCamelCase__       =       self.convert_ids_to_tokens(_lowerCAmelCase	)
										lowerCamelCase__       =       "".join(_lowerCAmelCase	).replace(_lowerCAmelCase	,  " "	).strip()
										return out_string





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										return self.vocab.get(_lowerCAmelCase	,  self.vocab.get(self.unk_token	)	)





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										return self.reverse_vocab.get(_lowerCAmelCase	,  self.unk_token	)





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase=None	):
										if token_ids_a is None:
															return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
										lowerCamelCase__       =       [self.cls_token_id]
										lowerCamelCase__       =       [self.sep_token_id]
										return _cls + token_ids_a + _sep + _sep + token_ids_a + _sep





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase=None	):
										if offset_mapping_a is None:
															return [(0, 0)] + offset_mapping_a + [(0, 0)]

										return [(0, 0)] + offset_mapping_a + [(0, 0), (0, 0)] + offset_mapping_a + [(0, 0)]





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase=None	,  _lowerCAmelCase=False	):

										if already_has_special_tokens:
															if token_ids_a is not None:
																				raise ValueError(
																				    "You should not supply a second sequence if the provided sequence of "
																				    "ids is already formatted with special tokens for the model."	)
															return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

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





					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase = None	):
										# called when `add_special_tokens` is True, so align with `build_inputs_with_special_tokens` method
										if token_ids_a is None:
															# [CLS] X [SEP]
															return (len(_lowerCAmelCase	) + 2) * [0]

										# [CLS] A [SEP] [SEP] B [SEP]
										return [0] * (len(_lowerCAmelCase	) + 1) + [1] * (len(_lowerCAmelCase	) + 3)





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										if "\u4e00" <= char <= "\u9fff":
															return True
										return False





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										if ("a" <= char <= "z") or ("A" <= char <= "Z"):
															return True
										return False





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										if char in ",;:.?!~，；：。？！《》【】":
															return True
										return False





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										if char == " " or char == "\t" or char == "\n" or char == "\r":
															return True
										if len(_lowerCAmelCase	) == 1:
															lowerCamelCase__       =       unicodedata.category(_lowerCAmelCase	)
															if cat == "Zs":
																				return True
										return False





					def 					__magic_name__ ( self	,  _lowerCAmelCase	):
										lowerCamelCase__       =       {}
										with io.open(_lowerCAmelCase	,  "r"	,  encoding="utf-8"	) as f:
															for index, line in enumerate(_lowerCAmelCase	):
																				lowerCamelCase__       =       line.rstrip("\n"	)
																				lowerCamelCase__       =       int(_lowerCAmelCase	)

										return token_to_idx






					def 					__magic_name__ ( self	,  _lowerCAmelCase	,  _lowerCAmelCase = None	):
										lowerCamelCase__       =       0
										if os.path.isdir(_lowerCAmelCase	):
															lowerCamelCase__       =       os.path.join(
															    _lowerCAmelCase	,  (filename_prefix + "-" if filename_prefix else "") + VOCAB_FILES_NAMES["vocab_file"]	)
										else:
															lowerCamelCase__       =       (filename_prefix + "-" if filename_prefix else "") + save_directory
										with open(_lowerCAmelCase	,  "w"	,  encoding="utf-8"	) as writer:
															for token, token_index in sorted(self.vocab.items()	,  key=lambda _lowerCAmelCase	: kv[1]	):
																				if index != token_index:
																									logger.warning(
																									    F"Saving vocabulary to {vocab_file}: vocabulary indices are not consecutive."
																									    " Please check that the vocabulary is not corrupted!"	)
																									lowerCamelCase__       =       token_index
																				writer.write(token + "\n"	)
																				index += 1

										lowerCamelCase__       =       os.path.join(_lowerCAmelCase	,  "sentencepiece.bpe.model"	)
										with open(_lowerCAmelCase	,  "wb"	) as fi:
															lowerCamelCase__       =       self.sp_model.serialized_model_proto()
															fi.write(_lowerCAmelCase	)

										return (vocab_file,)








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





def    __UpperCamelCase      (    a,     a) ->Optional[int]:
					lowerCamelCase__       =       [[float("inf") for _ in range(a)] for _ in range(a)]

					for i in range(a):
										for j in range(a):
															lowerCamelCase__       =       graph[i][j]

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

					_print_dist(a,     a)
					return dist, v


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

						A_												=     [[float("inf") for i in range(v)] for j in range(v)]

						for i in range(v):
												A_												=     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)
												A_												=     int(input("Enter source:"))
												A_												=     int(input("Enter destination:"))
												A_												=     float(input("Enter weight:"))
												A_												=     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

