page corrections ajout de boutons
This commit is contained in:
parent
7095f9633b
commit
1713aa30b5
7 changed files with 297 additions and 44 deletions
|
@ -15,8 +15,8 @@ import re
|
|||
import os
|
||||
import csv
|
||||
import argparse
|
||||
from spellchecker import SpellChecker
|
||||
import language_tool_python
|
||||
from spellchecker import SpellChecker
|
||||
|
||||
# Définir les arguments en ligne de commande
|
||||
parser = argparse.ArgumentParser(description='Analyser les fautes d\'orthographe et de grammaire dans un fichier Org-mode.')
|
||||
|
@ -77,7 +77,7 @@ def load_custom_dictionary(file_path):
|
|||
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:
|
||||
|
@ -86,7 +86,7 @@ def load_custom_dictionary(file_path):
|
|||
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'):
|
||||
|
@ -95,34 +95,34 @@ def check_spelling(text, lang='fr', custom_dict_path='dictionnaire_personnalise.
|
|||
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())
|
||||
|
||||
|
||||
# Trouver les mots mal orthographiés
|
||||
misspelled = spell.unknown(words)
|
||||
|
||||
|
||||
# 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) if suggestions is not None else []
|
||||
suggestions_list = suggestions_list[:5]
|
||||
spelling_errors[word] = suggestions_list
|
||||
|
||||
|
||||
return spelling_errors
|
||||
|
||||
def check_grammar(text, lang='fr'):
|
||||
|
@ -131,17 +131,17 @@ def check_grammar(text, lang='fr'):
|
|||
"""
|
||||
# Initialiser l'outil de vérification grammaticale
|
||||
tool = language_tool_python.LanguageTool(lang)
|
||||
|
||||
|
||||
# Vérifier le texte
|
||||
matches = tool.check(text)
|
||||
|
||||
|
||||
# Créer une liste d'erreurs grammaticales
|
||||
grammar_errors = []
|
||||
for match in matches:
|
||||
# Ignorer les erreurs d'orthographe (déjà traitées par le vérificateur d'orthographe)
|
||||
if match.ruleId.startswith('MORFOLOGIK_RULE'):
|
||||
continue
|
||||
|
||||
|
||||
error = {
|
||||
'message': match.message,
|
||||
'context': match.context,
|
||||
|
@ -151,10 +151,10 @@ def check_grammar(text, lang='fr'):
|
|||
'rule': match.ruleId
|
||||
}
|
||||
grammar_errors.append(error)
|
||||
|
||||
|
||||
# Fermer l'outil pour libérer les ressources
|
||||
tool.close()
|
||||
|
||||
|
||||
return grammar_errors
|
||||
|
||||
def generate_error_report(chapters, output_path):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue