Spaces:
Running
Running
Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
|
@@ -181,10 +181,15 @@ 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 |
-
|
| 185 |
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
| 186 |
-
|
| 187 |
-
# 2.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
dep_translations = {
|
| 189 |
'es': {
|
| 190 |
'ROOT': 'RAÍZ', 'nsubj': 'sujeto nominal', 'obj': 'objeto', 'iobj': 'objeto indirecto',
|
|
@@ -220,10 +225,11 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
| 220 |
'goeswith': 'va avec', 'reparandum': 'réparation', 'punct': 'ponctuation'
|
| 221 |
}
|
| 222 |
}
|
|
|
|
|
|
|
|
|
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
# 3. Definir función para traducir la morfología
|
| 227 |
def translate_morph(morph_string, lang_code):
|
| 228 |
morph_translations = {
|
| 229 |
'es': {
|
|
@@ -250,43 +256,31 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
| 250 |
'Ger': 'Gérondif', 'Pres': 'Présent', 'Past': 'Passé', 'Fut': 'Futur', 'Perf': 'Parfait', 'Imp': 'Imparfait'
|
| 251 |
}
|
| 252 |
}
|
| 253 |
-
|
| 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.
|
| 265 |
column_mapping = {
|
| 266 |
-
'text':
|
| 267 |
-
'lemma':
|
| 268 |
-
'pos':
|
| 269 |
-
'dep':
|
| 270 |
-
'morph':
|
| 271 |
}
|
| 272 |
|
| 273 |
-
# 6.
|
| 274 |
morph_df = morph_df.rename(columns=column_mapping)
|
| 275 |
|
| 276 |
-
# 7.
|
| 277 |
-
|
| 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)
|
|
|
|
| 181 |
|
| 182 |
with col2:
|
| 183 |
with st.expander(morpho_t.get('morphological_analysis', 'Morphological Analysis'), expanded=True):
|
| 184 |
+
# 1. Crear el DataFrame inicial
|
| 185 |
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
| 186 |
+
|
| 187 |
+
# 2. Primero traducir el contenido usando las traducciones específicas
|
| 188 |
+
|
| 189 |
+
# 2.1 Traducir categorías gramaticales usando POS_TRANSLATIONS global
|
| 190 |
+
morph_df['pos'] = morph_df['pos'].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
|
| 191 |
+
|
| 192 |
+
# 2.2 Traducir dependencias usando traducciones específicas
|
| 193 |
dep_translations = {
|
| 194 |
'es': {
|
| 195 |
'ROOT': 'RAÍZ', 'nsubj': 'sujeto nominal', 'obj': 'objeto', 'iobj': 'objeto indirecto',
|
|
|
|
| 225 |
'goeswith': 'va avec', 'reparandum': 'réparation', 'punct': 'ponctuation'
|
| 226 |
}
|
| 227 |
}
|
| 228 |
+
|
| 229 |
+
############################## Aplicar traducciones a la columna 'dep' original
|
| 230 |
+
morph_df['dep'] = morph_df['dep'].map(lambda x: dep_translations[lang_code].get(x, x))
|
| 231 |
|
| 232 |
+
# 2.3 Traducir morfología usando traducciones específicas
|
|
|
|
|
|
|
| 233 |
def translate_morph(morph_string, lang_code):
|
| 234 |
morph_translations = {
|
| 235 |
'es': {
|
|
|
|
| 256 |
'Ger': 'Gérondif', 'Pres': 'Présent', 'Past': 'Passé', 'Fut': 'Futur', 'Perf': 'Parfait', 'Imp': 'Imparfait'
|
| 257 |
}
|
| 258 |
}
|
| 259 |
+
|
| 260 |
for key, value in morph_translations[lang_code].items():
|
| 261 |
morph_string = morph_string.replace(key, value)
|
| 262 |
return morph_string
|
| 263 |
|
| 264 |
# 4. Aplicar traducciones a las columnas originales antes de renombrarlas
|
|
|
|
|
|
|
| 265 |
morph_df['morph'] = morph_df['morph'].apply(lambda x: translate_morph(x, lang_code))
|
| 266 |
+
#morph_df['dep'] = morph_df['dep'].map(lambda x: dep_translations[lang_code].get(x, x))
|
| 267 |
+
#morph_df['morph'] = morph_df['morph'].apply(lambda x: translate_morph(x, lang_code))
|
| 268 |
|
| 269 |
|
| 270 |
+
# 5. Después renombrar las columnas usando las traducciones de la interfaz
|
| 271 |
column_mapping = {
|
| 272 |
+
'text': t['word'],
|
| 273 |
+
'lemma': t['lemma'],
|
| 274 |
+
'pos': t['grammatical_category'],
|
| 275 |
+
'dep': t['dependency'],
|
| 276 |
+
'morph': t['morphology']
|
| 277 |
}
|
| 278 |
|
| 279 |
+
# 6. Aplicar el renombrado
|
| 280 |
morph_df = morph_df.rename(columns=column_mapping)
|
| 281 |
|
| 282 |
+
# 7. Mostrar el DataFrame con todas las columnas traducidas
|
| 283 |
+
st.dataframe(morph_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
|
| 286 |
# Mostrar diagramas de arco (código existente)
|