





from __future__ import annotations

from collections import deque






class        snake_case_    :






  def __init__(							self			:					int       ,  _snake_case			:					list[str]      )->Optional[int]:






   '''simple docstring'''

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

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






  def 				UpperCAmelCase__						(							self			:					Dict       ,  _snake_case			:					int       ,  _snake_case			:					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			:					Dict       ,  _snake_case			:					str      )->None:






   '''simple docstring'''

   __lowerCAmelCase					:	Union[str, Any]      =       0
   for character in keyword:
    __lowerCAmelCase					:	int      =       self.find_next_state(_snake_case       ,  _snake_case      )
    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      )
     __lowerCAmelCase					:	Optional[Any]      =       len(self.adlist      ) - 1
    else:
     __lowerCAmelCase					:	int      =       next_state
   self.adlist[current_state]["output"].append(_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Optional[Any]      )->None:






   '''simple docstring'''

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






  def 				UpperCAmelCase__						(							self			:					int       ,  _snake_case			:					str      )->dict[str, list[int]]:






   '''simple docstring'''

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


if __name__ == "__main__":
      import doctest

      doctest.testmod()






import warnings

from ...processing_utils import ProcessorMixin
from ...tokenization_utils_base import BatchEncoding






class        snake_case_    (		__lowercase						):
  A_      							=   ['image_processor', 'tokenizer']
  A_      							=   'ChineseCLIPImageProcessor'
  A_      							=   ('BertTokenizer', 'BertTokenizerFast')






  def __init__(							self			:					Optional[Any]       ,  _snake_case			:					List[Any]=None       ,  _snake_case			:					str=None       ,  **_snake_case			:					int      )->List[str]:






   '''simple docstring'''

   __lowerCAmelCase					:	str      =       None
   if "feature_extractor" in kwargs:
    warnings.warn(
        """The `feature_extractor` argument is deprecated and will be removed in v5, use `image_processor`"""
        """ instead."""       ,  _snake_case       ,  )
    __lowerCAmelCase					:	List[str]      =       kwargs.pop("""feature_extractor"""      )

   __lowerCAmelCase					:	Union[str, Any]      =       image_processor if image_processor is not None else feature_extractor
   if image_processor is None:
    raise ValueError("""You need to specify an `image_processor`."""      )
   if tokenizer is None:
    raise ValueError("""You need to specify a `tokenizer`."""      )

   super().__init__(_snake_case       ,  _snake_case      )
   __lowerCAmelCase					:	Any      =       self.image_processor






  def __call__(							self			:					Optional[Any]       ,  _snake_case			:					Tuple=None       ,  _snake_case			:					Tuple=None       ,  _snake_case			:					List[str]=None       ,  **_snake_case			:					Any      )->Union[str, Any]:






   '''simple docstring'''

   if text is None and images is None:
    raise ValueError("""You have to specify either text or images. Both cannot be none."""      )

   if text is not None:
    __lowerCAmelCase					:	List[Any]      =       self.tokenizer(_snake_case       ,  return_tensors=_snake_case       ,  **_snake_case      )

   if images is not None:
    __lowerCAmelCase					:	Tuple      =       self.image_processor(_snake_case       ,  return_tensors=_snake_case       ,  **_snake_case      )

   if text is not None and images is not None:
    __lowerCAmelCase					:	Optional[Any]      =       image_features.pixel_values
    return encoding
   elif text is not None:
    return encoding
   else:
    return BatchEncoding(data=dict(**_snake_case      )       ,  tensor_type=_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Optional[int]       ,  *_snake_case			:					Union[str, Any]       ,  **_snake_case			:					int      )->Optional[Any]:






   '''simple docstring'''

   return self.tokenizer.batch_decode(*_snake_case       ,  **_snake_case      )






  def 				UpperCAmelCase__						(							self			:					Dict       ,  *_snake_case			:					Dict       ,  **_snake_case			:					Any      )->Dict:






   '''simple docstring'''

   return self.tokenizer.decode(*_snake_case       ,  **_snake_case      )






  @property
  def 				UpperCAmelCase__						(							self			:					Optional[int]      )->str:






   '''simple docstring'''

   __lowerCAmelCase					:	Tuple      =       self.tokenizer.model_input_names
   __lowerCAmelCase					:	Tuple      =       self.image_processor.model_input_names
   return list(dict.fromkeys(tokenizer_input_names + image_processor_input_names      )      )






  @property
  def 				UpperCAmelCase__						(							self			:					Dict      )->Union[str, Any]:






   '''simple docstring'''

   warnings.warn(
       """`feature_extractor_class` is deprecated and will be removed in v5. Use `image_processor_class` instead."""       ,  _snake_case       ,  )
   return self.image_processor_class