AIdeaText commited on
Commit
5bd23d0
verified
1 Parent(s): 407e78c

Update modules/morphosyntax/morphosyntax_interface.py

Browse files
modules/morphosyntax/morphosyntax_interface.py CHANGED
@@ -172,19 +172,37 @@ def display_morphosyntax_interface(lang_code, nlp_models, morpho_t):
172
  logger.error(f"Error: {str(e)}")
173
 
174
 
175
- def display_morphosyntax_results(doc, morpho_t):
176
- """Muestra solo el diagrama de arco"""
177
- sentences = list(doc.sents)
178
- for i, sent in enumerate(sentences):
179
- try:
180
- st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
181
- html = displacy.render(sent, style="dep", options={"distance": 100})
182
- html = html.replace('height="375"', 'height="200"')
183
- html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
184
- html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"',
185
- lambda m: f'<g transform="translate({m.group(1)},50)"', html)
186
- html = f'<div class="arc-diagram-container">{html}</div>'
187
- st.write(html, unsafe_allow_html=True)
188
- except Exception as e:
189
- logger.error(f"Error en diagrama {i}: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
190
 
 
172
  logger.error(f"Error: {str(e)}")
173
 
174
 
175
+ def display_morphosyntax_results(result, lang_code, morpho_t):
176
+ """
177
+ Muestra solo el diagrama de arco.
178
+ Args:
179
+ result: Diccionario con el documento procesado y su an谩lisis
180
+ lang_code: C贸digo del idioma
181
+ morpho_t: Diccionario de traducciones
182
+ """
183
+ if result is None:
184
+ return
185
+
186
+ try:
187
+ doc = result['doc']
188
+ sentences = list(doc.sents)
189
+ for i, sent in enumerate(sentences):
190
+ try:
191
+ st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
192
+ html = displacy.render(sent, style="dep", options={
193
+ "distance": 100,
194
+ "arrow_spacing": 20,
195
+ "word_spacing": 30
196
+ })
197
+ html = html.replace('height="375"', 'height="200"')
198
+ html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
199
+ html = re.sub(r'<g [^>]*transform="translate\((\d+),(\d+)\)"',
200
+ lambda m: f'<g transform="translate({m.group(1)},50)"', html)
201
+ html = f'<div class="arc-diagram-container">{html}</div>'
202
+ st.write(html, unsafe_allow_html=True)
203
+ except Exception as e:
204
+ logger.error(f"Error en diagrama {i}: {str(e)}")
205
+ continue
206
+ except Exception as e:
207
+ logger.error(f"Error en display_morphosyntax_results: {str(e)}")
208