File size: 2,802 Bytes
c7f1f5b
 
 
 
d3778bb
2c54508
957c8b2
 
 
60946b5
957c8b2
 
 
 
c7f1f5b
 
 
 
 
a2bd669
 
 
957c8b2
 
a2bd669
 
957c8b2
 
 
 
 
d3778bb
 
 
957c8b2
a2bd669
957c8b2
d3778bb
 
 
 
 
c7f1f5b
a2bd669
d3778bb
 
 
 
957c8b2
 
 
 
cc92ef8
 
d3778bb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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)

    # Identificar conceptos clave para ambos documentos
    key_concepts1 = identify_key_concepts(doc1)
    key_concepts2 = identify_key_concepts(doc2)

    # Crear grafos de conceptos para ambos documentos
    G1 = create_concept_graph(doc1, key_concepts1)
    G2 = create_concept_graph(doc2, key_concepts2)

    # Visualizar los grafos de conceptos
    fig1 = visualize_concept_graph(G1, lang)
    fig2 = visualize_concept_graph(G2, lang)

    # Remover los títulos superpuestos
    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)

    # Crear tablas de conceptos clave
    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):
    translations = {
        'es': {
            'doc1_title': "Documento 1: Relaciones Conceptuales",
            'doc2_title': "Documento 2: Relaciones Conceptuales",
            'key_concepts': "Conceptos Clave",
        },
        'en': {
            'doc1_title': "Document 1: Conceptual Relations",
            'doc2_title': "Document 2: Conceptual Relations",
            'key_concepts': "Key Concepts",
        },
        'fr': {
            'doc1_title': "Document 1 : Relations Conceptuelles",
            'doc2_title': "Document 2 : Relations Conceptuelles",
            'key_concepts': "Concepts Clés",
        }
    }

    t = 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'])