class_docstr: Adds message features based on regex expressions.
class_docstr_tok: ["Adds","message","features","based","on","regex","expressions","."]
docstr: Checks which known patterns match the message.
  
  Given a sentence, returns a vector of {1,0} values indicating which
  regexes did match. Furthermore, if the
  message is tokenized, the function will mark all tokens with a dict
  relating the name of the regex to whether it was matched.
  
  Args:
      message: Message to be featurized.
      attribute: Attribute of message to be featurized.
  
  Returns:
     Token and sentence level features of message attribute.
docstr_tok: ["Checks","which","known","patterns","match","the","message",".","Given","a","sentence",",","returns","a","vector","of","{","1,0","}","values","indicating","which","regexes","did","match",".","Furthermore",",","if","the","message","is","tokenized",",","the","function","will","mark","all","tokens","with","a","dict","relating","the","name","of","the","regex","to","whether","it","was","matched",".","Args",":","message",":","Message","to","be","featurized",".","attribute",":","Attribute","of","message","to","be","featurized",".","Returns",":","Token","and","sentence","level","features","of","message","attribute","."]
code: def _features_for_patterns(
      self, message: Message, attribute: Text
  ) -> Tuple[
      Optional[scipy.sparse.coo_matrix],
      Optional[scipy.sparse.coo_matrix],
  ]:
      """Checks which known patterns match the message.
  
      Given a sentence, returns a vector of {1,0} values indicating which
      regexes did match. Furthermore, if the
      message is tokenized, the function will mark all tokens with a dict
      relating the name of the regex to whether it was matched.
  
      Args:
          message: Message to be featurized.
          attribute: Attribute of message to be featurized.
  
      Returns:
         Token and sentence level features of message attribute.
      """
      # Attribute not set (e.g. response not present)
      if not message.get(attribute):
          return None, None
  
      tokens = message.get(TOKENS_NAMES[attribute], [])
  
      if not tokens:
          # nothing to featurize
          return None, None
  
      flags = 0  # default flag
      if not self.case_sensitive:
          flags = re.IGNORECASE
  
      sequence_length = len(tokens)
  
      num_patterns = len(self.known_patterns)
  
      sequence_features = np.zeros([sequence_length, num_patterns])
      sentence_features = np.zeros([1, num_patterns])
  
      for pattern_index, pattern in enumerate(self.known_patterns):
          matches = list(
              re.finditer(
                  pattern["pattern"],
                  message.get(attribute),
                  flags=flags,
              )
          )
  
          for token_index, t in enumerate(tokens):
              patterns = t.get("pattern", default={})
              patterns[pattern["name"]] = False
  
              for match in matches:
                  if t.start < match.end() and t.end > match.start():
                      patterns[pattern["name"]] = True
                      sequence_features[token_index][
                          pattern_index
                      ] = 1.0
                      if attribute in [RESPONSE, TEXT, ACTION_TEXT]:
                          # sentence vector should contain all patterns
                          sentence_features[0][pattern_index] = 1.0
  
              t.set("pattern", patterns)
  
      return (
          scipy.sparse.coo_matrix(sequence_features),
          scipy.sparse.coo_matrix(sentence_features),
      )
  
imports: from __future__ import annotations
  import logging
  import re
  from typing import Any, Dict, List, Optional, Text, Tuple, Type
  import numpy
  import scipy.sparse
  from rasa.nlu.tokenizers.tokenizer import Tokenizer
  import rasa.shared.utils.io
  import rasa.utils.io
  import rasa.nlu.utils.pattern_utils
  from rasa.engine.graph import ExecutionContext, GraphComponent
  from rasa.engine.recipes.default_recipe import DefaultV1Recipe
  from rasa.engine.storage.resource import Resource
  from rasa.engine.storage.storage import ModelStorage
  from rasa.nlu.constants import TOKENS_NAMES
  from rasa.nlu.featurizers.sparse_featurizer.sparse_featurizer import SparseFeaturizer
  from rasa.shared.nlu.constants import TEXT, RESPONSE, ACTION_TEXT
  from rasa.shared.nlu.training_data.training_data import TrainingData
  from rasa.shared.nlu.training_data.message import Message
label_desc: Use image node_id 10 for calling the RegexFeaturizer obj's underlying member method code with example usage: obj._features_for_patterns(message, attribute) and returns: scipy,  scipy, None,  None, None,  None