class_docstr: The SpanRuler lets you add spans to the `Doc.spans` using token-based
  rules or exact phrase matches.
  
  DOCS: https://spacy.io/api/spanruler
  USAGE: https://spacy.io/usage/rule-based-matching#spanruler
class_docstr_tok: ["The","SpanRuler","lets","you","add","spans","to","the","`","Doc.spans","`","using","token-based","rules","or","exact","phrase","matches",".","DOCS",":","https",":","\/\/spacy.io\/api\/spanruler","USAGE",":","https",":","\/\/spacy.io\/usage\/rule-based-matching","#","spanruler"]
docstr: Add patterns to the span ruler. A pattern can either be a token
  pattern (list of dicts) or a phrase pattern (string). For example:
  {'label': 'ORG', 'pattern': 'Apple'}
  {'label': 'ORG', 'pattern': 'Apple', 'id': 'apple'}
  {'label': 'GPE', 'pattern': [{'lower': 'san'}, {'lower': 'francisco'}]}
  
  patterns (list): The patterns to add.
  
  DOCS: https://spacy.io/api/spanruler#add_patterns
docstr_tok: ["Add","patterns","to","the","span","ruler",".","A","pattern","can","either","be","a","token","pattern","(","list","of","dicts",")","or","a","phrase","pattern","(","string",")",".","For","example",":","{","'label","'",":","'ORG","'",",","'pattern","'",":","'Apple","'","}","{","'label","'",":","'ORG","'",",","'pattern","'",":","'Apple","'",",","'id","'",":","'apple","'","}","{","'label","'",":","'GPE","'",",","'pattern","'",":","[","{","'lower","'",":","'san","'","}",",","{","'lower","'",":","'francisco","'","}","]","}","patterns","(","list",")",":","The","patterns","to","add",".","DOCS",":","https",":","\/\/spacy.io\/api\/spanruler","#","add_patterns"]
code: def add_patterns(self, patterns: List[PatternType]) -> None:
      """Add patterns to the span ruler. A pattern can either be a token
      pattern (list of dicts) or a phrase pattern (string). For example:
      {'label': 'ORG', 'pattern': 'Apple'}
      {'label': 'ORG', 'pattern': 'Apple', 'id': 'apple'}
      {'label': 'GPE', 'pattern': [{'lower': 'san'}, {'lower': 'francisco'}]}
  
      patterns (list): The patterns to add.
  
      DOCS: https://spacy.io/api/spanruler#add_patterns
      """
  
      # disable the nlp components after this one in case they haven't been
      # initialized / deserialized yet
      try:
          current_index = -1
          for i, (name, pipe) in enumerate(self.nlp.pipeline):
              if self == pipe:
                  current_index = i
                  break
          subsequent_pipes = [
              pipe for pipe in self.nlp.pipe_names[current_index:]
          ]
      except ValueError:
          subsequent_pipes = []
      with self.nlp.select_pipes(disable=subsequent_pipes):
          phrase_pattern_labels = []
          phrase_pattern_texts = []
          for entry in patterns:
              p_label = cast(str, entry["label"])
              p_id = cast(str, entry.get("id", ""))
              label = repr((p_label, p_id))
              self._match_label_id_map[
                  self.nlp.vocab.strings.as_int(label)
              ] = {
                  "label": p_label,
                  "id": p_id,
              }
              if isinstance(entry["pattern"], str):
                  phrase_pattern_labels.append(label)
                  phrase_pattern_texts.append(entry["pattern"])
              elif isinstance(entry["pattern"], list):
                  self.matcher.add(label, [entry["pattern"]])
              else:
                  raise ValueError(
                      Errors.E097.format(pattern=entry["pattern"])
                  )
              self._patterns.append(entry)
          for label, pattern in zip(
              phrase_pattern_labels,
              self.nlp.pipe(phrase_pattern_texts),
          ):
              self.phrase_matcher.add(label, [pattern])
  
imports: import warnings
  from functools import partial
  from pathlib import Path
  from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Set, Tuple, Union, cast
  import srsly
  from ..None import util
  from ..errors import Errors, Warnings
  from ..language import Language
  from ..matcher import Matcher, PhraseMatcher
  from ..matcher.levenshtein import levenshtein_compare
  from ..scorer import Scorer
  from ..tokens import Doc, Span
  from ..training import Example
  from ..util import SimpleFrozenList, ensure_path, registry
  from .pipe import Pipe
label_desc: Use image node_id 12 for calling the SpanRuler obj's underlying member method code with example usage: obj.add_patterns(patterns) without return types