Spaces:
Sleeping
Sleeping
Update modules/studentact/current_situation_analysis.py
Browse files
modules/studentact/current_situation_analysis.py
CHANGED
|
@@ -23,35 +23,83 @@ logging.basicConfig(
|
|
| 23 |
# 3. Obtener el logger espec铆fico para este m贸dulo
|
| 24 |
logger = logging.getLogger(__name__)
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
def analyze_text_dimensions(doc):
|
| 27 |
"""
|
| 28 |
-
Analiza las dimensiones principales del texto.
|
| 29 |
"""
|
| 30 |
try:
|
| 31 |
-
#
|
| 32 |
vocab_score, vocab_details = analyze_vocabulary_diversity(doc)
|
| 33 |
-
|
| 34 |
-
# An谩lisis de estructura
|
| 35 |
struct_score = analyze_structure(doc)
|
| 36 |
-
|
| 37 |
-
# An谩lisis de cohesi贸n
|
| 38 |
cohesion_score = analyze_cohesion(doc)
|
| 39 |
-
|
| 40 |
-
# An谩lisis de claridad
|
| 41 |
clarity_score, clarity_details = analyze_clarity(doc)
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
'vocabulary': {
|
| 45 |
'normalized_score': vocab_score,
|
| 46 |
'details': vocab_details
|
| 47 |
},
|
| 48 |
'structure': {
|
| 49 |
'normalized_score': struct_score,
|
| 50 |
-
'details': None
|
| 51 |
},
|
| 52 |
'cohesion': {
|
| 53 |
'normalized_score': cohesion_score,
|
| 54 |
-
'details': None
|
| 55 |
},
|
| 56 |
'clarity': {
|
| 57 |
'normalized_score': clarity_score,
|
|
@@ -59,6 +107,20 @@ def analyze_text_dimensions(doc):
|
|
| 59 |
}
|
| 60 |
}
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
except Exception as e:
|
| 63 |
logger.error(f"Error en analyze_text_dimensions: {str(e)}")
|
| 64 |
return {
|
|
@@ -70,6 +132,8 @@ def analyze_text_dimensions(doc):
|
|
| 70 |
|
| 71 |
|
| 72 |
|
|
|
|
|
|
|
| 73 |
def analyze_clarity(doc):
|
| 74 |
"""
|
| 75 |
Analiza la claridad del texto considerando m煤ltiples factores.
|
|
|
|
| 23 |
# 3. Obtener el logger espec铆fico para este m贸dulo
|
| 24 |
logger = logging.getLogger(__name__)
|
| 25 |
|
| 26 |
+
#########################################################################
|
| 27 |
+
|
| 28 |
+
def correlate_metrics(scores):
|
| 29 |
+
"""
|
| 30 |
+
Ajusta los scores para mantener correlaciones l贸gicas entre m茅tricas.
|
| 31 |
+
|
| 32 |
+
Args:
|
| 33 |
+
scores: dict con scores iniciales de vocabulario, estructura, cohesi贸n y claridad
|
| 34 |
+
|
| 35 |
+
Returns:
|
| 36 |
+
dict con scores ajustados
|
| 37 |
+
"""
|
| 38 |
+
try:
|
| 39 |
+
# 1. Correlaci贸n estructura-cohesi贸n
|
| 40 |
+
# La cohesi贸n no puede ser menor que estructura * 0.7
|
| 41 |
+
min_cohesion = scores['structure']['normalized_score'] * 0.7
|
| 42 |
+
if scores['cohesion']['normalized_score'] < min_cohesion:
|
| 43 |
+
scores['cohesion']['normalized_score'] = min_cohesion
|
| 44 |
+
|
| 45 |
+
# 2. Correlaci贸n vocabulario-cohesi贸n
|
| 46 |
+
# La cohesi贸n l茅xica depende del vocabulario
|
| 47 |
+
vocab_influence = scores['vocabulary']['normalized_score'] * 0.6
|
| 48 |
+
scores['cohesion']['normalized_score'] = max(
|
| 49 |
+
scores['cohesion']['normalized_score'],
|
| 50 |
+
vocab_influence
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# 3. Correlaci贸n cohesi贸n-claridad
|
| 54 |
+
# La claridad no puede superar cohesi贸n * 1.2
|
| 55 |
+
max_clarity = scores['cohesion']['normalized_score'] * 1.2
|
| 56 |
+
if scores['clarity']['normalized_score'] > max_clarity:
|
| 57 |
+
scores['clarity']['normalized_score'] = max_clarity
|
| 58 |
+
|
| 59 |
+
# 4. Correlaci贸n estructura-claridad
|
| 60 |
+
# La claridad no puede superar estructura * 1.1
|
| 61 |
+
struct_max_clarity = scores['structure']['normalized_score'] * 1.1
|
| 62 |
+
scores['clarity']['normalized_score'] = min(
|
| 63 |
+
scores['clarity']['normalized_score'],
|
| 64 |
+
struct_max_clarity
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Normalizar todos los scores entre 0 y 1
|
| 68 |
+
for metric in scores:
|
| 69 |
+
scores[metric]['normalized_score'] = max(0.0, min(1.0, scores[metric]['normalized_score']))
|
| 70 |
+
|
| 71 |
+
return scores
|
| 72 |
+
|
| 73 |
+
except Exception as e:
|
| 74 |
+
logger.error(f"Error en correlate_metrics: {str(e)}")
|
| 75 |
+
return scores
|
| 76 |
+
|
| 77 |
+
##########################################################################
|
| 78 |
+
|
| 79 |
def analyze_text_dimensions(doc):
|
| 80 |
"""
|
| 81 |
+
Analiza las dimensiones principales del texto manteniendo correlaciones l贸gicas.
|
| 82 |
"""
|
| 83 |
try:
|
| 84 |
+
# Obtener scores iniciales
|
| 85 |
vocab_score, vocab_details = analyze_vocabulary_diversity(doc)
|
|
|
|
|
|
|
| 86 |
struct_score = analyze_structure(doc)
|
|
|
|
|
|
|
| 87 |
cohesion_score = analyze_cohesion(doc)
|
|
|
|
|
|
|
| 88 |
clarity_score, clarity_details = analyze_clarity(doc)
|
| 89 |
|
| 90 |
+
# Crear diccionario de scores inicial
|
| 91 |
+
scores = {
|
| 92 |
'vocabulary': {
|
| 93 |
'normalized_score': vocab_score,
|
| 94 |
'details': vocab_details
|
| 95 |
},
|
| 96 |
'structure': {
|
| 97 |
'normalized_score': struct_score,
|
| 98 |
+
'details': None
|
| 99 |
},
|
| 100 |
'cohesion': {
|
| 101 |
'normalized_score': cohesion_score,
|
| 102 |
+
'details': None
|
| 103 |
},
|
| 104 |
'clarity': {
|
| 105 |
'normalized_score': clarity_score,
|
|
|
|
| 107 |
}
|
| 108 |
}
|
| 109 |
|
| 110 |
+
# Ajustar correlaciones entre m茅tricas
|
| 111 |
+
adjusted_scores = correlate_metrics(scores)
|
| 112 |
+
|
| 113 |
+
# Logging para diagn贸stico
|
| 114 |
+
logger.info(f"""
|
| 115 |
+
Scores originales vs ajustados:
|
| 116 |
+
Vocabulario: {vocab_score:.2f} -> {adjusted_scores['vocabulary']['normalized_score']:.2f}
|
| 117 |
+
Estructura: {struct_score:.2f} -> {adjusted_scores['structure']['normalized_score']:.2f}
|
| 118 |
+
Cohesi贸n: {cohesion_score:.2f} -> {adjusted_scores['cohesion']['normalized_score']:.2f}
|
| 119 |
+
Claridad: {clarity_score:.2f} -> {adjusted_scores['clarity']['normalized_score']:.2f}
|
| 120 |
+
""")
|
| 121 |
+
|
| 122 |
+
return adjusted_scores
|
| 123 |
+
|
| 124 |
except Exception as e:
|
| 125 |
logger.error(f"Error en analyze_text_dimensions: {str(e)}")
|
| 126 |
return {
|
|
|
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
+
#############################################################################################
|
| 136 |
+
|
| 137 |
def analyze_clarity(doc):
|
| 138 |
"""
|
| 139 |
Analiza la claridad del texto considerando m煤ltiples factores.
|