def load_words_from_txt()

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


def load_words_from_txt(folder_path):
    """
    Load words from text files in the given folder into a dictionary.
    
    folder_path: Path to the folder containing the language text files.
    
    Returns:
        A dictionary where keys are language names and values are lists of words.
    """
    language_dict = {}

    # List all files in the folder
    for filename in os.listdir(folder_path):
        # Check if the file is a .txt file
        if filename.endswith('.txt'):
            # Extract the language name from the filename (excluding the .txt extension)
            lang = filename[:-4]
            word_list = []

            # Open the file and read the words
            with open(os.path.join(folder_path, filename), 'r', encoding='utf-8') as file:
                for line in file:
                    word = line.strip()  # Remove any leading/trailing whitespace
                    if word:  # Skip empty lines
                        word_list.append(word)

            # Store the list of words for the current language in the dictionary
            language_dict[lang] = set(word_list)
    
    return language_dict