


"""simple docstring"""




from __future__ import annotations

from collections import deque





class __snake_case		:







   """simple docstring"""




   def __init__(		self				:List[str]					,	UpperCamelCase__				:Tuple							):
          _a							 =					[]
          self.adlist.append(
              {"value": "", "next_states": [], "fail_state": 0, "output": []}							)

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




   def SCREAMING_SNAKE_CASE_   (		self				:Optional[int]					,	UpperCamelCase__				:Optional[Any]					,	UpperCamelCase__				:int							):
          for state in self.adlist[current_state]["next_states"]:
                 if char == self.adlist[state]["value"]:
                        return state
          return None




   def SCREAMING_SNAKE_CASE_   (		self				:Union[str, Any]					,	UpperCamelCase__				:Union[str, Any]							):
          _a							 =					0
          for character in keyword:
                 _a							 =					self.find_next_state(__UpperCAmelCase					,	__UpperCAmelCase							)
                 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(__UpperCAmelCase							)




   def SCREAMING_SNAKE_CASE_   (		self				:Union[str, Any]							):
          _a							 =					deque()
          for node in self.adlist[0]["next_states"]:
                 q.append(__UpperCAmelCase							)
                 _a							 =					0
          while q:
                 _a							 =					q.popleft()
                 for child in self.adlist[r]["next_states"]:
                        q.append(__UpperCAmelCase							)
                        _a							 =					self.adlist[r]["fail_state"]
                        while (
                            self.find_next_state(__UpperCAmelCase					,	self.adlist[child]["value"]							) is None
                            and state != 0
                        ):
                               _a							 =					self.adlist[state]["fail_state"]
                        _a							 =					self.find_next_state(
                            __UpperCAmelCase					,	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 SCREAMING_SNAKE_CASE_   (		self				:List[str]					,	UpperCamelCase__				:str							):
          _a							 =					{}  # returns a dict with keywords and list of its occurrences
          _a							 =					0
          for i in range(len(__UpperCAmelCase							)							):
                 while (
                     self.find_next_state(__UpperCAmelCase					,	string[i]							) is None
                     and current_state != 0
                 ):
                        _a							 =					self.adlist[current_state]["fail_state"]
                 _a							 =					self.find_next_state(__UpperCAmelCase					,	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(__UpperCAmelCase							) + 1							)
          return result


if __name__ == "__main__":
   import doctest

   doctest.testmod()





from typing import Callable, Optional

from .. import Features
from ..packaged_modules.generator.generator import Generator
from .abc import AbstractDatasetInputStream



class 			__lowerCAmelCase  (						lowerCAmelCase__ ):




 def __init__(    self						,					__UpperCAmelCase						,					__UpperCAmelCase = None						,					__UpperCAmelCase = None						,					__UpperCAmelCase = False						,					__UpperCAmelCase = False						,					__UpperCAmelCase = None						,					__UpperCAmelCase = None						,					**__UpperCAmelCase						,					):



    '''simple docstring'''
    super().__init__(
        features=__UpperCAmelCase						,					cache_dir=__UpperCAmelCase						,					keep_in_memory=__UpperCAmelCase						,					streaming=__UpperCAmelCase						,					num_proc=__UpperCAmelCase						,					**__UpperCAmelCase						,					)
    __lowerCamelCase    				=     Generator(
        cache_dir=__UpperCAmelCase						,					features=__UpperCAmelCase						,					generator=__UpperCAmelCase						,					gen_kwargs=__UpperCAmelCase						,					**__UpperCAmelCase						,					)




 def 							lowerCamelCase   (    self					):



    '''simple docstring'''
    # Build iterable dataset
    if self.streaming:
       __lowerCamelCase    				=     self.builder.as_streaming_dataset(split='''train'''					)
    # Build regular (map-style) dataset
    else:
       __lowerCamelCase    				=     None
       __lowerCamelCase    				=     None
       __lowerCamelCase    				=     None
       __lowerCamelCase    				=     None

       self.builder.download_and_prepare(
           download_config=__UpperCAmelCase						,					download_mode=__UpperCAmelCase						,					verification_mode=__UpperCAmelCase						,					base_path=__UpperCAmelCase						,					num_proc=self.num_proc						,					)
       __lowerCamelCase    				=     self.builder.as_dataset(
           split='''train'''						,					verification_mode=__UpperCAmelCase						,					in_memory=self.keep_in_memory					)
    return dataset






