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: Initialize the entity ruler. If patterns are supplied here, they
  need to be a list of dictionaries with a `"label"` and `"pattern"`
  key. A pattern can either be a token pattern (list) or a phrase pattern
  (string). For example: `{'label': 'ORG', 'pattern': 'Apple'}`.
  
  nlp (Language): The shared nlp object to pass the vocab to the matchers
      and process phrase patterns.
  name (str): Instance name of the current pipeline component. Typically
      passed in automatically from the factory when the component is
      added. Used to disable the current entity ruler while creating
      phrase patterns with the nlp object.
  phrase_matcher_attr (int / str): Token attribute to match on, passed
      to the internal PhraseMatcher as `attr`.
  matcher_fuzzy_compare (Callable): The fuzzy comparison method for the
      internal Matcher. Defaults to
      spacy.matcher.levenshtein.levenshtein_compare.
  validate (bool): Whether patterns should be validated, passed to
      Matcher and PhraseMatcher as `validate`
  patterns (iterable): Optional patterns to load in.
  overwrite_ents (bool): If existing entities are present, e.g. entities
      added by the model, overwrite them by matches if necessary.
  ent_id_sep (str): Separator used internally for entity IDs.
  scorer (Optional[Callable]): The scoring method. Defaults to
      spacy.scorer.get_ner_prf.
  
  DOCS: https://spacy.io/api/entityruler#init
code: def __init__(
      self,
      nlp: Language,
      name: str = "entity_ruler",
      *,
      phrase_matcher_attr: Optional[Union[int, str]] = None,
      matcher_fuzzy_compare: Callable = levenshtein_compare,
      validate: bool = False,
      overwrite_ents: bool = False,
      ent_id_sep: str = DEFAULT_ENT_ID_SEP,
      patterns: Optional[List[PatternType]] = None,
      scorer: Optional[Callable] = entity_ruler_score,
  ) -> None:
      """Initialize the entity ruler. If patterns are supplied here, they
      need to be a list of dictionaries with a `"label"` and `"pattern"`
      key. A pattern can either be a token pattern (list) or a phrase pattern
      (string). For example: `{'label': 'ORG', 'pattern': 'Apple'}`.
  
      nlp (Language): The shared nlp object to pass the vocab to the matchers
          and process phrase patterns.
      name (str): Instance name of the current pipeline component. Typically
          passed in automatically from the factory when the component is
          added. Used to disable the current entity ruler while creating
          phrase patterns with the nlp object.
      phrase_matcher_attr (int / str): Token attribute to match on, passed
          to the internal PhraseMatcher as `attr`.
      matcher_fuzzy_compare (Callable): The fuzzy comparison method for the
          internal Matcher. Defaults to
          spacy.matcher.levenshtein.levenshtein_compare.
      validate (bool): Whether patterns should be validated, passed to
          Matcher and PhraseMatcher as `validate`
      patterns (iterable): Optional patterns to load in.
      overwrite_ents (bool): If existing entities are present, e.g. entities
          added by the model, overwrite them by matches if necessary.
      ent_id_sep (str): Separator used internally for entity IDs.
      scorer (Optional[Callable]): The scoring method. Defaults to
          spacy.scorer.get_ner_prf.
  
      DOCS: https://spacy.io/api/entityruler#init
      """
      self.nlp = nlp
      self.name = name
      self.overwrite = overwrite_ents
      self.token_patterns = defaultdict(list)  # type: ignore
      self.phrase_patterns = defaultdict(list)  # type: ignore
      self._validate = validate
      self.matcher_fuzzy_compare = matcher_fuzzy_compare
      self.matcher = Matcher(
          nlp.vocab,
          validate=validate,
          fuzzy_compare=self.matcher_fuzzy_compare,
      )
      self.phrase_matcher_attr = phrase_matcher_attr
      self.phrase_matcher = PhraseMatcher(
          nlp.vocab, attr=self.phrase_matcher_attr, validate=validate
      )
      self.ent_id_sep = ent_id_sep
      self._ent_ids = defaultdict(tuple)  # type: ignore
      if patterns is not None:
          self.add_patterns(patterns)
      self.scorer = scorer
  
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 1 to create a new EntityRuler object from inherited base classes: Pipe with example: obj = EntityRuler(nlp, name)