class_docstr: The EntityRuler lets you add spans to the `Doc.ents` using token-based
  rules or exact phrase matches. It can be combined with the statistical
  `EntityRecognizer` to boost accuracy, or used on its own to implement a
  purely rule-based entity recognition system. After initialization, the
  component is typically added to the pipeline using `nlp.add_pipe`.
  
  DOCS: https://spacy.io/api/entityruler
  USAGE: https://spacy.io/usage/rule-based-matching#entityruler
docstr: Add patterns to the entity ruler. A pattern can either be a token
  pattern (list of dicts) or a phrase pattern (string). For example:
  {'label': 'ORG', 'pattern': 'Apple'}
  {'label': 'GPE', 'pattern': [{'lower': 'san'}, {'lower': 'francisco'}]}
  
  patterns (list): The patterns to add.
  
  DOCS: https://spacy.io/api/entityruler#add_patterns
code: def add_patterns(self, patterns: List[PatternType]) -> None:
      """Add patterns to the entity ruler. A pattern can either be a token
      pattern (list of dicts) or a phrase pattern (string). For example:
      {'label': 'ORG', 'pattern': 'Apple'}
      {'label': 'GPE', 'pattern': [{'lower': 'san'}, {'lower': 'francisco'}]}
  
      patterns (list): The patterns to add.
  
      DOCS: https://spacy.io/api/entityruler#add_patterns
      """
  
      # disable the nlp components after this one in case they hadn't been initialized / deserialised 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):
          token_patterns = []
          phrase_pattern_labels = []
          phrase_pattern_texts = []
          phrase_pattern_ids = []
          for entry in patterns:
              if isinstance(entry["pattern"], str):
                  phrase_pattern_labels.append(entry["label"])
                  phrase_pattern_texts.append(entry["pattern"])
                  phrase_pattern_ids.append(entry.get("id"))
              elif isinstance(entry["pattern"], list):
                  token_patterns.append(entry)
          phrase_patterns = []
          for label, pattern, ent_id in zip(
              phrase_pattern_labels,
              self.nlp.pipe(phrase_pattern_texts),
              phrase_pattern_ids,
          ):
              phrase_pattern = {"label": label, "pattern": pattern}
              if ent_id:
                  phrase_pattern["id"] = ent_id
              phrase_patterns.append(phrase_pattern)
          for entry in token_patterns + phrase_patterns:  # type: ignore[operator]
              label = entry["label"]  # type: ignore
              if "id" in entry:
                  ent_label = label
                  label = self._create_label(label, entry["id"])
                  key = self.matcher._normalize_key(label)
                  self._ent_ids[key] = (ent_label, entry["id"])
              pattern = entry["pattern"]  # type: ignore
              if isinstance(pattern, Doc):
                  self.phrase_patterns[label].append(pattern)
                  self.phrase_matcher.add(label, [pattern])  # type: ignore
              elif isinstance(pattern, list):
                  self.token_patterns[label].append(pattern)
                  self.matcher.add(label, [pattern])
              else:
                  raise ValueError(Errors.E097.format(pattern=pattern))
  
imports: import warnings
  from collections import defaultdict
  from pathlib import Path
  from typing import Any, Callable, Dict, Iterable, List, Optional, Sequence, Tuple, Union
  import srsly
  from ..errors import Errors, Warnings
  from ..language import Language
  from ..matcher import Matcher, PhraseMatcher
  from ..matcher.levenshtein import levenshtein_compare
  from ..scorer import get_ner_prf
  from ..tokens import Doc, Span
  from ..training import Example
  from ..util import SimpleFrozenList, ensure_path, from_disk, registry, to_disk
  from .pipe import Pipe
label_desc: Use image node_id 11 for calling the EntityRuler obj's underlying member method code with example usage: obj.add_patterns(patterns) without return types