




from __future__ import annotations

from collections import deque




class 					snake_case__							:
				"""simple docstring"""



				def __init__(   self       :  Any      ,   __lowerCamelCase       :  list[str]							)      ->  Optional[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 							__UpperCAmelCase							(   self       :  Optional[Any]      ,   __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 							__UpperCAmelCase							(   self       :  List[Any]      ,   __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 							__UpperCAmelCase							(   self       :  int							)      ->  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 							__UpperCAmelCase							(   self       :  Any      ,   __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 typing import TYPE_CHECKING

from ...utils import (
    OptionalDependencyNotAvailable,
    _LazyModule,
    is_tf_available,
    is_torch_available,
    is_vision_available,
)


__lowerCAmelCase	:       Dict     =	{
    'configuration_blip': [
        'BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP',
        'BlipConfig',
        'BlipTextConfig',
        'BlipVisionConfig',
    ],
    'processing_blip': ['BlipProcessor'],
}

try:
		if not is_vision_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase	:       Optional[Any]     =	['BlipImageProcessor']


try:
		if not is_torch_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase	:       List[Any]     =	[
		    'BLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'BlipModel',
		    'BlipPreTrainedModel',
		    'BlipForConditionalGeneration',
		    'BlipForQuestionAnswering',
		    'BlipVisionModel',
		    'BlipTextModel',
		    'BlipForImageTextRetrieval',
		]

try:
		if not is_tf_available():
				raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
		pass
else:
		__lowerCAmelCase	:       Any     =	[
		    'TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST',
		    'TFBlipModel',
		    'TFBlipPreTrainedModel',
		    'TFBlipForConditionalGeneration',
		    'TFBlipForQuestionAnswering',
		    'TFBlipVisionModel',
		    'TFBlipTextModel',
		    'TFBlipForImageTextRetrieval',
		]

if TYPE_CHECKING:
		from .configuration_blip import BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP, BlipConfig, BlipTextConfig, BlipVisionConfig
		from .processing_blip import BlipProcessor

		try:
				if not is_vision_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .image_processing_blip import BlipImageProcessor

		try:
				if not is_torch_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_blip import (
				    BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    BlipForConditionalGeneration,
				    BlipForImageTextRetrieval,
				    BlipForQuestionAnswering,
				    BlipModel,
				    BlipPreTrainedModel,
				    BlipTextModel,
				    BlipVisionModel,
				)

		try:
				if not is_tf_available():
						raise OptionalDependencyNotAvailable()
		except OptionalDependencyNotAvailable:
				pass
		else:
				from .modeling_tf_blip import (
				    TF_BLIP_PRETRAINED_MODEL_ARCHIVE_LIST,
				    TFBlipForConditionalGeneration,
				    TFBlipForImageTextRetrieval,
				    TFBlipForQuestionAnswering,
				    TFBlipModel,
				    TFBlipPreTrainedModel,
				    TFBlipTextModel,
				    TFBlipVisionModel,
				)

else:
		import sys

		__lowerCAmelCase	:       List[str]     =	_LazyModule(__name__, globals()['__file__'], _import_structure, module_spec=__spec__)






