(snippet, len_range, min_text_frac, exclude_en)
return True
Args:
        snippet (str)
        len_range (Tuple[int, int])
        min_text_frac (float)
        exclude_en (bool)

    Returns:
        bool
Args:
        snippet (str)
        len_range (Tuple[int, int])
        min_text_frac (float)
        exclude_en (bool)
Args : snippet ( str ) len_range ( Tuple [ int int ] ) min_text_frac ( float ) exclude_en ( bool )
def is_good_snippet(snippet, len_range, min_text_frac, exclude_en):
    """
    Args:
        snippet (str)
        len_range (Tuple[int, int])
        min_text_frac (float)
        exclude_en (bool)

    Returns:
        bool
    """
    len_snippet = len(snippet)
    if len_snippet < len_range[0] or len_snippet >= len_range[1]:
        return False
    # make sure snippet is *mostly* text
    len_text = sum(match.end() - match.start() for match in re_text.finditer(snippet))
    if len_text / len_snippet < min_text_frac:
        return False
    # ugh, math and urls!
    if any(s in snippet for s in (r"\displaystyle", "http://", "https://")):
        return False
    # check for citations/references
    if any(re_pat.search(snippet) for re_pat in (re_doi, re_issn, re_isbn)):
        return False
    # filter out english copy-paste jobs
    if exclude_en is True:
        is_reliable, _, best_guesses = cld2_detect(
            snippet.encode("utf-8"), bestEffort=True
        )
        if is_reliable is True and best_guesses[0][1] == "en":
            logging.debug(
                "found english-heavy snippet in non-english wiki text:\n%s", snippet
            )
            return False
    return True
def is_good_snippet ( snippet , len_range , min_text_frac , exclude_en ) : len_snippet = len ( snippet ) if len_snippet < len_range [ 0 ] or len_snippet >= len_range [ 1 ] : return False # make sure snippet is *mostly* text len_text = sum ( match . end ( ) - match . start ( ) for match in re_text . finditer ( snippet ) ) if len_text / len_snippet < min_text_frac : return False # ugh, math and urls! if any ( s in snippet for s in ( r"\displaystyle" , "http://" , "https://" ) ) : return False # check for citations/references if any ( re_pat . search ( snippet ) for re_pat in ( re_doi , re_issn , re_isbn ) ) : return False # filter out english copy-paste jobs if exclude_en is True : is_reliable , _ , best_guesses = cld2_detect ( snippet . encode ( "utf-8" ) , bestEffort = True ) if is_reliable is True and best_guesses [ 0 ] [ 1 ] == "en" : logging . debug ( "found english-heavy snippet in non-english wiki text:\n%s" , snippet ) return False return True