(
    term_scores: Iterable[Tuple[str, float]],
    topn: int,
    *,
    match_threshold: Optional[float] = None,
)
return topn_terms
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()`.
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.
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 .
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
def get_filtered_topn_terms ( term_scores : Iterable [ Tuple [ str , float ] ] , topn : int , * , match_threshold : Optional [ float ] = None , ) -> List [ Tuple [ str , float ] ] : 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