visualisation des corrections et api flask pour modifier le livre
This commit is contained in:
parent
0680c7594e
commit
7095f9633b
14 changed files with 1593 additions and 276 deletions
|
@ -15,7 +15,7 @@ import re
|
|||
import os
|
||||
import csv
|
||||
import argparse
|
||||
from pyspellchecker import SpellChecker
|
||||
from spellchecker import SpellChecker
|
||||
import language_tool_python
|
||||
|
||||
# Définir les arguments en ligne de commande
|
||||
|
@ -71,12 +71,38 @@ def clean_chapter_content(content):
|
|||
|
||||
return content.strip()
|
||||
|
||||
def check_spelling(text, lang='fr'):
|
||||
def load_custom_dictionary(file_path):
|
||||
"""
|
||||
Charge le dictionnaire personnalisé à partir d'un fichier texte.
|
||||
Retourne un ensemble de mots à considérer comme corrects.
|
||||
"""
|
||||
custom_words = set()
|
||||
|
||||
# Vérifier si le fichier existe
|
||||
if os.path.exists(file_path):
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
for line in file:
|
||||
# Ignorer les lignes vides et les commentaires
|
||||
line = line.strip()
|
||||
if line and not line.startswith('#'):
|
||||
custom_words.add(line.lower())
|
||||
|
||||
return custom_words
|
||||
|
||||
def check_spelling(text, lang='fr', custom_dict_path='dictionnaire_personnalise.txt'):
|
||||
"""
|
||||
Vérifie l'orthographe d'un texte et retourne les mots mal orthographiés.
|
||||
Utilise un dictionnaire personnalisé pour exclure certains mots de la vérification.
|
||||
"""
|
||||
spell = SpellChecker(language=lang)
|
||||
|
||||
# Charger le dictionnaire personnalisé
|
||||
custom_words = load_custom_dictionary(custom_dict_path)
|
||||
|
||||
# Ajouter les mots du dictionnaire personnalisé au dictionnaire du vérificateur
|
||||
if custom_words:
|
||||
spell.word_frequency.load_words(custom_words)
|
||||
|
||||
# Diviser le texte en mots
|
||||
words = re.findall(r'\b\w+\b', text.lower())
|
||||
|
||||
|
@ -86,10 +112,15 @@ def check_spelling(text, lang='fr'):
|
|||
# Créer un dictionnaire avec les mots mal orthographiés et leurs suggestions
|
||||
spelling_errors = {}
|
||||
for word in misspelled:
|
||||
# Vérifier si le mot est dans le dictionnaire personnalisé
|
||||
if word in custom_words:
|
||||
continue
|
||||
|
||||
# Obtenir les suggestions de correction
|
||||
suggestions = spell.candidates(word)
|
||||
# Limiter à 5 suggestions maximum
|
||||
suggestions_list = list(suggestions)[:5]
|
||||
suggestions_list = list(suggestions) if suggestions is not None else []
|
||||
suggestions_list = suggestions_list[:5]
|
||||
spelling_errors[word] = suggestions_list
|
||||
|
||||
return spelling_errors
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue