|
import streamlit as st
|
|
import spacy
|
|
import networkx as nx
|
|
import matplotlib.pyplot as plt
|
|
import pandas as pd
|
|
import numpy as np
|
|
from .semantic_analysis import (
|
|
create_concept_graph,
|
|
visualize_concept_graph,
|
|
identify_key_concepts,
|
|
POS_COLORS,
|
|
POS_TRANSLATIONS,
|
|
ENTITY_LABELS
|
|
)
|
|
|
|
def compare_semantic_analysis(text1, text2, nlp, lang):
|
|
doc1 = nlp(text1)
|
|
doc2 = nlp(text2)
|
|
|
|
|
|
key_concepts1 = identify_key_concepts(doc1)
|
|
key_concepts2 = identify_key_concepts(doc2)
|
|
|
|
|
|
G1 = create_concept_graph(doc1, key_concepts1)
|
|
G2 = create_concept_graph(doc2, key_concepts2)
|
|
|
|
|
|
fig1 = visualize_concept_graph(G1, lang)
|
|
fig2 = visualize_concept_graph(G2, lang)
|
|
|
|
|
|
fig1.suptitle("")
|
|
fig2.suptitle("")
|
|
|
|
return fig1, fig2, key_concepts1, key_concepts2
|
|
|
|
def create_concept_table(key_concepts):
|
|
df = pd.DataFrame(key_concepts, columns=['Concepto', 'Frecuencia'])
|
|
df['Frecuencia'] = df['Frecuencia'].round(2)
|
|
return df
|
|
|
|
def perform_discourse_analysis(text1, text2, nlp, lang):
|
|
graph1, graph2, key_concepts1, key_concepts2 = compare_semantic_analysis(text1, text2, nlp, lang)
|
|
|
|
|
|
table1 = create_concept_table(key_concepts1)
|
|
table2 = create_concept_table(key_concepts2)
|
|
|
|
return {
|
|
'graph1': graph1,
|
|
'graph2': graph2,
|
|
'key_concepts1': key_concepts1,
|
|
'key_concepts2': key_concepts2
|
|
}
|
|
|
|
def display_discourse_analysis_results(analysis_result, lang_code):
|
|
t = get_translations(lang_code)
|
|
|
|
col1, col2 = st.columns(2)
|
|
|
|
with col1:
|
|
with st.expander(t['doc1_title'], expanded=True):
|
|
st.pyplot(analysis_result['graph1'])
|
|
st.subheader(t['key_concepts'])
|
|
st.table(analysis_result['table1'])
|
|
|
|
with col2:
|
|
with st.expander(t['doc2_title'], expanded=True):
|
|
st.pyplot(analysis_result['graph2'])
|
|
st.subheader(t['key_concepts'])
|
|
st.table(analysis_result['table2']) |