

from __future__ import annotations

from collections import deque






class _UpperCamelCase							:
			'''simple docstring'''







			def __init__(	self							:       int					,					a							:       list[str]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					list[dict]    =				[]
				self.adlist.append(
				    {"value": "", "next_states": [], "fail_state": 0, "output": []}		)

				for keyword in keywords:
					self.add_keyword(a		)
				self.set_fail_transitions()
			def 							__UpperCamelCase       (	self							:       Tuple					,					a							:       int					,					a							:       str		)							->				int | None:

				"""simple docstring"""

				for state in self.adlist[current_state]["next_states"]:
					if char == self.adlist[state]["value"]:
						return state
				return None
			def 							__UpperCamelCase       (	self							:       List[str]					,					a							:       str		)							->				None:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				0
				for character in keyword:
					SCREAMING_SNAKE_CASE      :					Optional[int]    =				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		)
						SCREAMING_SNAKE_CASE      :					int    =				len(self.adlist		) - 1
					else:
						SCREAMING_SNAKE_CASE      :					Dict    =				next_state
				self.adlist[current_state]["output"].append(a		)
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				None:

				"""simple docstring"""

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






			def 							__UpperCamelCase       (	self							:       Optional[Any]					,					a							:       str		)							->				dict[str, list[int]]:

				"""simple docstring"""

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


if __name__ == "__main__":
			import doctest

			doctest.testmod()





import itertools
from dataclasses import dataclass
from typing import Optional

import pandas as pd
import pyarrow as pa

import datasets
from datasets.table import table_cast




@dataclass
class       __lowerCAmelCase				(							datasets.BuilderConfig):
       _a           =  None







class       __lowerCAmelCase				(							datasets.ArrowBasedBuilder):
       _a           =  PandasConfig






       def     SCREAMING_SNAKE_CASE			(      self:    Any ):
         return datasets.DatasetInfo(features=self.config.features )






       def     SCREAMING_SNAKE_CASE			(      self:    str				,    _lowerCAmelCase:    List[str] ):
         if not self.config.data_files:
           raise ValueError(F"At least one data file must be specified, but got data_files={self.config.data_files}" )
         lowercase			:int							=  dl_manager.download_and_extract(self.config.data_files )
         if isinstance(_lowerCAmelCase				,    (str, list, tuple) ):
           lowercase			:Union[str, Any]							=  data_files
           if isinstance(_lowerCAmelCase				,    _lowerCAmelCase ):
             lowercase			:str							=  [files]
           # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
           lowercase			:Optional[int]							=  [dl_manager.iter_files(_lowerCAmelCase ) for file in files]
           return [datasets.SplitGenerator(name=datasets.Split.TRAIN				,    gen_kwargs={"files": files} )]
         lowercase			:List[Any]							=  []
         for split_name, files in data_files.items():
           if isinstance(_lowerCAmelCase				,    _lowerCAmelCase ):
             lowercase			:Optional[Any]							=  [files]
           # Use `dl_manager.iter_files` to skip hidden files in an extracted archive
           lowercase			:Optional[Any]							=  [dl_manager.iter_files(_lowerCAmelCase ) for file in files]
           splits.append(datasets.SplitGenerator(name=_lowerCAmelCase				,    gen_kwargs={"files": files} ) )
         return splits






       def     SCREAMING_SNAKE_CASE			(      self:    int				,    _lowerCAmelCase:    pa.Table ):
         if self.config.features is not None:
           # more expensive cast to support nested features with keys in a different order
           # allows str <-> int/float or str to Audio for example
           lowercase			:Any							=  table_cast(_lowerCAmelCase				,    self.config.features.arrow_schema )
         return pa_table






       def     SCREAMING_SNAKE_CASE			(      self:    Optional[int]				,    _lowerCAmelCase:    Union[str, Any] ):
         for i, file in enumerate(itertools.chain.from_iterable(_lowerCAmelCase ) ):
           with open(_lowerCAmelCase				,    "rb" ) as f:
             lowercase			:int							=  pa.Table.from_pandas(pd.read_pickle(_lowerCAmelCase ) )
             yield i, self._cast_table(_lowerCAmelCase )



