code: def get_ngram_candidates(
      doc: Doc,
      ns: int | Collection[int],
      *,
      include_pos: Optional[str | Collection[str]] = (
          "NOUN",
          "PROPN",
          "ADJ",
      ),
  ) -> Iterable[tuple[Token, ...]]:
      """
      Get candidate keyterms from ``doc``, where candidates are n-length sequences
      of tokens (for all n in ``ns``) that don't start/end with a stop word or
      contain punctuation tokens, and whose constituent tokens are filtered by POS tag.
  
      Args:
          doc
          ns: One or more n values for which to generate n-grams. For example,
              ``2`` gets bigrams; ``(2, 3)`` gets bigrams and trigrams.
          include_pos: One or more POS tags with which to filter ngrams.
              If None, include tokens of all POS tags.
  
      Yields:
          Next ngram candidate, as a tuple of constituent Tokens.
  
      See Also:
          :func:`textacy.extract.ngrams()`
      """
      ns_: tuple[int, ...] = utils.to_tuple(ns)
      ngrams = itertoolz.concat(
          itertoolz.sliding_window(n, doc) for n in ns_
      )
      ngrams = (
          ngram
          for ngram in ngrams
          if not (ngram[0].is_stop or ngram[-1].is_stop)
          and not any(word.is_punct or word.is_space for word in ngram)
      )
      if include_pos:
          include_pos_: set[str] = utils.to_set(include_pos)
          ngrams = (
              ngram
              for ngram in ngrams
              if all(word.pos_ in include_pos_ for word in ngram)
          )
      for ngram in ngrams:
          yield ngram
  
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 5 for calling a global function with example usage: get_ngram_candidates(doc, ns) without return types