
'''simple docstring'''

from __future__ import annotations

from collections import deque


class  _UpperCAmelCase :

     """simple docstring"""

     def __init__(      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

       a_      :	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 							_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'''

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


     def 							_lowerCAmelCase  (      self ):

       '''simple docstring'''

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






     def 							_lowerCAmelCase  (      self							,		lowerCAmelCase_ ):

       '''simple docstring'''

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


if __name__ == "__main__":
    import doctest

    doctest.testmod()




'''simple docstring'''

from dataclasses import dataclass
from enum import Enum
from typing import List, Optional, Union

import numpy as np
import PIL
from PIL import Image

from ...utils import BaseOutput, is_torch_available, is_transformers_available


@dataclass
class  _UpperCAmelCase ( lowerCAmelCase__    ):

     """simple docstring"""

     a_    	=					42
     a_    	=					42


if is_transformers_available() and is_torch_available():
    from .pipeline_semantic_stable_diffusion import SemanticStableDiffusionPipeline


