code: def get_filtered_topn_terms(
      term_scores: Iterable[tuple[str, float]],
      topn: int,
      *,
      match_threshold: Optional[float] = None,
  ) -> list[tuple[str, float]]:
      """
      Build up a list of the ``topn`` terms, filtering out any that are substrings
      of better-scoring terms and optionally filtering out any that are sufficiently
      similar to better-scoring terms.
  
      Args:
          term_scores: Iterable of (term, score) pairs, sorted in order of score
              from best to worst. Note that this may be from high to low value or
              low to high, depending on the scoring algorithm.
          topn: Maximum number of top-scoring terms to get.
          match_threshold: Minimal edit distance between a term and previously seen terms,
              used to filter out terms that are sufficiently similar
              to higher-scoring terms. Uses :func:`textacy.similarity.token_sort_ratio()`.
      """
      from .. import similarity  # ugh, hide import here
  
      topn_terms = []
      seen_terms: set[str] = set()
      sim_func = similarity.token_sort_ratio
      for term, score in term_scores:
          # skip terms that are substrings of any higher-scoring term
          if any(term in st for st in seen_terms):
              continue
          # skip terms that are sufficiently similar to any higher-scoring term
          if match_threshold and any(
              sim_func(term, st) >= match_threshold for st in seen_terms
          ):
              continue
          seen_terms.add(term)
          topn_terms.append((term, score))
          if len(topn_terms) >= topn:
              break
      return topn_terms
  
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 7 for calling a global function with example usage: get_filtered_topn_terms(term_scores, topn) and returns: topn_terms