Create discourse_analysis.py
Browse files
modules/discourse_analysis.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import spacy
|
3 |
+
import networkx as nx
|
4 |
+
import matplotlib.pyplot as plt
|
5 |
+
from collections import defaultdict
|
6 |
+
from .semantic_analysis import visualize_semantic_relations
|
7 |
+
|
8 |
+
def compare_semantic_analysis(text1, text2, nlp, lang):
|
9 |
+
doc1 = nlp(text1)
|
10 |
+
doc2 = nlp(text2)
|
11 |
+
|
12 |
+
fig1 = visualize_semantic_relations(doc1, lang)
|
13 |
+
fig2 = visualize_semantic_relations(doc2, lang)
|
14 |
+
|
15 |
+
# Create a new figure with two subplots side by side
|
16 |
+
fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(72, 27))
|
17 |
+
|
18 |
+
# Get the contents of fig1 and fig2
|
19 |
+
fig1.axes[0].get_children()
|
20 |
+
for child in fig1.axes[0].get_children():
|
21 |
+
ax1.add_artist(child.copy())
|
22 |
+
ax1.set_title("Documento 1: Relaciones Semánticas Relevantes", fontsize=24, fontweight='bold')
|
23 |
+
ax1.axis('off')
|
24 |
+
|
25 |
+
fig2.axes[0].get_children()
|
26 |
+
for child in fig2.axes[0].get_children():
|
27 |
+
ax2.add_artist(child.copy())
|
28 |
+
ax2.set_title("Documento 2: Relaciones Semánticas Relevantes", fontsize=24, fontweight='bold')
|
29 |
+
ax2.axis('off')
|
30 |
+
|
31 |
+
plt.tight_layout()
|
32 |
+
|
33 |
+
return fig
|
34 |
+
|
35 |
+
def perform_discourse_analysis(text1, text2, nlp, lang):
|
36 |
+
comparison_graph = compare_semantic_analysis(text1, text2, nlp, lang)
|
37 |
+
return comparison_graph
|