


'''simple docstring'''






from __future__ import annotations

from collections import deque






class  __magic_name__							:






       def __init__(      self  ,							snake_case)						->  Union[str, Any]:




          '''simple docstring'''
          _UpperCAmelCase       :       list[dict]							   =[]
          self.adlist.append(
              {'value': '', 'next_states': [], 'fail_state': 0, 'output': []})

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






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case)						->  int | None:




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






       def       lowerCAmelCase		(      self  ,							snake_case)						->  None:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =0
          for character in keyword:
             _UpperCAmelCase       :       Optional[Any]							   =self.find_next_state(snake_case  ,							snake_case)
             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)
                _UpperCAmelCase       :       Optional[int]							   =len(self.adlist) - 1
             else:
                _UpperCAmelCase       :       List[Any]							   =next_state
          self.adlist[current_state]["output"].append(snake_case)






       def       lowerCAmelCase		(      self)						->  None:




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






       def       lowerCAmelCase		(      self  ,							snake_case)						->  dict[str, list[int]]:




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


if __name__ == "__main__":
 import doctest

 doctest.testmod()





'''simple docstring'''






from typing import TYPE_CHECKING

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


lowercase							={
    'configuration_groupvit': [
        'GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'GroupViTConfig',
        'GroupViTOnnxConfig',
        'GroupViTTextConfig',
        'GroupViTVisionConfig',
    ],
}

try:
 if not is_torch_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowercase							=[
     'GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'GroupViTModel',
     'GroupViTPreTrainedModel',
     'GroupViTTextModel',
     'GroupViTVisionModel',
 ]

try:
 if not is_tf_available():
  raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
 pass
else:
 lowercase							=[
     'TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST',
     'TFGroupViTModel',
     'TFGroupViTPreTrainedModel',
     'TFGroupViTTextModel',
     'TFGroupViTVisionModel',
 ]

if TYPE_CHECKING:
 from .configuration_groupvit import (
     GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP,
     GroupViTConfig,
     GroupViTOnnxConfig,
     GroupViTTextConfig,
     GroupViTVisionConfig,
 )

 try:
  if not is_torch_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_groupvit import (
      GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      GroupViTModel,
      GroupViTPreTrainedModel,
      GroupViTTextModel,
      GroupViTVisionModel,
  )

 try:
  if not is_tf_available():
   raise OptionalDependencyNotAvailable()
 except OptionalDependencyNotAvailable:
  pass
 else:
  from .modeling_tf_groupvit import (
      TF_GROUPVIT_PRETRAINED_MODEL_ARCHIVE_LIST,
      TFGroupViTModel,
      TFGroupViTPreTrainedModel,
      TFGroupViTTextModel,
      TFGroupViTVisionModel,
  )

else:
 import sys

 lowercase							=_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)

