Update modules/studentact/current_situation_analysis.py
Browse files
modules/studentact/current_situation_analysis.py
CHANGED
@@ -4,37 +4,40 @@ import streamlit as st
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
import networkx as nx
|
6 |
import seaborn as sns
|
|
|
|
|
|
|
|
|
7 |
import logging
|
8 |
|
9 |
logger = logging.getLogger(__name__)
|
10 |
|
11 |
def display_current_situation_visual(doc, metrics):
|
12 |
-
"""
|
13 |
-
Crea y muestra las visualizaciones del an谩lisis de situaci贸n actual.
|
14 |
-
Aprovecha los componentes visuales existentes del sistema.
|
15 |
-
"""
|
16 |
try:
|
17 |
-
# Contenedor principal para visualizaciones
|
18 |
with st.container():
|
19 |
-
# 1. Red de Vocabulario
|
20 |
st.subheader("Riqueza de Vocabulario")
|
21 |
vocabulary_graph = create_vocabulary_network(doc)
|
22 |
-
|
|
|
|
|
23 |
|
24 |
-
|
25 |
-
st.subheader("Estructura de Oraciones")
|
26 |
syntax_graph = create_syntax_complexity_graph(doc)
|
27 |
-
|
|
|
|
|
28 |
|
29 |
-
# 3. Cohesi贸n Textual
|
30 |
st.subheader("Cohesi贸n del Texto")
|
31 |
cohesion_map = create_cohesion_heatmap(doc)
|
32 |
-
|
33 |
-
|
|
|
|
|
34 |
except Exception as e:
|
35 |
logger.error(f"Error mostrando visualizaciones: {str(e)}")
|
36 |
st.error("Error al generar visualizaciones")
|
37 |
|
|
|
38 |
def analyze_text_dimensions(doc):
|
39 |
"""
|
40 |
Analiza las diferentes dimensiones del texto.
|
@@ -188,6 +191,56 @@ def create_vocabulary_network(doc):
|
|
188 |
plt.axis('off')
|
189 |
return fig
|
190 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
191 |
def create_syntax_complexity_graph(doc):
|
192 |
"""
|
193 |
Genera el diagrama de arco de complejidad sint谩ctica.
|
|
|
4 |
import matplotlib.pyplot as plt
|
5 |
import networkx as nx
|
6 |
import seaborn as sns
|
7 |
+
from collections import Counter
|
8 |
+
from itertools import combinations
|
9 |
+
import numpy as np
|
10 |
+
import matplotlib.patches as patches
|
11 |
import logging
|
12 |
|
13 |
logger = logging.getLogger(__name__)
|
14 |
|
15 |
def display_current_situation_visual(doc, metrics):
|
|
|
|
|
|
|
|
|
16 |
try:
|
|
|
17 |
with st.container():
|
|
|
18 |
st.subheader("Riqueza de Vocabulario")
|
19 |
vocabulary_graph = create_vocabulary_network(doc)
|
20 |
+
if vocabulary_graph:
|
21 |
+
st.pyplot(vocabulary_graph)
|
22 |
+
plt.close(vocabulary_graph)
|
23 |
|
24 |
+
st.subheader("Estructura de Oraciones")
|
|
|
25 |
syntax_graph = create_syntax_complexity_graph(doc)
|
26 |
+
if syntax_graph:
|
27 |
+
st.pyplot(syntax_graph)
|
28 |
+
plt.close(syntax_graph)
|
29 |
|
|
|
30 |
st.subheader("Cohesi贸n del Texto")
|
31 |
cohesion_map = create_cohesion_heatmap(doc)
|
32 |
+
if cohesion_map:
|
33 |
+
st.pyplot(cohesion_map)
|
34 |
+
plt.close(cohesion_map)
|
35 |
+
|
36 |
except Exception as e:
|
37 |
logger.error(f"Error mostrando visualizaciones: {str(e)}")
|
38 |
st.error("Error al generar visualizaciones")
|
39 |
|
40 |
+
|
41 |
def analyze_text_dimensions(doc):
|
42 |
"""
|
43 |
Analiza las diferentes dimensiones del texto.
|
|
|
191 |
plt.axis('off')
|
192 |
return fig
|
193 |
|
194 |
+
def create_cohesion_heatmap(doc):
|
195 |
+
"""
|
196 |
+
Genera un mapa de calor que muestra la cohesi贸n entre p谩rrafos/oraciones.
|
197 |
+
"""
|
198 |
+
try:
|
199 |
+
# Dividir en oraciones
|
200 |
+
sentences = list(doc.sents)
|
201 |
+
n_sentences = len(sentences)
|
202 |
+
|
203 |
+
if n_sentences < 2:
|
204 |
+
return None
|
205 |
+
|
206 |
+
# Crear matriz de similitud
|
207 |
+
similarity_matrix = np.zeros((n_sentences, n_sentences))
|
208 |
+
|
209 |
+
# Calcular similitud entre pares de oraciones
|
210 |
+
for i in range(n_sentences):
|
211 |
+
for j in range(n_sentences):
|
212 |
+
sent1_lemmas = {token.lemma_ for token in sentences[i]
|
213 |
+
if token.is_alpha and not token.is_stop}
|
214 |
+
sent2_lemmas = {token.lemma_ for token in sentences[j]
|
215 |
+
if token.is_alpha and not token.is_stop}
|
216 |
+
|
217 |
+
if sent1_lemmas and sent2_lemmas:
|
218 |
+
intersection = len(sent1_lemmas & sent2_words)
|
219 |
+
union = len(sent1_lemmas | sent2_words)
|
220 |
+
similarity_matrix[i, j] = intersection / union if union > 0 else 0
|
221 |
+
|
222 |
+
# Crear visualizaci贸n
|
223 |
+
fig, ax = plt.subplots(figsize=(10, 8))
|
224 |
+
|
225 |
+
sns.heatmap(similarity_matrix,
|
226 |
+
cmap='YlOrRd',
|
227 |
+
square=True,
|
228 |
+
xticklabels=False,
|
229 |
+
yticklabels=False,
|
230 |
+
cbar_kws={'label': 'Cohesi贸n'},
|
231 |
+
ax=ax)
|
232 |
+
|
233 |
+
plt.title("Mapa de Cohesi贸n Textual")
|
234 |
+
plt.xlabel("Oraciones")
|
235 |
+
plt.ylabel("Oraciones")
|
236 |
+
|
237 |
+
plt.tight_layout()
|
238 |
+
return fig
|
239 |
+
|
240 |
+
except Exception as e:
|
241 |
+
logger.error(f"Error en create_cohesion_heatmap: {str(e)}")
|
242 |
+
return None
|
243 |
+
|
244 |
def create_syntax_complexity_graph(doc):
|
245 |
"""
|
246 |
Genera el diagrama de arco de complejidad sint谩ctica.
|