Update modules/studentact/current_situation_analysis.py
Browse files
modules/studentact/current_situation_analysis.py
CHANGED
@@ -249,7 +249,7 @@ def analyze_clarity(doc):
|
|
249 |
logger.error(f"Error en analyze_clarity: {str(e)}")
|
250 |
return 0.0, {}
|
251 |
|
252 |
-
|
253 |
def analyze_vocabulary_diversity(doc):
|
254 |
"""Análisis mejorado de la diversidad y calidad del vocabulario"""
|
255 |
try:
|
@@ -307,6 +307,7 @@ def analyze_vocabulary_diversity(doc):
|
|
307 |
logger.error(f"Error en analyze_vocabulary_diversity: {str(e)}")
|
308 |
return 0.0, {}
|
309 |
|
|
|
310 |
def analyze_cohesion(doc):
|
311 |
"""Analiza la cohesión textual"""
|
312 |
try:
|
@@ -388,6 +389,7 @@ def analyze_cohesion(doc):
|
|
388 |
logger.error(f"Error en analyze_cohesion: {str(e)}")
|
389 |
return 0.0
|
390 |
|
|
|
391 |
def analyze_structure(doc):
|
392 |
try:
|
393 |
if len(doc) == 0:
|
@@ -408,8 +410,8 @@ def analyze_structure(doc):
|
|
408 |
logger.error(f"Error en analyze_structure: {str(e)}")
|
409 |
return 0.0
|
410 |
|
|
|
411 |
# Funciones auxiliares de análisis
|
412 |
-
|
413 |
def get_dependency_depths(token, depth=0, analyzed_tokens=None):
|
414 |
"""
|
415 |
Analiza la profundidad y calidad de las relaciones de dependencia.
|
@@ -515,6 +517,7 @@ def get_dependency_depths(token, depth=0, analyzed_tokens=None):
|
|
515 |
|
516 |
return current_result
|
517 |
|
|
|
518 |
def normalize_score(value, metric_type,
|
519 |
min_threshold=0.0, target_threshold=1.0,
|
520 |
range_factor=2.0, optimal_length=None,
|
@@ -617,7 +620,200 @@ def normalize_score(value, metric_type,
|
|
617 |
logger.error(f"Error en normalize_score: {str(e)}")
|
618 |
return 0.0
|
619 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
620 |
|
|
|
|
|
621 |
# Funciones de generación de gráficos
|
622 |
def generate_sentence_graphs(doc):
|
623 |
"""Genera visualizaciones de estructura de oraciones"""
|
|
|
249 |
logger.error(f"Error en analyze_clarity: {str(e)}")
|
250 |
return 0.0, {}
|
251 |
|
252 |
+
#########################################################################
|
253 |
def analyze_vocabulary_diversity(doc):
|
254 |
"""Análisis mejorado de la diversidad y calidad del vocabulario"""
|
255 |
try:
|
|
|
307 |
logger.error(f"Error en analyze_vocabulary_diversity: {str(e)}")
|
308 |
return 0.0, {}
|
309 |
|
310 |
+
#########################################################################
|
311 |
def analyze_cohesion(doc):
|
312 |
"""Analiza la cohesión textual"""
|
313 |
try:
|
|
|
389 |
logger.error(f"Error en analyze_cohesion: {str(e)}")
|
390 |
return 0.0
|
391 |
|
392 |
+
#########################################################################
|
393 |
def analyze_structure(doc):
|
394 |
try:
|
395 |
if len(doc) == 0:
|
|
|
410 |
logger.error(f"Error en analyze_structure: {str(e)}")
|
411 |
return 0.0
|
412 |
|
413 |
+
#########################################################################
|
414 |
# Funciones auxiliares de análisis
|
|
|
415 |
def get_dependency_depths(token, depth=0, analyzed_tokens=None):
|
416 |
"""
|
417 |
Analiza la profundidad y calidad de las relaciones de dependencia.
|
|
|
517 |
|
518 |
return current_result
|
519 |
|
520 |
+
#########################################################################
|
521 |
def normalize_score(value, metric_type,
|
522 |
min_threshold=0.0, target_threshold=1.0,
|
523 |
range_factor=2.0, optimal_length=None,
|
|
|
620 |
logger.error(f"Error en normalize_score: {str(e)}")
|
621 |
return 0.0
|
622 |
|
623 |
+
#########################################################################
|
624 |
+
#########################################################################
|
625 |
+
def generate_recommendations(metrics, text_type, lang_code='es'):
|
626 |
+
"""
|
627 |
+
Genera recomendaciones personalizadas basadas en las métricas del texto y el tipo de texto.
|
628 |
+
|
629 |
+
Args:
|
630 |
+
metrics: Diccionario con las métricas analizadas
|
631 |
+
text_type: Tipo de texto ('academic_article', 'student_essay', 'general_communication')
|
632 |
+
lang_code: Código del idioma para las recomendaciones (es, en, fr, pt)
|
633 |
+
|
634 |
+
Returns:
|
635 |
+
dict: Recomendaciones organizadas por categoría en el idioma correspondiente
|
636 |
+
"""
|
637 |
+
try:
|
638 |
+
# Obtener umbrales según el tipo de texto
|
639 |
+
thresholds = TEXT_TYPES[text_type]['thresholds']
|
640 |
+
|
641 |
+
# Verificar que el idioma esté soportado, usar español como respaldo
|
642 |
+
if lang_code not in RECOMMENDATIONS:
|
643 |
+
logger.warning(f"Idioma {lang_code} no soportado para recomendaciones, usando español")
|
644 |
+
lang_code = 'es'
|
645 |
+
|
646 |
+
# Obtener traducciones para el idioma seleccionado
|
647 |
+
translations = RECOMMENDATIONS[lang_code]
|
648 |
+
|
649 |
+
# Inicializar diccionario de recomendaciones
|
650 |
+
recommendations = {
|
651 |
+
'vocabulary': [],
|
652 |
+
'structure': [],
|
653 |
+
'cohesion': [],
|
654 |
+
'clarity': [],
|
655 |
+
'specific': [],
|
656 |
+
'priority': {
|
657 |
+
'area': 'general',
|
658 |
+
'tips': []
|
659 |
+
},
|
660 |
+
'text_type_name': translations['text_types'][text_type],
|
661 |
+
'dimension_names': translations['dimension_names'],
|
662 |
+
'ui_text': {
|
663 |
+
'priority_intro': translations['priority_intro'],
|
664 |
+
'detailed_recommendations': translations['detailed_recommendations'],
|
665 |
+
'save_button': translations['save_button'],
|
666 |
+
'save_success': translations['save_success'],
|
667 |
+
'save_error': translations['save_error'],
|
668 |
+
'area_priority': translations['area_priority']
|
669 |
+
}
|
670 |
+
}
|
671 |
+
|
672 |
+
# Determinar nivel para cada dimensión y asignar recomendaciones
|
673 |
+
dimensions = ['vocabulary', 'structure', 'cohesion', 'clarity']
|
674 |
+
scores = {}
|
675 |
+
|
676 |
+
for dim in dimensions:
|
677 |
+
score = metrics[dim]['normalized_score']
|
678 |
+
scores[dim] = score
|
679 |
+
|
680 |
+
# Determinar nivel (bajo, medio, alto)
|
681 |
+
if score < thresholds[dim]['min']:
|
682 |
+
level = 'low'
|
683 |
+
elif score < thresholds[dim]['target']:
|
684 |
+
level = 'medium'
|
685 |
+
else:
|
686 |
+
level = 'high'
|
687 |
+
|
688 |
+
# Asignar recomendaciones para ese nivel
|
689 |
+
recommendations[dim] = translations[dim][level]
|
690 |
+
|
691 |
+
# Asignar recomendaciones específicas por tipo de texto
|
692 |
+
recommendations['specific'] = translations[text_type]
|
693 |
+
|
694 |
+
# Determinar área prioritaria (la que tiene menor puntuación)
|
695 |
+
priority_dimension = min(scores, key=scores.get)
|
696 |
+
recommendations['priority']['area'] = priority_dimension
|
697 |
+
recommendations['priority']['tips'] = recommendations[priority_dimension]
|
698 |
+
|
699 |
+
logger.info(f"Generadas recomendaciones en {lang_code} para texto tipo {text_type}")
|
700 |
+
return recommendations
|
701 |
+
|
702 |
+
except Exception as e:
|
703 |
+
logger.error(f"Error en generate_recommendations: {str(e)}")
|
704 |
+
# Retornar mensajes genéricos en caso de error
|
705 |
+
if lang_code == 'en':
|
706 |
+
return {
|
707 |
+
'vocabulary': ["Try enriching your vocabulary"],
|
708 |
+
'structure': ["Work on the structure of your sentences"],
|
709 |
+
'cohesion': ["Improve the connection between your ideas"],
|
710 |
+
'clarity': ["Try to express your ideas more clearly"],
|
711 |
+
'specific': ["Adapt your text according to its purpose"],
|
712 |
+
'priority': {
|
713 |
+
'area': 'general',
|
714 |
+
'tips': ["Seek specific feedback from a tutor or teacher"]
|
715 |
+
},
|
716 |
+
'dimension_names': {
|
717 |
+
'vocabulary': 'Vocabulary',
|
718 |
+
'structure': 'Structure',
|
719 |
+
'cohesion': 'Cohesion',
|
720 |
+
'clarity': 'Clarity',
|
721 |
+
'general': 'General'
|
722 |
+
},
|
723 |
+
'ui_text': {
|
724 |
+
'priority_intro': "This is where you should focus your efforts.",
|
725 |
+
'detailed_recommendations': "Detailed recommendations",
|
726 |
+
'save_button': "Save analysis",
|
727 |
+
'save_success': "Analysis saved successfully",
|
728 |
+
'save_error': "Error saving analysis",
|
729 |
+
'area_priority': "Priority area"
|
730 |
+
}
|
731 |
+
}
|
732 |
+
elif lang_code == 'fr':
|
733 |
+
return {
|
734 |
+
'vocabulary': ["Essayez d'enrichir votre vocabulaire"],
|
735 |
+
'structure': ["Travaillez sur la structure de vos phrases"],
|
736 |
+
'cohesion': ["Améliorez la connexion entre vos idées"],
|
737 |
+
'clarity': ["Essayez d'exprimer vos idées plus clairement"],
|
738 |
+
'specific': ["Adaptez votre texte en fonction de son objectif"],
|
739 |
+
'priority': {
|
740 |
+
'area': 'general',
|
741 |
+
'tips': ["Demandez des commentaires spécifiques à un tuteur ou un professeur"]
|
742 |
+
},
|
743 |
+
'dimension_names': {
|
744 |
+
'vocabulary': 'Vocabulaire',
|
745 |
+
'structure': 'Structure',
|
746 |
+
'cohesion': 'Cohésion',
|
747 |
+
'clarity': 'Clarté',
|
748 |
+
'general': 'Général'
|
749 |
+
},
|
750 |
+
'ui_text': {
|
751 |
+
'priority_intro': "C'est là que vous devriez concentrer vos efforts.",
|
752 |
+
'detailed_recommendations': "Recommandations détaillées",
|
753 |
+
'save_button': "Enregistrer l'analyse",
|
754 |
+
'save_success': "Analyse enregistrée avec succès",
|
755 |
+
'save_error': "Erreur lors de l'enregistrement de l'analyse",
|
756 |
+
'area_priority': "Domaine prioritaire"
|
757 |
+
}
|
758 |
+
}
|
759 |
+
elif lang_code == 'pt':
|
760 |
+
return {
|
761 |
+
'vocabulary': ["Tente enriquecer seu vocabulário"],
|
762 |
+
'structure': ["Trabalhe na estrutura de suas frases"],
|
763 |
+
'cohesion': ["Melhore a conexão entre suas ideias"],
|
764 |
+
'clarity': ["Tente expressar suas ideias com mais clareza"],
|
765 |
+
'specific': ["Adapte seu texto de acordo com seu propósito"],
|
766 |
+
'priority': {
|
767 |
+
'area': 'general',
|
768 |
+
'tips': ["Busque feedback específico de um tutor ou professor"]
|
769 |
+
},
|
770 |
+
'dimension_names': {
|
771 |
+
'vocabulary': 'Vocabulário',
|
772 |
+
'structure': 'Estrutura',
|
773 |
+
'cohesion': 'Coesão',
|
774 |
+
'clarity': 'Clareza',
|
775 |
+
'general': 'Geral'
|
776 |
+
},
|
777 |
+
'ui_text': {
|
778 |
+
'priority_intro': "É aqui que você deve concentrar seus esforços.",
|
779 |
+
'detailed_recommendations': "Recomendações detalhadas",
|
780 |
+
'save_button': "Salvar análise",
|
781 |
+
'save_success': "Análise salva com sucesso",
|
782 |
+
'save_error': "Erro ao salvar análise",
|
783 |
+
'area_priority': "Área prioritária"
|
784 |
+
}
|
785 |
+
}
|
786 |
+
else: # Español por defecto
|
787 |
+
return {
|
788 |
+
'vocabulary': ["Intenta enriquecer tu vocabulario"],
|
789 |
+
'structure': ["Trabaja en la estructura de tus oraciones"],
|
790 |
+
'cohesion': ["Mejora la conexión entre tus ideas"],
|
791 |
+
'clarity': ["Busca expresar tus ideas con mayor claridad"],
|
792 |
+
'specific': ["Adapta tu texto según su propósito"],
|
793 |
+
'priority': {
|
794 |
+
'area': 'general',
|
795 |
+
'tips': ["Busca retroalimentación específica de un tutor o profesor"]
|
796 |
+
},
|
797 |
+
'dimension_names': {
|
798 |
+
'vocabulary': 'Vocabulario',
|
799 |
+
'structure': 'Estructura',
|
800 |
+
'cohesion': 'Cohesión',
|
801 |
+
'clarity': 'Claridad',
|
802 |
+
'general': 'General'
|
803 |
+
},
|
804 |
+
'ui_text': {
|
805 |
+
'priority_intro': "Esta es el área donde debes concentrar tus esfuerzos.",
|
806 |
+
'detailed_recommendations': "Recomendaciones detalladas",
|
807 |
+
'save_button': "Guardar análisis",
|
808 |
+
'save_success': "Análisis guardado con éxito",
|
809 |
+
'save_error': "Error al guardar el análisis",
|
810 |
+
'area_priority': "Área prioritaria"
|
811 |
+
}
|
812 |
+
}
|
813 |
+
|
814 |
|
815 |
+
#########################################################################
|
816 |
+
#########################################################################
|
817 |
# Funciones de generación de gráficos
|
818 |
def generate_sentence_graphs(doc):
|
819 |
"""Genera visualizaciones de estructura de oraciones"""
|