def filter_score()

in misc/precision_filtering/wordlist_score.py [0:0]


def filter_score(text, lang):
    text = simplify_text(str(text).strip(), norm_config)
    # Split the text into words and convert it to a set
    words = set(split_into_words(text, lang))
    # Get the list of words for the specified language and convert it to a set
    lang_words = loaded_language_dict[lang]  # Convert to set for faster lookups

    # Count how many words from the text appear in the language's word list
    matching_words = len(words & lang_words)  # Use set intersection to count matches

    # Calculate the normalized score (between 0 and 1)
    score = matching_words / len(words) if words else 0  # Avoid division by zero if text is empty
    return score