Update modules/discourse/discourse_process.py
Browse files
modules/discourse/discourse_process.py
CHANGED
@@ -1,21 +1,68 @@
|
|
1 |
-
from ..text_analysis.discourse_analysis import perform_discourse_analysis, compare_semantic_analysis
|
2 |
-
import streamlit as st
|
3 |
-
|
4 |
-
def process_discourse_input(
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
text1
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ..text_analysis.discourse_analysis import perform_discourse_analysis, compare_semantic_analysis
|
2 |
+
import streamlit as st
|
3 |
+
|
4 |
+
def process_discourse_input(text1, text2, nlp_models, lang_code):
|
5 |
+
"""
|
6 |
+
Procesa la entrada para el análisis del discurso
|
7 |
+
Args:
|
8 |
+
text1: Texto del primer documento
|
9 |
+
text2: Texto del segundo documento
|
10 |
+
nlp_models: Diccionario de modelos de spaCy
|
11 |
+
lang_code: Código del idioma actual
|
12 |
+
Returns:
|
13 |
+
dict: Resultados del análisis
|
14 |
+
"""
|
15 |
+
try:
|
16 |
+
# Obtener el modelo específico del idioma
|
17 |
+
nlp = nlp_models[lang_code]
|
18 |
+
|
19 |
+
# Realizar el análisis
|
20 |
+
analysis_result = perform_discourse_analysis(text1, text2, nlp, lang_code)
|
21 |
+
|
22 |
+
if analysis_result['success']:
|
23 |
+
return {
|
24 |
+
'success': True,
|
25 |
+
'analysis': analysis_result
|
26 |
+
}
|
27 |
+
else:
|
28 |
+
return {
|
29 |
+
'success': False,
|
30 |
+
'error': 'Error en el análisis del discurso'
|
31 |
+
}
|
32 |
+
|
33 |
+
except Exception as e:
|
34 |
+
logger.error(f"Error en process_discourse_input: {str(e)}")
|
35 |
+
return {
|
36 |
+
'success': False,
|
37 |
+
'error': str(e)
|
38 |
+
}
|
39 |
+
|
40 |
+
def format_discourse_results(result):
|
41 |
+
"""
|
42 |
+
Formatea los resultados del análisis para su visualización
|
43 |
+
Args:
|
44 |
+
result: Resultado del análisis
|
45 |
+
Returns:
|
46 |
+
dict: Resultados formateados
|
47 |
+
"""
|
48 |
+
try:
|
49 |
+
if not result['success']:
|
50 |
+
return result
|
51 |
+
|
52 |
+
analysis = result['analysis']
|
53 |
+
return {
|
54 |
+
'success': True,
|
55 |
+
'graph1': analysis['graph1'],
|
56 |
+
'graph2': analysis['graph2'],
|
57 |
+
'key_concepts1': analysis['key_concepts1'],
|
58 |
+
'key_concepts2': analysis['key_concepts2'],
|
59 |
+
'table1': analysis['table1'],
|
60 |
+
'table2': analysis['table2']
|
61 |
+
}
|
62 |
+
|
63 |
+
except Exception as e:
|
64 |
+
logger.error(f"Error en format_discourse_results: {str(e)}")
|
65 |
+
return {
|
66 |
+
'success': False,
|
67 |
+
'error': str(e)
|
68 |
+
}
|