Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -114,7 +114,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
114 |
arc_diagrams=analysis['arc_diagrams']
|
115 |
):
|
116 |
# Mostrar diagrama original
|
117 |
-
|
118 |
|
119 |
st.markdown("---")
|
120 |
|
@@ -157,7 +157,7 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
157 |
text=iteration_text,
|
158 |
arc_diagrams=analysis['arc_diagrams']
|
159 |
):
|
160 |
-
|
161 |
|
162 |
except Exception as e:
|
163 |
st.error("Error al procesar iteraci贸n")
|
@@ -171,55 +171,19 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
|
|
171 |
st.error("Error general en la interfaz")
|
172 |
logger.error(f"Error: {str(e)}")
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
doc = result['doc']
|
190 |
-
|
191 |
-
with st.container():
|
192 |
-
sentences = list(doc.sents)
|
193 |
-
for i, sent in enumerate(sentences):
|
194 |
-
try:
|
195 |
-
st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
|
196 |
-
|
197 |
-
# Renderizar con opciones optimizadas
|
198 |
-
html = displacy.render(sent, style="dep", options={
|
199 |
-
"distance": 100,
|
200 |
-
"arrow_spacing": 20,
|
201 |
-
"word_spacing": 30
|
202 |
-
})
|
203 |
-
|
204 |
-
# Ajustar dimensiones del SVG
|
205 |
-
html = html.replace('height="375"', 'height="200"')
|
206 |
-
html = re.sub(r'<svg[^>]*>',
|
207 |
-
lambda m: m.group(0).replace('height="450"', 'height="300"'),
|
208 |
-
html)
|
209 |
-
html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"',
|
210 |
-
lambda m: f'<g transform="translate({m.group(1)},50)"',
|
211 |
-
html)
|
212 |
-
|
213 |
-
# Envolver en contenedor con clase CSS
|
214 |
-
html = f'<div class="arc-diagram-container">{html}</div>'
|
215 |
-
|
216 |
-
# Mostrar diagrama
|
217 |
-
st.write(html, unsafe_allow_html=True)
|
218 |
-
|
219 |
-
except Exception as e:
|
220 |
-
logger.error(f"Error al renderizar oraci贸n {i}: {str(e)}")
|
221 |
-
continue # Continuar con la siguiente oraci贸n si hay error
|
222 |
-
|
223 |
-
except Exception as e:
|
224 |
-
logger.error(f"Error general en display_morphosyntax_results: {str(e)}")
|
225 |
|
|
|
114 |
arc_diagrams=analysis['arc_diagrams']
|
115 |
):
|
116 |
# Mostrar diagrama original
|
117 |
+
display_morphosyntax_results({'doc': doc, 'analysis': analysis}, lang_code, morpho_t)
|
118 |
|
119 |
st.markdown("---")
|
120 |
|
|
|
157 |
text=iteration_text,
|
158 |
arc_diagrams=analysis['arc_diagrams']
|
159 |
):
|
160 |
+
display_morphosyntax_results({'doc': doc, 'analysis': analysis}, lang_code, morpho_t)
|
161 |
|
162 |
except Exception as e:
|
163 |
st.error("Error al procesar iteraci贸n")
|
|
|
171 |
st.error("Error general en la interfaz")
|
172 |
logger.error(f"Error: {str(e)}")
|
173 |
|
174 |
+
def display_arc_diagram(doc, morpho_t):
|
175 |
+
"""Muestra solo el diagrama de arco"""
|
176 |
+
sentences = list(doc.sents)
|
177 |
+
for i, sent in enumerate(sentences):
|
178 |
+
try:
|
179 |
+
st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
|
180 |
+
html = displacy.render(sent, style="dep", options={"distance": 100})
|
181 |
+
html = html.replace('height="375"', 'height="200"')
|
182 |
+
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|
183 |
+
html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"',
|
184 |
+
lambda m: f'<g transform="translate({m.group(1)},50)"', html)
|
185 |
+
html = f'<div class="arc-diagram-container">{html}</div>'
|
186 |
+
st.write(html, unsafe_allow_html=True)
|
187 |
+
except Exception as e:
|
188 |
+
logger.error(f"Error en diagrama {i}: {str(e)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
189 |
|