



from __future__ import annotations

from collections import deque


class 	lowerCamelCase__	:



 """simple docstring"""

 def __init__(    self					:					int			,						__lowerCAmelCase					:					list[str]      )   ->	Union[str, Any]:
    _A      =       []
    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					:					Dict			,						__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					:					str			,						__lowerCAmelCase					:					str      )   ->	None:
    _A      =       0
    for character in keyword:
       _A      =       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      =       len(self.adlist      ) - 1
       else:
          _A      =       next_state
    self.adlist[current_state]["output"].append(__lowerCAmelCase      )

 def     snake_case_      (    self					:					List[Any]      )   ->	None:
    _A      =       deque()
    for node in self.adlist[0]["next_states"]:
       q.append(__lowerCAmelCase      )
       _A      =       0
    while q:
       _A      =       q.popleft()
       for child in self.adlist[r]["next_states"]:
          q.append(__lowerCAmelCase      )
          _A      =       self.adlist[r]['''fail_state''']
          while (
              self.find_next_state(__lowerCAmelCase			,						self.adlist[child]['''value''']      ) is None
              and state != 0
          ):
             _A      =       self.adlist[state]['''fail_state''']
          _A      =       self.find_next_state(
              __lowerCAmelCase			,						self.adlist[child]['''value''']      )
          if self.adlist[child]["fail_state"] is None:
             _A      =       0
          _A      =       (
              self.adlist[child]['''output''']
              + self.adlist[self.adlist[child]['''fail_state''']]['''output''']
          )

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


if __name__ == "__main__":
   import doctest

   doctest.testmod()








from .configuration_bert_masked import MaskedBertConfig
from .modeling_bert_masked import (
    MaskedBertForMultipleChoice,
    MaskedBertForQuestionAnswering,
    MaskedBertForSequenceClassification,
    MaskedBertForTokenClassification,
    MaskedBertModel,
)
from .modules import *



