
'''simple docstring'''







from __future__ import annotations

from collections import deque


class 		__UpperCAmelCase   :


							def __init__( self					,     lowerCAmelCase_						):





								"""simple docstring"""






								_snake_case     		=	[]
								self.adlist.append(
								    {'value': '', 'next_states': [], 'fail_state': 0, 'output': []}						)

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


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_					,     lowerCAmelCase_						):





								"""simple docstring"""






								for state in self.adlist[current_state]["next_states"]:
									if char == self.adlist[state]["value"]:
										return state
								return None


							def 				lowerCamelCase       ( self					,     lowerCAmelCase_						):





								"""simple docstring"""






								_snake_case     		=	0
								for character in keyword:
									_snake_case     		=	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						)
										_snake_case     		=	len(self.adlist						) - 1
									else:
										_snake_case     		=	next_state
								self.adlist[current_state]["output"].append(lowerCAmelCase_						)


							def 				lowerCamelCase       ( self						):





								"""simple docstring"""






								_snake_case     		=	deque()
								for node in self.adlist[0]["next_states"]:
									q.append(lowerCAmelCase_						)
									_snake_case     		=	0
								while q:
									_snake_case     		=	q.popleft()
									for child in self.adlist[r]["next_states"]:
										q.append(lowerCAmelCase_						)
										_snake_case     		=	self.adlist[r]['fail_state']
										while (
										    self.find_next_state(lowerCAmelCase_					,     self.adlist[child]['value']						) is None
										    and state != 0
										):
											_snake_case     		=	self.adlist[state]['fail_state']
										_snake_case     		=	self.find_next_state(
										    lowerCAmelCase_					,     self.adlist[child]['value']						)
										if self.adlist[child]["fail_state"] is None:
											_snake_case     		=	0
										_snake_case     		=	(
										    self.adlist[child]['output']
										    + self.adlist[self.adlist[child]['fail_state']]['output']
										)




							def 				lowerCamelCase       ( self					,     lowerCAmelCase_						):





								"""simple docstring"""






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


if __name__ == "__main__":
					import doctest

					doctest.testmod()



'''simple docstring'''







from typing import TYPE_CHECKING

from ...utils import OptionalDependencyNotAvailable, _LazyModule, is_tokenizers_available, is_torch_available


lowercase					:							str   =      {
    "configuration_nezha": ["NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP", "NezhaConfig"],
}

try:
					if not is_torch_available():
										raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
					pass
else:
					lowercase					:							Any   =      [
					    "NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST",
					    "NezhaForNextSentencePrediction",
					    "NezhaForMaskedLM",
					    "NezhaForPreTraining",
					    "NezhaForMultipleChoice",
					    "NezhaForQuestionAnswering",
					    "NezhaForSequenceClassification",
					    "NezhaForTokenClassification",
					    "NezhaModel",
					    "NezhaPreTrainedModel",
					]


if TYPE_CHECKING:
					from .configuration_nezha import NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP, NezhaConfig

					try:
										if not is_torch_available():
															raise OptionalDependencyNotAvailable()
					except OptionalDependencyNotAvailable:
										pass
					else:
										from .modeling_nezha import (
										    NEZHA_PRETRAINED_MODEL_ARCHIVE_LIST,
										    NezhaForMaskedLM,
										    NezhaForMultipleChoice,
										    NezhaForNextSentencePrediction,
										    NezhaForPreTraining,
										    NezhaForQuestionAnswering,
										    NezhaForSequenceClassification,
										    NezhaForTokenClassification,
										    NezhaModel,
										    NezhaPreTrainedModel,
										)


else:
					import sys

					lowercase					:							Union[str, Any]   =      _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)

