Update modules/morphosyntax/morphosyntax_interface.py
Browse files
modules/morphosyntax/morphosyntax_interface.py
CHANGED
@@ -168,31 +168,54 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
168 |
|
169 |
# Renombrar las columnas para mayor claridad
|
170 |
pos_df = pos_df.rename(columns={
|
171 |
-
'pos':
|
172 |
-
'count':
|
173 |
-
'percentage':
|
174 |
-
'examples':
|
175 |
})
|
176 |
-
|
177 |
# Mostrar el dataframe
|
178 |
st.dataframe(pos_df)
|
179 |
|
180 |
with col2:
|
181 |
-
with st.expander(morpho_t.get('morphological_analysis', 'Morphological Analysis'
|
182 |
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
183 |
|
184 |
# Definir el mapeo de columnas
|
185 |
column_mapping = {
|
186 |
-
'text':
|
187 |
-
'lemma':
|
188 |
-
'pos':
|
189 |
-
'dep':
|
190 |
-
'morph':
|
191 |
}
|
192 |
|
193 |
# Renombrar las columnas existentes
|
194 |
morph_df = morph_df.rename(columns={col: new_name for col, new_name in column_mapping.items() if col in morph_df.columns})
|
195 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
# Traducir las categor铆as gramaticales
|
197 |
morph_df[t['grammatical_category']] = morph_df[t['grammatical_category']].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
|
198 |
|
@@ -232,6 +255,7 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
232 |
'goeswith': 'va avec', 'reparandum': 'r茅paration', 'punct': 'ponctuation'
|
233 |
}
|
234 |
}
|
|
|
235 |
morph_df[t['dependency']] = morph_df[t['dependency']].map(lambda x: dep_translations[lang_code].get(x, x))
|
236 |
|
237 |
# Traducir la morfolog铆a
|
@@ -268,18 +292,24 @@ def display_morphosyntax_results(result, lang_code, t):
|
|
268 |
morph_df[t['morphology']] = morph_df[t['morphology']].apply(lambda x: translate_morph(x, lang_code))
|
269 |
|
270 |
# Seleccionar y ordenar las columnas a mostrar
|
271 |
-
columns_to_display = [
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
columns_to_display = [col for col in columns_to_display if col in morph_df.columns]
|
273 |
|
274 |
# Mostrar el DataFrame
|
275 |
st.dataframe(morph_df[columns_to_display])
|
276 |
|
277 |
# Mostrar diagramas de arco (c贸digo existente)
|
278 |
-
with st.expander(
|
279 |
sentences = list(doc.sents)
|
280 |
arc_diagrams = []
|
281 |
for i, sent in enumerate(sentences):
|
282 |
-
st.subheader(f"{
|
283 |
html = displacy.render(sent, style="dep", options={"distance": 100})
|
284 |
html = html.replace('height="375"', 'height="200"')
|
285 |
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|
|
|
168 |
|
169 |
# Renombrar las columnas para mayor claridad
|
170 |
pos_df = pos_df.rename(columns={
|
171 |
+
'pos': morpho_t.get('grammatical_category', 'Grammatical category'),
|
172 |
+
'count': morpho_t.get('count', 'Count'),
|
173 |
+
'percentage': morpho_t.get('percentage', 'Percentage'),
|
174 |
+
'examples': morpho_t.get('examples', 'Examples')
|
175 |
})
|
176 |
+
|
177 |
# Mostrar el dataframe
|
178 |
st.dataframe(pos_df)
|
179 |
|
180 |
with col2:
|
181 |
+
with st.expander(morpho_t.get('morphological_analysis', 'Morphological Analysis'), expanded=True):
|
182 |
morph_df = pd.DataFrame(advanced_analysis['morphological_analysis'])
|
183 |
|
184 |
# Definir el mapeo de columnas
|
185 |
column_mapping = {
|
186 |
+
'text': morpho_t.get('word', 'Word'),
|
187 |
+
'lemma': morpho_t.get('lemma', 'Lemma'),
|
188 |
+
'pos': morpho_t.get('grammatical_category', 'Grammatical category'),
|
189 |
+
'dep': morpho_t.get('dependency', 'Dependency'),
|
190 |
+
'morph': morpho_t.get('morphology', 'Morphology')
|
191 |
}
|
192 |
|
193 |
# Renombrar las columnas existentes
|
194 |
morph_df = morph_df.rename(columns={col: new_name for col, new_name in column_mapping.items() if col in morph_df.columns})
|
195 |
|
196 |
+
# Primero definimos las columnas con morpho_t
|
197 |
+
cat_col = morpho_t.get('grammatical_category', 'Grammatical category')
|
198 |
+
dep_col = morpho_t.get('dependency', 'Dependency')
|
199 |
+
morph_col = morpho_t.get('morphology', 'Morphology')
|
200 |
+
|
201 |
+
# Luego las usamos en las transformaciones
|
202 |
+
morph_df[cat_col] = morph_df[cat_col].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
|
203 |
+
morph_df[dep_col] = morph_df[dep_col].map(lambda x: dep_translations[lang_code].get(x, x))
|
204 |
+
morph_df[morph_col] = morph_df[morph_col].apply(lambda x: translate_morph(x, lang_code))
|
205 |
+
|
206 |
+
# Seleccionar y ordenar las columnas a mostrar
|
207 |
+
columns_to_display = [
|
208 |
+
morpho_t.get('word', 'Word'),
|
209 |
+
morpho_t.get('lemma', 'Lemma'),
|
210 |
+
cat_col,
|
211 |
+
dep_col,
|
212 |
+
morph_col
|
213 |
+
]
|
214 |
+
columns_to_display = [col for col in columns_to_display if col in morph_df.columns]
|
215 |
+
|
216 |
+
# Mostrar el DataFrame
|
217 |
+
st.dataframe(morph_df[columns_to_display])
|
218 |
+
|
219 |
# Traducir las categor铆as gramaticales
|
220 |
morph_df[t['grammatical_category']] = morph_df[t['grammatical_category']].map(lambda x: POS_TRANSLATIONS[lang_code].get(x, x))
|
221 |
|
|
|
255 |
'goeswith': 'va avec', 'reparandum': 'r茅paration', 'punct': 'ponctuation'
|
256 |
}
|
257 |
}
|
258 |
+
|
259 |
morph_df[t['dependency']] = morph_df[t['dependency']].map(lambda x: dep_translations[lang_code].get(x, x))
|
260 |
|
261 |
# Traducir la morfolog铆a
|
|
|
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
|
295 |
+
columns_to_display = [
|
296 |
+
morpho_t.get('word', 'Word'),
|
297 |
+
morpho_t.get('lemma', 'Lemma'),
|
298 |
+
morpho_t.get('grammatical_category', 'Grammatical category'),
|
299 |
+
morpho_t.get('dependency', 'Dependency'),
|
300 |
+
morpho_t.get('morphology', 'Morphology')
|
301 |
+
]
|
302 |
columns_to_display = [col for col in columns_to_display if col in morph_df.columns]
|
303 |
|
304 |
# Mostrar el DataFrame
|
305 |
st.dataframe(morph_df[columns_to_display])
|
306 |
|
307 |
# Mostrar diagramas de arco (c贸digo existente)
|
308 |
+
with st.expander(morpho_t.get('arc_diagram', 'Syntactic analysis: Arc diagram'), expanded=True):
|
309 |
sentences = list(doc.sents)
|
310 |
arc_diagrams = []
|
311 |
for i, sent in enumerate(sentences):
|
312 |
+
st.subheader(f"{morpho_t.get('sentence', 'Sentence')} {i+1}")
|
313 |
html = displacy.render(sent, style="dep", options={"distance": 100})
|
314 |
html = html.replace('height="375"', 'height="200"')
|
315 |
html = re.sub(r'<svg[^>]*>', lambda m: m.group(0).replace('height="450"', 'height="300"'), html)
|