code: def terms_to_strings(
      terms: Iterable[types.SpanLike],
      by: str | Callable[[types.SpanLike], str],
  ) -> Iterable[str]:
      """
      Transform a sequence of terms as spaCy ``Token`` s or ``Span`` s into strings.
  
      Args:
          terms
          by: Method by which terms are transformed into strings.
              If "orth", terms are represented by their text exactly as written;
              if "lower", by the lowercased form of their text;
              if "lemma", by their base form w/o inflectional suffixes;
              if a callable, must accept a ``Token`` or ``Span`` and return a string.
  
      Yields:
          Next term in ``terms``, as a string.
      """
      terms_: Iterable[str]
      if by == "lower":
          terms_ = (term.text.lower() for term in terms)
      elif by in ("lemma", "orth"):
          by_ = operator.attrgetter(f"{by}_")
          terms_ = (by_(term) for term in terms)
      elif callable(by):
          terms_ = (by(term) for term in terms)
      else:
          raise ValueError(
              errors.value_invalid_msg(
                  "by", by, {"orth", "lower", "lemma", Callable}
              )
          )
      for term in terms_:
          yield term
  
file_path: textacy/src/textacy/extract/utils.py
imports: from __future__ import annotations
  import itertools
  import operator
  import re
  from typing import Callable, Collection, Iterable, Optional
  from cytoolz import itertoolz
  from spacy.tokens import Doc, Token
  from ..None import constants, errors, types, utils
  from .None import matches
label_desc: Use image node_id 1 for calling a global function with example usage: terms_to_strings(terms, by) without return types