Update modules/ui/ui.py
Browse filesEsta actualización incluye los siguientes cambios principales:
Se han añadido nuevas traducciones para los nuevos elementos de análisis.
Se utiliza la función perform_advanced_morphosyntactic_analysis del módulo morph_analysis.py para obtener el análisis avanzado.
Se muestran los nuevos análisis (categorías gramaticales, análisis morfológico y estructura de oraciones) utilizando expanders de Streamlit.
Se ha actualizado la función store_morphosyntax_result para incluir los nuevos datos de análisis.
- modules/ui/ui.py +75 -5
modules/ui/ui.py
CHANGED
|
@@ -359,7 +359,22 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 359 |
'sentence': "Oración",
|
| 360 |
'success_message': "Análisis guardado correctamente.",
|
| 361 |
'error_message': "Hubo un problema al guardar el análisis. Por favor, inténtelo de nuevo.",
|
| 362 |
-
'warning_message': "Por favor, ingrese un texto para analizar."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 363 |
},
|
| 364 |
'en': {
|
| 365 |
'title': "AIdeaText - Morphological and Syntactic Analysis",
|
|
@@ -372,7 +387,22 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 372 |
'sentence': "Sentence",
|
| 373 |
'success_message': "Analysis saved successfully.",
|
| 374 |
'error_message': "There was a problem saving the analysis. Please try again.",
|
| 375 |
-
'warning_message': "Please enter a text to analyze."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
},
|
| 377 |
'fr': {
|
| 378 |
'title': "AIdeaText - Analyse morphologique et syntaxique",
|
|
@@ -385,7 +415,22 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 385 |
'sentence': "Phrase",
|
| 386 |
'success_message': "Analyse enregistrée avec succès.",
|
| 387 |
'error_message': "Un problème est survenu lors de l'enregistrement de l'analyse. Veuillez réessayer.",
|
| 388 |
-
'warning_message': "Veuillez entrer un texte à analyser."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 389 |
}
|
| 390 |
}
|
| 391 |
|
|
@@ -409,13 +454,17 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 409 |
current_input = st.session_state[input_key]
|
| 410 |
if current_input:
|
| 411 |
doc = nlp_models[lang_code](current_input)
|
| 412 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 413 |
word_colors = get_repeated_words_colors(doc)
|
| 414 |
-
|
| 415 |
with st.expander(t['repeated_words'], expanded=True):
|
| 416 |
highlighted_text = highlight_repeated_words(doc, word_colors)
|
| 417 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 418 |
|
|
|
|
| 419 |
st.markdown(f"##### {t['legend']}")
|
| 420 |
legend_html = "<div style='display: flex; flex-wrap: wrap;'>"
|
| 421 |
for pos, color in POS_COLORS.items():
|
|
@@ -423,7 +472,27 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 423 |
legend_html += f"<div style='margin-right: 10px;'><span style='background-color: {color}; padding: 2px 5px;'>{POS_TRANSLATIONS[lang_code][pos]}</span></div>"
|
| 424 |
legend_html += "</div>"
|
| 425 |
st.markdown(legend_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
|
|
|
|
| 427 |
with st.expander(t['arc_diagram'], expanded=True):
|
| 428 |
sentences = list(doc.sents)
|
| 429 |
arc_diagrams = []
|
|
@@ -436,6 +505,7 @@ def display_morphosyntax_analysis_interface(nlp_models, lang_code):
|
|
| 436 |
st.write(html, unsafe_allow_html=True)
|
| 437 |
arc_diagrams.append(html)
|
| 438 |
|
|
|
|
| 439 |
if store_morphosyntax_result(
|
| 440 |
st.session_state.username,
|
| 441 |
current_input,
|
|
|
|
| 359 |
'sentence': "Oración",
|
| 360 |
'success_message': "Análisis guardado correctamente.",
|
| 361 |
'error_message': "Hubo un problema al guardar el análisis. Por favor, inténtelo de nuevo.",
|
| 362 |
+
'warning_message': "Por favor, ingrese un texto para analizar.",
|
| 363 |
+
'pos_analysis': "Análisis de categorías gramaticales",
|
| 364 |
+
'morphological_analysis': "Análisis morfológico",
|
| 365 |
+
'sentence_structure': "Estructura de oraciones",
|
| 366 |
+
'word': "Palabra",
|
| 367 |
+
'count': "Cantidad",
|
| 368 |
+
'percentage': "Porcentaje",
|
| 369 |
+
'examples': "Ejemplos",
|
| 370 |
+
'lemma': "Lema",
|
| 371 |
+
'tag': "Etiqueta",
|
| 372 |
+
'dep': "Dependencia",
|
| 373 |
+
'morph': "Morfología",
|
| 374 |
+
'root': "Raíz",
|
| 375 |
+
'subjects': "Sujetos",
|
| 376 |
+
'objects': "Objetos",
|
| 377 |
+
'verbs': "Verbos"
|
| 378 |
},
|
| 379 |
'en': {
|
| 380 |
'title': "AIdeaText - Morphological and Syntactic Analysis",
|
|
|
|
| 387 |
'sentence': "Sentence",
|
| 388 |
'success_message': "Analysis saved successfully.",
|
| 389 |
'error_message': "There was a problem saving the analysis. Please try again.",
|
| 390 |
+
'warning_message': "Please enter a text to analyze.",
|
| 391 |
+
'pos_analysis': "Part of Speech Analysis",
|
| 392 |
+
'morphological_analysis': "Morphological Analysis",
|
| 393 |
+
'sentence_structure': "Sentence Structure",
|
| 394 |
+
'word': "Word",
|
| 395 |
+
'count': "Count",
|
| 396 |
+
'percentage': "Percentage",
|
| 397 |
+
'examples': "Examples",
|
| 398 |
+
'lemma': "Lemma",
|
| 399 |
+
'tag': "Tag",
|
| 400 |
+
'dep': "Dependency",
|
| 401 |
+
'morph': "Morphology",
|
| 402 |
+
'root': "Root",
|
| 403 |
+
'subjects': "Subjects",
|
| 404 |
+
'objects': "Objects",
|
| 405 |
+
'verbs': "Verbs"
|
| 406 |
},
|
| 407 |
'fr': {
|
| 408 |
'title': "AIdeaText - Analyse morphologique et syntaxique",
|
|
|
|
| 415 |
'sentence': "Phrase",
|
| 416 |
'success_message': "Analyse enregistrée avec succès.",
|
| 417 |
'error_message': "Un problème est survenu lors de l'enregistrement de l'analyse. Veuillez réessayer.",
|
| 418 |
+
'warning_message': "Veuillez entrer un texte à analyser.",
|
| 419 |
+
'pos_analysis': "Analyse des parties du discours",
|
| 420 |
+
'morphological_analysis': "Analyse morphologique",
|
| 421 |
+
'sentence_structure': "Structure des phrases",
|
| 422 |
+
'word': "Mot",
|
| 423 |
+
'count': "Nombre",
|
| 424 |
+
'percentage': "Pourcentage",
|
| 425 |
+
'examples': "Exemples",
|
| 426 |
+
'lemma': "Lemme",
|
| 427 |
+
'tag': "Étiquette",
|
| 428 |
+
'dep': "Dépendance",
|
| 429 |
+
'morph': "Morphologie",
|
| 430 |
+
'root': "Racine",
|
| 431 |
+
'subjects': "Sujets",
|
| 432 |
+
'objects': "Objets",
|
| 433 |
+
'verbs': "Verbes"
|
| 434 |
}
|
| 435 |
}
|
| 436 |
|
|
|
|
| 454 |
current_input = st.session_state[input_key]
|
| 455 |
if current_input:
|
| 456 |
doc = nlp_models[lang_code](current_input)
|
| 457 |
+
|
| 458 |
+
# Análisis morfosintáctico avanzado
|
| 459 |
+
advanced_analysis = perform_advanced_morphosyntactic_analysis(current_input, nlp_models[lang_code])
|
| 460 |
+
|
| 461 |
+
# Mostrar análisis de palabras repetidas (código existente)
|
| 462 |
word_colors = get_repeated_words_colors(doc)
|
|
|
|
| 463 |
with st.expander(t['repeated_words'], expanded=True):
|
| 464 |
highlighted_text = highlight_repeated_words(doc, word_colors)
|
| 465 |
st.markdown(highlighted_text, unsafe_allow_html=True)
|
| 466 |
|
| 467 |
+
# Mostrar leyenda (código existente)
|
| 468 |
st.markdown(f"##### {t['legend']}")
|
| 469 |
legend_html = "<div style='display: flex; flex-wrap: wrap;'>"
|
| 470 |
for pos, color in POS_COLORS.items():
|
|
|
|
| 472 |
legend_html += f"<div style='margin-right: 10px;'><span style='background-color: {color}; padding: 2px 5px;'>{POS_TRANSLATIONS[lang_code][pos]}</span></div>"
|
| 473 |
legend_html += "</div>"
|
| 474 |
st.markdown(legend_html, unsafe_allow_html=True)
|
| 475 |
+
|
| 476 |
+
# Mostrar análisis de categorías gramaticales
|
| 477 |
+
with st.expander(t['pos_analysis'], expanded=True):
|
| 478 |
+
pos_df = pd.DataFrame(advanced_analysis['pos_analysis'])
|
| 479 |
+
st.dataframe(pos_df)
|
| 480 |
+
|
| 481 |
+
# Mostrar análisis morfológico
|
| 482 |
+
with st.expander(t['morphological_analysis'], expanded=True):
|
| 483 |
+
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
| 484 |
+
st.dataframe(morph_df)
|
| 485 |
+
|
| 486 |
+
# Mostrar estructura de oraciones
|
| 487 |
+
with st.expander(t['sentence_structure'], expanded=True):
|
| 488 |
+
for i, sent_analysis in enumerate(advanced_analysis['sentence_structure']):
|
| 489 |
+
st.subheader(f"{t['sentence']} {i+1}")
|
| 490 |
+
st.write(f"{t['root']}: {sent_analysis['root']} ({sent_analysis['root_pos']})")
|
| 491 |
+
st.write(f"{t['subjects']}: {', '.join(sent_analysis['subjects'])}")
|
| 492 |
+
st.write(f"{t['objects']}: {', '.join(sent_analysis['objects'])}")
|
| 493 |
+
st.write(f"{t['verbs']}: {', '.join(sent_analysis['verbs'])}")
|
| 494 |
|
| 495 |
+
# Mostrar diagramas de arco (código existente)
|
| 496 |
with st.expander(t['arc_diagram'], expanded=True):
|
| 497 |
sentences = list(doc.sents)
|
| 498 |
arc_diagrams = []
|
|
|
|
| 505 |
st.write(html, unsafe_allow_html=True)
|
| 506 |
arc_diagrams.append(html)
|
| 507 |
|
| 508 |
+
# Guardar resultados
|
| 509 |
if store_morphosyntax_result(
|
| 510 |
st.session_state.username,
|
| 511 |
current_input,
|