Update modules/studentact/current_situation_analysis.py
Browse files
modules/studentact/current_situation_analysis.py
CHANGED
@@ -14,42 +14,62 @@ logger = logging.getLogger(__name__)
|
|
14 |
|
15 |
def analyze_text_dimensions(doc):
|
16 |
"""
|
17 |
-
Analiza las
|
18 |
|
19 |
Args:
|
20 |
doc: Documento procesado por spaCy
|
21 |
-
|
22 |
Returns:
|
23 |
dict: M茅tricas del an谩lisis
|
24 |
"""
|
25 |
try:
|
26 |
-
#
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
cohesion_score = analyze_cohesion(doc)
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
|
|
|
|
|
|
43 |
return {
|
44 |
-
'
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
'
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
}
|
52 |
-
|
53 |
except Exception as e:
|
54 |
logger.error(f"Error en analyze_text_dimensions: {str(e)}")
|
55 |
raise
|
@@ -95,31 +115,41 @@ def get_dependency_depths(token, depth=0):
|
|
95 |
depths.extend(get_dependency_depths(child, depth + 1))
|
96 |
return depths
|
97 |
|
98 |
-
def normalize_score(value, optimal_value=1.0, range_factor=2.0, optimal_length=None):
|
99 |
"""
|
100 |
Normaliza un valor a una escala de 0-1.
|
|
|
101 |
Args:
|
102 |
value: Valor a normalizar
|
103 |
-
optimal_value: Valor 贸ptimo de referencia
|
104 |
range_factor: Factor para ajustar el rango
|
105 |
optimal_length: Longitud 贸ptima (opcional)
|
|
|
|
|
|
|
|
|
106 |
"""
|
107 |
try:
|
108 |
-
if
|
|
|
|
|
|
|
|
|
|
|
109 |
# Usar optimal_length si est谩 definido
|
110 |
diff = abs(value - optimal_length)
|
111 |
max_diff = optimal_length * range_factor
|
112 |
return 1.0 - min(diff / max_diff, 1.0)
|
113 |
else:
|
114 |
# Usar optimal_value por defecto
|
115 |
-
diff = abs(value - optimal_value)
|
116 |
max_diff = optimal_value * range_factor
|
117 |
return 1.0 - min(diff / max_diff, 1.0)
|
|
|
118 |
except Exception as e:
|
119 |
logger.error(f"Error en normalize_score: {str(e)}")
|
120 |
return 0.0
|
121 |
|
122 |
-
|
123 |
# Funciones de generaci贸n de gr谩ficos
|
124 |
def generate_sentence_graphs(doc):
|
125 |
"""Genera visualizaciones de estructura de oraciones"""
|
|
|
14 |
|
15 |
def analyze_text_dimensions(doc):
|
16 |
"""
|
17 |
+
Analiza las dimensiones principales del texto.
|
18 |
|
19 |
Args:
|
20 |
doc: Documento procesado por spaCy
|
21 |
+
|
22 |
Returns:
|
23 |
dict: M茅tricas del an谩lisis
|
24 |
"""
|
25 |
try:
|
26 |
+
# An谩lisis de vocabulario
|
27 |
+
vocab_score = analyze_vocabulary_diversity(doc)
|
28 |
+
vocab_normalized = normalize_score(
|
29 |
+
value=vocab_score,
|
30 |
+
optimal_connections=len(doc) * 0.4 # 40% del total de palabras como conexiones 贸ptimas
|
31 |
+
)
|
32 |
+
|
33 |
+
# An谩lisis de estructura
|
34 |
+
struct_score = analyze_structure(doc)
|
35 |
+
struct_normalized = normalize_score(
|
36 |
+
value=struct_score,
|
37 |
+
optimal_length=20 # Longitud 贸ptima promedio de oraci贸n
|
38 |
+
)
|
39 |
+
|
40 |
+
# An谩lisis de cohesi贸n
|
41 |
cohesion_score = analyze_cohesion(doc)
|
42 |
+
cohesion_normalized = normalize_score(
|
43 |
+
value=cohesion_score,
|
44 |
+
optimal_value=0.7 # 70% de cohesi贸n como valor 贸ptimo
|
45 |
+
)
|
46 |
+
|
47 |
+
# An谩lisis de claridad
|
48 |
+
clarity_score = analyze_clarity(doc)
|
49 |
+
clarity_normalized = normalize_score(
|
50 |
+
value=clarity_score,
|
51 |
+
optimal_value=0.8 # 80% de claridad como valor 贸ptimo
|
52 |
+
)
|
53 |
+
|
54 |
return {
|
55 |
+
'vocabulary': {
|
56 |
+
'raw_score': vocab_score,
|
57 |
+
'normalized_score': vocab_normalized
|
58 |
+
},
|
59 |
+
'structure': {
|
60 |
+
'raw_score': struct_score,
|
61 |
+
'normalized_score': struct_normalized
|
62 |
+
},
|
63 |
+
'cohesion': {
|
64 |
+
'raw_score': cohesion_score,
|
65 |
+
'normalized_score': cohesion_normalized
|
66 |
+
},
|
67 |
+
'clarity': {
|
68 |
+
'raw_score': clarity_score,
|
69 |
+
'normalized_score': clarity_normalized
|
70 |
+
}
|
71 |
}
|
72 |
+
|
73 |
except Exception as e:
|
74 |
logger.error(f"Error en analyze_text_dimensions: {str(e)}")
|
75 |
raise
|
|
|
115 |
depths.extend(get_dependency_depths(child, depth + 1))
|
116 |
return depths
|
117 |
|
118 |
+
def normalize_score(value, optimal_value=1.0, range_factor=2.0, optimal_length=None, optimal_connections=None):
|
119 |
"""
|
120 |
Normaliza un valor a una escala de 0-1.
|
121 |
+
|
122 |
Args:
|
123 |
value: Valor a normalizar
|
124 |
+
optimal_value: Valor 贸ptimo de referencia
|
125 |
range_factor: Factor para ajustar el rango
|
126 |
optimal_length: Longitud 贸ptima (opcional)
|
127 |
+
optimal_connections: N煤mero 贸ptimo de conexiones (opcional)
|
128 |
+
|
129 |
+
Returns:
|
130 |
+
float: Valor normalizado entre 0 y 1
|
131 |
"""
|
132 |
try:
|
133 |
+
if optimal_connections is not None:
|
134 |
+
# Usar optimal_connections si est谩 definido
|
135 |
+
diff = abs(value - optimal_connections)
|
136 |
+
max_diff = optimal_connections * range_factor
|
137 |
+
return 1.0 - min(diff / max_diff, 1.0)
|
138 |
+
elif optimal_length is not None:
|
139 |
# Usar optimal_length si est谩 definido
|
140 |
diff = abs(value - optimal_length)
|
141 |
max_diff = optimal_length * range_factor
|
142 |
return 1.0 - min(diff / max_diff, 1.0)
|
143 |
else:
|
144 |
# Usar optimal_value por defecto
|
145 |
+
diff = abs(value - optimal_value)
|
146 |
max_diff = optimal_value * range_factor
|
147 |
return 1.0 - min(diff / max_diff, 1.0)
|
148 |
+
|
149 |
except Exception as e:
|
150 |
logger.error(f"Error en normalize_score: {str(e)}")
|
151 |
return 0.0
|
152 |
|
|
|
153 |
# Funciones de generaci贸n de gr谩ficos
|
154 |
def generate_sentence_graphs(doc):
|
155 |
"""Genera visualizaciones de estructura de oraciones"""
|