AIdeaText commited on
Commit
e1b8d97
·
verified ·
1 Parent(s): ccf055d

Update modules/morphosyntax/morphosyntax_interface.py

Browse files
modules/morphosyntax/morphosyntax_interface.py CHANGED
@@ -182,45 +182,7 @@ def display_morphosyntax_results(result, lang_code, t):
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
- # Definir el mapeo de columnas
187
- column_mapping = {
188
- 'text': morpho_t.get('word', 'Word'),
189
- 'lemma': morpho_t.get('lemma', 'Lemma'),
190
- 'pos': morpho_t.get('grammatical_category', 'Grammatical category'),
191
- 'dep': morpho_t.get('dependency', 'Dependency'),
192
- 'morph': morpho_t.get('morphology', 'Morphology')
193
- }
194
-
195
- # Renombrar las columnas existentes
196
- morph_df = morph_df.rename(columns={col: new_name for col, new_name in column_mapping.items() if col in morph_df.columns})
197
-
198
- # Primero definimos las columnas con morpho_t
199
- cat_col = morpho_t.get('grammatical_category', 'Grammatical category')
200
- dep_col = morpho_t.get('dependency', 'Dependency')
201
- morph_col = morpho_t.get('morphology', 'Morphology')
202
-
203
- # Luego las usamos en las transformaciones
204
- morph_df[cat_col] = morph_df[cat_col].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
205
- morph_df[dep_col] = morph_df[dep_col].map(lambda x: dep_translations[lang_code].get(x, x))
206
- morph_df[morph_col] = morph_df[morph_col].apply(lambda x: translate_morph(x, lang_code))
207
-
208
- # Seleccionar y ordenar las columnas a mostrar
209
- columns_to_display = [
210
- morpho_t.get('word', 'Word'),
211
- morpho_t.get('lemma', 'Lemma'),
212
- cat_col,
213
- dep_col,
214
- morph_col
215
- ]
216
- columns_to_display = [col for col in columns_to_display if col in morph_df.columns]
217
-
218
- # Mostrar el DataFrame
219
- st.dataframe(morph_df[columns_to_display])
220
-
221
- # Traducir las categorías gramaticales
222
- morph_df[t['grammatical_category']] = morph_df[t['grammatical_category']].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
223
-
224
  # Traducir las dependencias
225
  dep_translations = {
226
  'es': {
@@ -287,10 +249,46 @@ def display_morphosyntax_results(result, lang_code, t):
287
  'Ger': 'Gérondif', 'Pres': 'Présent', 'Past': 'Passé', 'Fut': 'Futur', 'Perf': 'Parfait', 'Imp': 'Imparfait'
288
  }
289
  }
 
290
  for key, value in morph_translations[lang_code].items():
291
  morph_string = morph_string.replace(key, value)
292
  return morph_string
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  morph_df[t['morphology']] = morph_df[t['morphology']].apply(lambda x: translate_morph(x, lang_code))
295
 
296
  # Seleccionar y ordenar las columnas a mostrar
 
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
  # Traducir las dependencias
187
  dep_translations = {
188
  'es': {
 
249
  'Ger': 'Gérondif', 'Pres': 'Présent', 'Past': 'Passé', 'Fut': 'Futur', 'Perf': 'Parfait', 'Imp': 'Imparfait'
250
  }
251
  }
252
+
253
  for key, value in morph_translations[lang_code].items():
254
  morph_string = morph_string.replace(key, value)
255
  return morph_string
256
 
257
+ # Definir el mapeo de columnas
258
+ column_mapping = {
259
+ 'text': morpho_t.get('word', 'Word'),
260
+ 'lemma': morpho_t.get('lemma', 'Lemma'),
261
+ 'pos': morpho_t.get('grammatical_category', 'Grammatical category'),
262
+ 'dep': morpho_t.get('dependency', 'Dependency'),
263
+ 'morph': morpho_t.get('morphology', 'Morphology')
264
+ }
265
+
266
+ # Renombrar las columnas existentes
267
+ morph_df = morph_df.rename(columns={col: new_name for col, new_name in column_mapping.items() if col in morph_df.columns})
268
+
269
+ # Primero definimos las columnas con morpho_t
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
+ # Luego las usamos en las transformaciones
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
+ cat_col,
284
+ dep_col,
285
+ morph_col
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
  morph_df[t['morphology']] = morph_df[t['morphology']].apply(lambda x: translate_morph(x, lang_code))
293
 
294
  # Seleccionar y ordenar las columnas a mostrar