# Script pour tester la validité des mots de english_words.txt selon la logique de cemantle.py

WORDS_FILE = "english_words.txt"
VALID_WORDS_FILE = "english_words.txt"

with open(VALID_WORDS_FILE) as f:
    valid_words = set(w.strip() for w in f)

def is_valid_word(word):
    return word.islower() and word.isalpha() and word in valid_words and 3 <= len(word) <= 15

with open(WORDS_FILE) as f:
    words_to_test = [w.strip() for w in f]

valid = []
invalid = []
for word in words_to_test:
    if is_valid_word(word):
        valid.append(word)
    else:
        invalid.append(word)

with open("valid_english_words.txt", "w") as f:
    f.write("\n".join(valid))
with open("invalid_english_words.txt", "w") as f:
    f.write("\n".join(invalid))

print(f"Mots valides : {len(valid)}\nMots invalides : {len(invalid)}")
