





"""simple docstring"""






from __future__ import annotations

from collections import deque



class 	lowerCAmelCase					:






       def __init__(   self    ,  a__     ):
              _UpperCAmelCase     =     []
              self.adlist.append(
                  {'value': '', 'next_states': [], 'fail_state': 0, 'output': []}     )

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






       def 							__A (   self    ,  a__    ,  a__     ):
              for state in self.adlist[current_state]["next_states"]:
                     if char == self.adlist[state]["value"]:
                            return state
              return None






       def 							__A (   self    ,  a__     ):
              _UpperCAmelCase     =     0
              for character in keyword:
                     _UpperCAmelCase     =     self.find_next_state(a__    ,  a__     )
                     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     =     len(self.adlist     ) - 1
                     else:
                            _UpperCAmelCase     =     next_state
              self.adlist[current_state]["output"].append(a__     )






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






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


if __name__ == "__main__":
    import doctest

    doctest.testmod()













"""simple docstring"""






from datetime import datetime

import matplotlib.pyplot as plt
import torch

def       __lowerCamelCase    (       SCREAMING_SNAKE_CASE							)		->       Any:






       """simple docstring"""




       for param in module.parameters():
              _UpperCAmelCase     =     False

def       __lowerCamelCase    (       )		->       Dict:






       """simple docstring"""




       _UpperCAmelCase     =     'cuda' if torch.cuda.is_available() else 'cpu'
       if torch.backends.mps.is_available() and torch.backends.mps.is_built():
              _UpperCAmelCase     =     'mps'
       if device == "mps":
              print(
                  'WARNING: MPS currently doesn\'t seem to work, and messes up backpropagation without any visible torch'
                  ' errors. I recommend using CUDA on a colab notebook or CPU instead if you\'re facing inexplicable issues'
                  ' with generations.'							)
       return device

def       __lowerCamelCase    (       SCREAMING_SNAKE_CASE							)		->       str:






       """simple docstring"""




       _UpperCAmelCase     =     plt.imshow(SCREAMING_SNAKE_CASE							)
       fig.axes.get_xaxis().set_visible(SCREAMING_SNAKE_CASE							)
       fig.axes.get_yaxis().set_visible(SCREAMING_SNAKE_CASE							)
       plt.show()


def       __lowerCamelCase    (       )		->       Dict:






       """simple docstring"""




       _UpperCAmelCase     =     datetime.now()
       _UpperCAmelCase     =     current_time.strftime('%H:%M:%S'							)
       return timestamp






