(
    terms: Iterable[types.SpanLike], by: str | Callable[[types.SpanLike], 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.
Transform a sequence of terms as spaCy ``Token`` s or ``Span`` s into strings.
Transform a sequence of terms as spaCy Token s or Span s into strings .
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.
    """
    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
def terms_to_strings ( terms : Iterable [ types . SpanLike ] , by : str | Callable [ [ types . SpanLike ] , str ] , ) -> 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