import nltk
from nltk.tokenize import word_tokenize
from nltk.corpus import stopwords
from nltk import RegexpParser
from spellchecker import SpellChecker 


def spell_check_french(text):
    # Charger le correcteur orthographique
    spell = SpellChecker(language='fr')  # Specify the language
    
    # Tokeniser le texte
    tokens = word_tokenize(text)

    # Corriger chaque token
    corrected_text = [spell.correction(token) for token in tokens]

    return ' '.join(corrected_text)

# Exemple d'utilisation
input_text_french = "caffé byciclette militère orenge solucion aindustryel consomation volontères phrontière"
corrected_text_french = spell_check_french(input_text_french)

print("Original Text (French) : ", input_text_french)
print("Spell Checked Text (NLTK French) : ", corrected_text_french)
