




from __future__ import annotations

from collections import deque





class     SCREAMING_SNAKE_CASE__		:
     def __init__(						self	:		Dict       ,						__lowerCamelCase	:		list[str]						):



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

       for keyword in keywords:
         self.add_keyword(__lowerCamelCase						)
       self.set_fail_transitions()
     def        A__      (						self	:		List[Any]       ,						__lowerCamelCase	:		int       ,						__lowerCamelCase	:		str						):



       """simple docstring"""
       for state in self.adlist[current_state]["next_states"]:
         if char == self.adlist[state]["value"]:
           return state
       return None
     def        A__      (						self	:		List[Any]       ,						__lowerCamelCase	:		str						):



       """simple docstring"""
       lowerCAmelCase__										=      0
       for character in keyword:
         lowerCAmelCase__										=      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__										=      len(self.adlist						) - 1
         else:
           lowerCAmelCase__										=      next_state
       self.adlist[current_state]["output"].append(__lowerCamelCase						)
     def        A__      (						self	:		Any						):



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



     def        A__      (						self	:		List[str]       ,						__lowerCamelCase	:		str						):



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


if __name__ == "__main__":
      import doctest

      doctest.testmod()







from typing import TYPE_CHECKING

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


__magic_name__  :  Union[str, Any]					=       {
    """configuration_altclip""": [
        """ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP""",
        """AltCLIPConfig""",
        """AltCLIPTextConfig""",
        """AltCLIPVisionConfig""",
    ],
    """processing_altclip""": ["""AltCLIPProcessor"""],
}

try:
      if not is_torch_available():
            raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
      pass
else:
      __magic_name__  :  str					=       [
          """ALTCLIP_PRETRAINED_MODEL_ARCHIVE_LIST""",
          """AltCLIPPreTrainedModel""",
          """AltCLIPModel""",
          """AltCLIPTextModel""",
          """AltCLIPVisionModel""",
      ]


if TYPE_CHECKING:
      from .configuration_altclip import (
          ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP,
          AltCLIPConfig,
          AltCLIPTextConfig,
          AltCLIPVisionConfig,
      )
      from .processing_altclip import AltCLIPProcessor

      try:
            if not is_torch_available():
                  raise OptionalDependencyNotAvailable()
      except OptionalDependencyNotAvailable:
            pass
      else:
            from .modeling_altclip import (
                ALTCLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
                AltCLIPModel,
                AltCLIPPreTrainedModel,
                AltCLIPTextModel,
                AltCLIPVisionModel,
            )


else:
      import sys

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

