test2 / modules /discourse_analysis.py
AIdeaText's picture
Create discourse_analysis.py
22e19aa verified
raw
history blame
No virus
1.24 kB
import streamlit as st
import spacy
import networkx as nx
import matplotlib.pyplot as plt
from collections import defaultdict
from .semantic_analysis import visualize_semantic_relations
def compare_semantic_analysis(text1, text2, nlp, lang):
doc1 = nlp(text1)
doc2 = nlp(text2)
fig1 = visualize_semantic_relations(doc1, lang)
fig2 = visualize_semantic_relations(doc2, lang)
# Create a new figure with two subplots side by side
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(72, 27))
# Get the contents of fig1 and fig2
fig1.axes[0].get_children()
for child in fig1.axes[0].get_children():
ax1.add_artist(child.copy())
ax1.set_title("Documento 1: Relaciones Semánticas Relevantes", fontsize=24, fontweight='bold')
ax1.axis('off')
fig2.axes[0].get_children()
for child in fig2.axes[0].get_children():
ax2.add_artist(child.copy())
ax2.set_title("Documento 2: Relaciones Semánticas Relevantes", fontsize=24, fontweight='bold')
ax2.axis('off')
plt.tight_layout()
return fig
def perform_discourse_analysis(text1, text2, nlp, lang):
comparison_graph = compare_semantic_analysis(text1, text2, nlp, lang)
return comparison_graph