Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -181,9 +181,10 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
181 |
|
182 |
with col2:
|
183 |
with st.expander(morpho_t.get('morphological_analysis', 'Morphological Analysis'), expanded=True):
|
|
|
184 |
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
185 |
|
186 |
-
#
|
187 |
dep_translations = {
|
188 |
'es': {
|
189 |
'ROOT': 'RAÍZ', 'nsubj': 'sujeto nominal', 'obj': 'objeto', 'iobj': 'objeto indirecto',
|
@@ -222,7 +223,7 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
222 |
|
223 |
morph_df[t['dependency']] = morph_df[t['dependency']].map(lambda x: dep_translations[lang_code].get(x, x))
|
224 |
|
225 |
-
#
|
226 |
def translate_morph(morph_string, lang_code):
|
227 |
morph_translations = {
|
228 |
'es': {
|
@@ -253,8 +254,14 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
253 |
for key, value in morph_translations[lang_code].items():
|
254 |
morph_string = morph_string.replace(key, value)
|
255 |
return morph_string
|
256 |
-
|
257 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
258 |
column_mapping = {
|
259 |
'text': morpho_t.get('word', 'Word'),
|
260 |
'lemma': morpho_t.get('lemma', 'Lemma'),
|
@@ -263,31 +270,24 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
263 |
'morph': morpho_t.get('morphology', 'Morphology')
|
264 |
}
|
265 |
|
266 |
-
# Renombrar las columnas
|
267 |
-
morph_df = morph_df.rename(columns=
|
268 |
|
269 |
-
# Definir
|
270 |
-
cat_col = morpho_t.get('grammatical_category', 'Grammatical category')
|
271 |
-
dep_col = morpho_t.get('dependency', 'Dependency')
|
272 |
-
morph_col = morpho_t.get('morphology', 'Morphology')
|
273 |
-
|
274 |
-
# Aplicar traducciones
|
275 |
-
morph_df[cat_col] = morph_df[cat_col].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
|
276 |
-
morph_df[dep_col] = morph_df[dep_col].map(lambda x: dep_translations[lang_code].get(x, x))
|
277 |
-
morph_df[morph_col] = morph_df[morph_col].apply(lambda x: translate_morph(x, lang_code))
|
278 |
-
|
279 |
-
# Seleccionar y ordenar las columnas a mostrar
|
280 |
columns_to_display = [
|
281 |
morpho_t.get('word', 'Word'),
|
282 |
morpho_t.get('lemma', 'Lemma'),
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
]
|
|
|
|
|
287 |
columns_to_display = [col for col in columns_to_display if col in morph_df.columns]
|
288 |
-
|
289 |
-
# Mostrar el DataFrame
|
290 |
st.dataframe(morph_df[columns_to_display])
|
|
|
291 |
|
292 |
# Mostrar diagramas de arco (código existente)
|
293 |
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|
|
|
181 |
|
182 |
with col2:
|
183 |
with st.expander(morpho_t.get('morphological_analysis', 'Morphological Analysis'), expanded=True):
|
184 |
+
# 1. Crear el DataFrame inicial desde el análisis morfológico
|
185 |
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
186 |
|
187 |
+
# 2. Definir las traducciones específicas para dependencias
|
188 |
dep_translations = {
|
189 |
'es': {
|
190 |
'ROOT': 'RAÍZ', 'nsubj': 'sujeto nominal', 'obj': 'objeto', 'iobj': 'objeto indirecto',
|
|
|
223 |
|
224 |
morph_df[t['dependency']] = morph_df[t['dependency']].map(lambda x: dep_translations[lang_code].get(x, x))
|
225 |
|
226 |
+
# 3. Definir función para traducir la morfología
|
227 |
def translate_morph(morph_string, lang_code):
|
228 |
morph_translations = {
|
229 |
'es': {
|
|
|
254 |
for key, value in morph_translations[lang_code].items():
|
255 |
morph_string = morph_string.replace(key, value)
|
256 |
return morph_string
|
257 |
+
|
258 |
+
# 4. Aplicar traducciones a las columnas originales antes de renombrarlas
|
259 |
+
morph_df['pos'] = morph_df['pos'].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
|
260 |
+
morph_df['dep'] = morph_df['dep'].map(lambda x: dep_translations[lang_code].get(x, x))
|
261 |
+
morph_df['morph'] = morph_df['morph'].apply(lambda x: translate_morph(x, lang_code))
|
262 |
+
|
263 |
+
|
264 |
+
# 5. Definir el mapeo para los nombres de las columnas usando las traducciones de la interfaz
|
265 |
column_mapping = {
|
266 |
'text': morpho_t.get('word', 'Word'),
|
267 |
'lemma': morpho_t.get('lemma', 'Lemma'),
|
|
|
270 |
'morph': morpho_t.get('morphology', 'Morphology')
|
271 |
}
|
272 |
|
273 |
+
# 6. Renombrar las columnas
|
274 |
+
morph_df = morph_df.rename(columns=column_mapping)
|
275 |
|
276 |
+
# 7. Definir las columnas a mostrar usando los nombres traducidos
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
277 |
columns_to_display = [
|
278 |
morpho_t.get('word', 'Word'),
|
279 |
morpho_t.get('lemma', 'Lemma'),
|
280 |
+
morpho_t.get('grammatical_category', 'Grammatical category'),
|
281 |
+
morpho_t.get('dependency', 'Dependency'),
|
282 |
+
morpho_t.get('morphology', 'Morphology')
|
283 |
]
|
284 |
+
|
285 |
+
# 8. Filtrar las columnas que existen en el DataFrame
|
286 |
columns_to_display = [col for col in columns_to_display if col in morph_df.columns]
|
287 |
+
|
288 |
+
# 9. Mostrar el DataFrame
|
289 |
st.dataframe(morph_df[columns_to_display])
|
290 |
+
|
291 |
|
292 |
# Mostrar diagramas de arco (código existente)
|
293 |
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|