| import streamlit as st |
| import spacy |
| import networkx as nx |
| import matplotlib.pyplot as plt |
| from collections import defaultdict |
| from .semantic_analysis import ( |
| create_concept_graph, |
| visualize_concept_graph, |
| identify_and_contextualize_entities, |
| POS_COLORS, |
| POS_TRANSLATIONS, |
| ENTITY_LABELS |
| ) |
|
|
| def compare_semantic_analysis(text1, text2, nlp, lang): |
| doc1 = nlp(text1) |
| doc2 = nlp(text2) |
|
|
| |
| entities1, key_concepts1 = identify_and_contextualize_entities(doc1, lang) |
| entities2, key_concepts2 = identify_and_contextualize_entities(doc2, lang) |
|
|
| |
| concepts1 = [concept for concept, _ in key_concepts1] |
| concepts2 = [concept for concept, _ in key_concepts2] |
| G1 = create_concept_graph(text1, concepts1) |
| G2 = create_concept_graph(text2, concepts2) |
|
|
| |
| fig1 = visualize_concept_graph(G1, lang) |
| fig2 = visualize_concept_graph(G2, lang) |
|
|
| |
| fig1.suptitle("Documento 1: Relaciones Conceptuales", fontsize=16, fontweight='bold') |
| fig2.suptitle("Documento 2: Relaciones Conceptuales", fontsize=16, fontweight='bold') |
|
|
| return fig1, fig2, entities1, entities2, key_concepts1, key_concepts2 |
|
|
| def perform_discourse_analysis(text1, text2, nlp, lang): |
| graph1, graph2, entities1, entities2, key_concepts1, key_concepts2 = compare_semantic_analysis(text1, text2, nlp, lang) |
| |
| |
| |
|
|
| return { |
| 'graph1': graph1, |
| 'graph2': graph2, |
| 'entities1': entities1, |
| 'entities2': entities2, |
| 'key_concepts1': key_concepts1, |
| 'key_concepts2': key_concepts2 |
| } |