Update modules/text_analysis/discourse_analysis.py
Browse files
modules/text_analysis/discourse_analysis.py
CHANGED
|
@@ -2,6 +2,7 @@ import streamlit as st
|
|
| 2 |
import spacy
|
| 3 |
import networkx as nx
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
| 5 |
from .semantic_analysis import (
|
| 6 |
create_concept_graph,
|
| 7 |
visualize_concept_graph,
|
|
@@ -27,21 +28,62 @@ def compare_semantic_analysis(text1, text2, nlp, lang):
|
|
| 27 |
fig1 = visualize_concept_graph(G1, lang)
|
| 28 |
fig2 = visualize_concept_graph(G2, lang)
|
| 29 |
|
| 30 |
-
#
|
| 31 |
-
fig1.suptitle("
|
| 32 |
-
fig2.suptitle("
|
| 33 |
|
| 34 |
return fig1, fig2, key_concepts1, key_concepts2
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def perform_discourse_analysis(text1, text2, nlp, lang):
|
| 37 |
graph1, graph2, key_concepts1, key_concepts2 = compare_semantic_analysis(text1, text2, nlp, lang)
|
| 38 |
-
|
| 39 |
-
#
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
return {
|
| 43 |
'graph1': graph1,
|
| 44 |
'graph2': graph2,
|
| 45 |
-
'
|
| 46 |
-
'
|
| 47 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import spacy
|
| 3 |
import networkx as nx
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
+
import pandas as pd
|
| 6 |
from .semantic_analysis import (
|
| 7 |
create_concept_graph,
|
| 8 |
visualize_concept_graph,
|
|
|
|
| 28 |
fig1 = visualize_concept_graph(G1, lang)
|
| 29 |
fig2 = visualize_concept_graph(G2, lang)
|
| 30 |
|
| 31 |
+
# Remover los títulos superpuestos
|
| 32 |
+
fig1.suptitle("")
|
| 33 |
+
fig2.suptitle("")
|
| 34 |
|
| 35 |
return fig1, fig2, key_concepts1, key_concepts2
|
| 36 |
|
| 37 |
+
def create_concept_table(key_concepts):
|
| 38 |
+
df = pd.DataFrame(key_concepts, columns=['Concepto', 'Frecuencia'])
|
| 39 |
+
df['Frecuencia'] = df['Frecuencia'].round(2)
|
| 40 |
+
return df
|
| 41 |
+
|
| 42 |
def perform_discourse_analysis(text1, text2, nlp, lang):
|
| 43 |
graph1, graph2, key_concepts1, key_concepts2 = compare_semantic_analysis(text1, text2, nlp, lang)
|
| 44 |
+
|
| 45 |
+
# Crear tablas de conceptos clave
|
| 46 |
+
table1 = create_concept_table(key_concepts1)
|
| 47 |
+
table2 = create_concept_table(key_concepts2)
|
| 48 |
|
| 49 |
return {
|
| 50 |
'graph1': graph1,
|
| 51 |
'graph2': graph2,
|
| 52 |
+
'table1': table1,
|
| 53 |
+
'table2': table2
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
def display_discourse_analysis_results(analysis_result, lang_code):
|
| 57 |
+
translations = {
|
| 58 |
+
'es': {
|
| 59 |
+
'doc1_title': "Documento 1: Relaciones Conceptuales",
|
| 60 |
+
'doc2_title': "Documento 2: Relaciones Conceptuales",
|
| 61 |
+
'key_concepts': "Conceptos Clave",
|
| 62 |
+
},
|
| 63 |
+
'en': {
|
| 64 |
+
'doc1_title': "Document 1: Conceptual Relations",
|
| 65 |
+
'doc2_title': "Document 2: Conceptual Relations",
|
| 66 |
+
'key_concepts': "Key Concepts",
|
| 67 |
+
},
|
| 68 |
+
'fr': {
|
| 69 |
+
'doc1_title': "Document 1 : Relations Conceptuelles",
|
| 70 |
+
'doc2_title': "Document 2 : Relations Conceptuelles",
|
| 71 |
+
'key_concepts': "Concepts Clés",
|
| 72 |
+
}
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
t = translations[lang_code]
|
| 76 |
+
|
| 77 |
+
col1, col2 = st.columns(2)
|
| 78 |
+
|
| 79 |
+
with col1:
|
| 80 |
+
with st.expander(t['doc1_title'], expanded=True):
|
| 81 |
+
st.pyplot(analysis_result['graph1'])
|
| 82 |
+
st.subheader(t['key_concepts'])
|
| 83 |
+
st.table(analysis_result['table1'])
|
| 84 |
+
|
| 85 |
+
with col2:
|
| 86 |
+
with st.expander(t['doc2_title'], expanded=True):
|
| 87 |
+
st.pyplot(analysis_result['graph2'])
|
| 88 |
+
st.subheader(t['key_concepts'])
|
| 89 |
+
st.table(analysis_result['table2'])
|