



"""simple docstring"""






from __future__ import annotations

from collections import deque

class  __SCREAMING_SNAKE_CASE			:


					'''simple docstring'''





					def __init__( self							:						Optional[Any],						lowerCamelCase							:						list[str]  )->      List[Any]:
								lowerCamelCase__	:	list[dict]				=[]
								self.adlist.append(
								    {'''value''': '''''', '''next_states''': [], '''fail_state''': 0, '''output''': []}  )

								for keyword in keywords:
											self.add_keyword(lowerCamelCase  )
								self.set_fail_transitions()



					def 	snake_case ( self							:						Any,						lowerCamelCase							:						int,						lowerCamelCase							:						str  )->      int | None:
								for state in self.adlist[current_state]["next_states"]:
											if char == self.adlist[state]["value"]:
														return state
								return None



					def 	snake_case ( self							:						Tuple,						lowerCamelCase							:						str  )->      None:
								lowerCamelCase__	:	str				=0
								for character in keyword:
											lowerCamelCase__	:	str				=self.find_next_state(lowerCamelCase,						lowerCamelCase  )
											if next_state is None:
														self.adlist.append(
														    {
														        '''value''': character,
														        '''next_states''': [],
														        '''fail_state''': 0,
														        '''output''': [],
														    }  )
														self.adlist[current_state]["next_states"].append(len(self.adlist  ) - 1  )
														lowerCamelCase__	:	Tuple				=len(self.adlist  ) - 1
											else:
														lowerCamelCase__	:	Union[str, Any]				=next_state
								self.adlist[current_state]["output"].append(lowerCamelCase  )



					def 	snake_case ( self							:						Dict  )->      None:
								lowerCamelCase__	:	deque				=deque()
								for node in self.adlist[0]["next_states"]:
											q.append(lowerCamelCase  )
											lowerCamelCase__	:	Dict				=0
								while q:
											lowerCamelCase__	:	Tuple				=q.popleft()
											for child in self.adlist[r]["next_states"]:
														q.append(lowerCamelCase  )
														lowerCamelCase__	:	Tuple				=self.adlist[r]['''fail_state''']
														while (
														    self.find_next_state(lowerCamelCase,						self.adlist[child]['''value''']  ) is None
														    and state != 0
														):
																	lowerCamelCase__	:	List[str]				=self.adlist[state]['''fail_state''']
														lowerCamelCase__	:	Optional[Any]				=self.find_next_state(
														    lowerCamelCase,						self.adlist[child]['''value''']  )
														if self.adlist[child]["fail_state"] is None:
																	lowerCamelCase__	:	Dict				=0
														lowerCamelCase__	:	Optional[int]				=(
														    self.adlist[child]['''output''']
														    + self.adlist[self.adlist[child]['''fail_state''']]['''output''']
														)




					def 	snake_case ( self							:						Any,						lowerCamelCase							:						str  )->      dict[str, list[int]]:
								lowerCamelCase__	:	dict				={}  # returns a dict with keywords and list of its occurrences
								lowerCamelCase__	:	int				=0
								for i in range(len(lowerCamelCase  )  ):
											while (
											    self.find_next_state(lowerCamelCase,						string[i]  ) is None
											    and current_state != 0
											):
														lowerCamelCase__	:	Optional[Any]				=self.adlist[current_state]['''fail_state''']
											lowerCamelCase__	:	int				=self.find_next_state(lowerCamelCase,						string[i]  )
											if next_state is None:
														lowerCamelCase__	:	List[str]				=0
											else:
														lowerCamelCase__	:	int				=next_state
														for key in self.adlist[current_state]["output"]:
																	if key not in result:
																				lowerCamelCase__	:	Optional[Any]				=[]
																	result[key].append(i - len(lowerCamelCase  ) + 1  )
								return result


if __name__ == "__main__":
		import doctest

		doctest.testmod()









"""simple docstring"""






from ..utils import DummyObject, requires_backends

class  __SCREAMING_SNAKE_CASE			(   metaclass=lowerCAmelCase_     ):


					'''simple docstring'''





					_a         =							['onnx']



					def __init__( self							:						List[str],						*lowerCamelCase							:						Union[str, Any],						**lowerCamelCase							:						str  )->      Optional[int]:
								requires_backends(self,						['''onnx''']  )



					@classmethod
					def 	snake_case ( cls							:						List[str],						*lowerCamelCase							:						Any,						**lowerCamelCase							:						Union[str, Any]  )->      Optional[int]:
								requires_backends(cls,						['''onnx''']  )




					@classmethod
					def 	snake_case ( cls							:						Union[str, Any],						*lowerCamelCase							:						Tuple,						**lowerCamelCase							:						Tuple  )->      Optional[int]:
								requires_backends(cls,						['''onnx''']  )




