class_docstr: A spaCy pipe for detecting hyponyms using Hearst patterns.
  This class sets the following attributes:
  
  - `Doc._.hearst_patterns`: A List[Tuple[str, Span, Span]] corresonding to
     the matching predicate, extracted general term and specific term
     that matched a Hearst pattern.
  
  Parts of the implementation taken from
  https://github.com/mmichelsonIF/hearst_patterns_python/blob/master/hearstPatterns/hearstPatterns.py
  and
  https://github.com/Fourthought/CNDPipeline/blob/master/cndlib/hpspacy.py
  
  The pipe can be used with an instantiated spacy model like so:
  ```
  # add the hyponym detector
  nlp.add_pipe('hyponym_detector', config={'extended': True}, last=True)
  
  Parameters
  ----------
  
  nlp: `Language`, a required argument for spacy to use this as a factory
  name: `str`, a required argument for spacy to use this as a factory
  extended: `bool`, whether to use the extended Hearts patterns or not
docstr: Runs the matcher on the Doc object and sets token and
  doc level attributes for hypernym and hyponym relations.
docstr_tok: ["Runs","the","matcher","on","the","Doc","object","and","sets","token","and","doc","level","attributes","for","hypernym","and","hyponym","relations","."]
code: def __call__(self, doc: Doc):
      """
      Runs the matcher on the Doc object and sets token and
      doc level attributes for hypernym and hyponym relations.
      """
      # Find matches in doc
      matches = self.matcher(doc)
  
      # If none are found then return None
      if not matches:
          return doc
  
      for match_id, start, end in matches:
          predicate = self.nlp.vocab.strings[match_id]
  
          # if the predicate is in the list where the hypernym is last, else hypernym is first
          if predicate in self.last:
              hypernym = doc[end - 1]
              hyponym = doc[start]
          else:
              # An inelegent way to deal with the "such_NOUN_as pattern"
              # since the first token is not the hypernym.
              if doc[start].lemma_ == "such":
                  start += 1
              hypernym = doc[start]
              hyponym = doc[end - 1]
  
          hypernym = self.find_noun_compound_head(hypernym)
          hyponym = self.find_noun_compound_head(hyponym)
  
          # For the document level, we expand to contain noun phrases.
          hypernym_extended = self.expand_to_noun_compound(
              hypernym, doc
          )
          hyponym_extended = self.expand_to_noun_compound(hyponym, doc)
  
          doc._.hearst_patterns.append(
              (predicate, hypernym_extended, hyponym_extended)
          )
  
          for token in hyponym.conjuncts:
              token_extended = self.expand_to_noun_compound(token, doc)
              if token != hypernym and token is not None:
                  doc._.hearst_patterns.append(
                      (predicate, hypernym_extended, token_extended)
                  )
  
      return doc
  
file_path: scispacy/scispacy/hyponym_detector.py
imports: from spacy.matcher import Matcher
  from spacy.tokens import Token, Doc
  from spacy.language import Language
  from scispacy.hearst_patterns import BASE_PATTERNS, EXTENDED_PATTERNS
label_desc: Use image node_id 4 for calling the HyponymDetector obj's underlying member method code with example usage: obj.__call__(doc) and returns: doc, doc