add analyse fréquence mots tagcloud
This commit is contained in:
parent
cffb31c1ef
commit
5acbfd8461
1 changed files with 44 additions and 23 deletions
|
|
@ -15,7 +15,8 @@ import re
|
||||||
import os
|
import os
|
||||||
import csv
|
import csv
|
||||||
import argparse
|
import argparse
|
||||||
|
from pyspellchecker import SpellChecker
|
||||||
|
import language_tool_python
|
||||||
# Vérifier si les modules nécessaires sont disponibles
|
# Vérifier si les modules nécessaires sont disponibles
|
||||||
try:
|
try:
|
||||||
import language_tool_python
|
import language_tool_python
|
||||||
|
|
@ -83,7 +84,6 @@ def clean_chapter_content(content):
|
||||||
content = re.sub(r'\n\s*\n', '\n\n', content)
|
content = re.sub(r'\n\s*\n', '\n\n', content)
|
||||||
|
|
||||||
return content.strip()
|
return content.strip()
|
||||||
|
|
||||||
def load_custom_dictionary(file_path):
|
def load_custom_dictionary(file_path):
|
||||||
"""
|
"""
|
||||||
Charge le dictionnaire personnalisé à partir d'un fichier texte.
|
Charge le dictionnaire personnalisé à partir d'un fichier texte.
|
||||||
|
|
@ -102,7 +102,9 @@ def load_custom_dictionary(file_path):
|
||||||
|
|
||||||
return custom_words
|
return custom_words
|
||||||
|
|
||||||
|
|
||||||
def check_spelling(text, lang='fr', custom_dict_path='dictionnaire_personnalise.txt'):
|
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.
|
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.
|
Utilise un dictionnaire personnalisé pour exclure certains mots de la vérification.
|
||||||
|
|
@ -176,6 +178,24 @@ def check_spelling(text, lang='fr', custom_dict_path='dictionnaire_personnalise.
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Erreur lors de la vérification orthographique: {str(e)}")
|
print(f"Erreur lors de la vérification orthographique: {str(e)}")
|
||||||
return []
|
return []
|
||||||
|
spell = SpellChecker(language=lang)
|
||||||
|
|
||||||
|
# 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:
|
||||||
|
# Obtenir les suggestions de correction
|
||||||
|
suggestions = spell.candidates(word)
|
||||||
|
# Limiter à 5 suggestions maximum
|
||||||
|
suggestions_list = list(suggestions)[:5]
|
||||||
|
spelling_errors[word] = suggestions_list
|
||||||
|
|
||||||
|
return spelling_errors
|
||||||
|
|
||||||
def check_grammar(text, lang='fr'):
|
def check_grammar(text, lang='fr'):
|
||||||
"""
|
"""
|
||||||
|
|
@ -311,6 +331,7 @@ def generate_error_report(chapters, output_path):
|
||||||
# Mettre en évidence l'erreur dans le contexte
|
# Mettre en évidence l'erreur dans le contexte
|
||||||
context = error['context'].replace(error['context'][error['offset']:error['offset']+error['length']],
|
context = error['context'].replace(error['context'][error['offset']:error['offset']+error['length']],
|
||||||
f"**{error['context'][error['offset']:error['offset']+error['length']]}**")
|
f"**{error['context'][error['offset']:error['offset']+error['length']]}**")
|
||||||
|
report_file.write(f"- **Erreur**: {error['message']}\n")
|
||||||
|
|
||||||
report_file.write(f"- **Erreur {i+1}**: {error['message']}\n")
|
report_file.write(f"- **Erreur {i+1}**: {error['message']}\n")
|
||||||
report_file.write(f" - **Contexte**: {context}\n")
|
report_file.write(f" - **Contexte**: {context}\n")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue