AIdeaText commited on
Commit
2f61f89
1 Parent(s): e442b89

Update modules/discourse_analysis.py

Browse files
Files changed (1) hide show
  1. modules/discourse_analysis.py +15 -13
modules/discourse_analysis.py CHANGED
@@ -5,6 +5,7 @@ import matplotlib.pyplot as plt
5
  from collections import defaultdict
6
  from .semantic_analysis import visualize_semantic_relations, create_semantic_graph, POS_COLORS, POS_TRANSLATIONS
7
 
 
8
  def compare_semantic_analysis(text1, text2, nlp, lang):
9
  doc1 = nlp(text1)
10
  doc2 = nlp(text2)
@@ -12,26 +13,26 @@ def compare_semantic_analysis(text1, text2, nlp, lang):
12
  G1, pos_counts1 = create_semantic_graph(doc1, lang)
13
  G2, pos_counts2 = create_semantic_graph(doc2, lang)
14
 
15
- # Create two separate figures
16
- fig1, ax1 = plt.subplots(figsize=(36, 27))
17
- fig2, ax2 = plt.subplots(figsize=(36, 27))
18
 
19
  # Draw the first graph
20
  pos1 = nx.spring_layout(G1, k=0.7, iterations=50)
21
  nx.draw(G1, pos1, ax=ax1, node_color=[POS_COLORS.get(G1.nodes[node]['pos'], '#CCCCCC') for node in G1.nodes()],
22
- with_labels=True, node_size=8000, font_size=16, font_weight='bold',
23
- arrows=True, arrowsize=30, width=3, edge_color='gray')
24
- nx.draw_networkx_edge_labels(G1, pos1, edge_labels=nx.get_edge_attributes(G1, 'label'), font_size=14, ax=ax1)
25
 
26
  # Draw the second graph
27
  pos2 = nx.spring_layout(G2, k=0.7, iterations=50)
28
  nx.draw(G2, pos2, ax=ax2, node_color=[POS_COLORS.get(G2.nodes[node]['pos'], '#CCCCCC') for node in G2.nodes()],
29
- with_labels=True, node_size=8000, font_size=16, font_weight='bold',
30
- arrows=True, arrowsize=30, width=3, edge_color='gray')
31
- nx.draw_networkx_edge_labels(G2, pos2, edge_labels=nx.get_edge_attributes(G2, 'label'), font_size=14, ax=ax2)
32
 
33
- ax1.set_title("Documento 1: Relaciones Semánticas Relevantes", fontsize=28, fontweight='bold')
34
- ax2.set_title("Documento 2: Relaciones Semánticas Relevantes", fontsize=28, fontweight='bold')
35
 
36
  ax1.axis('off')
37
  ax2.axis('off')
@@ -40,13 +41,14 @@ def compare_semantic_analysis(text1, text2, nlp, lang):
40
  legend_elements = [plt.Rectangle((0,0),1,1,fc=POS_COLORS.get(pos, '#CCCCCC'), edgecolor='none',
41
  label=f"{POS_TRANSLATIONS[lang].get(pos, pos)}")
42
  for pos in ['NOUN', 'VERB']]
43
- ax1.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, 1), fontsize=16)
44
- ax2.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, 1), fontsize=16)
45
 
46
  plt.tight_layout()
47
 
48
  return fig1, fig2
49
 
 
50
  def perform_discourse_analysis(text1, text2, nlp, lang):
51
  graph1, graph2 = compare_semantic_analysis(text1, text2, nlp, lang)
52
  return graph1, graph2
 
5
  from collections import defaultdict
6
  from .semantic_analysis import visualize_semantic_relations, create_semantic_graph, POS_COLORS, POS_TRANSLATIONS
7
 
8
+ ##################################################################################################################
9
  def compare_semantic_analysis(text1, text2, nlp, lang):
10
  doc1 = nlp(text1)
11
  doc2 = nlp(text2)
 
13
  G1, pos_counts1 = create_semantic_graph(doc1, lang)
14
  G2, pos_counts2 = create_semantic_graph(doc2, lang)
15
 
16
+ # Create two separate figures with a smaller size
17
+ fig1, ax1 = plt.subplots(figsize=(18, 13))
18
+ fig2, ax2 = plt.subplots(figsize=(18, 13))
19
 
20
  # Draw the first graph
21
  pos1 = nx.spring_layout(G1, k=0.7, iterations=50)
22
  nx.draw(G1, pos1, ax=ax1, node_color=[POS_COLORS.get(G1.nodes[node]['pos'], '#CCCCCC') for node in G1.nodes()],
23
+ with_labels=True, node_size=4000, font_size=10, font_weight='bold',
24
+ arrows=True, arrowsize=20, width=2, edge_color='gray')
25
+ nx.draw_networkx_edge_labels(G1, pos1, edge_labels=nx.get_edge_attributes(G1, 'label'), font_size=8, ax=ax1)
26
 
27
  # Draw the second graph
28
  pos2 = nx.spring_layout(G2, k=0.7, iterations=50)
29
  nx.draw(G2, pos2, ax=ax2, node_color=[POS_COLORS.get(G2.nodes[node]['pos'], '#CCCCCC') for node in G2.nodes()],
30
+ with_labels=True, node_size=4000, font_size=10, font_weight='bold',
31
+ arrows=True, arrowsize=20, width=2, edge_color='gray')
32
+ nx.draw_networkx_edge_labels(G2, pos2, edge_labels=nx.get_edge_attributes(G2, 'label'), font_size=8, ax=ax2)
33
 
34
+ ax1.set_title("Documento 1: Relaciones Semánticas Relevantes", fontsize=14, fontweight='bold')
35
+ ax2.set_title("Documento 2: Relaciones Semánticas Relevantes", fontsize=14, fontweight='bold')
36
 
37
  ax1.axis('off')
38
  ax2.axis('off')
 
41
  legend_elements = [plt.Rectangle((0,0),1,1,fc=POS_COLORS.get(pos, '#CCCCCC'), edgecolor='none',
42
  label=f"{POS_TRANSLATIONS[lang].get(pos, pos)}")
43
  for pos in ['NOUN', 'VERB']]
44
+ ax1.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, 1), fontsize=8)
45
+ ax2.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, 1), fontsize=8)
46
 
47
  plt.tight_layout()
48
 
49
  return fig1, fig2
50
 
51
+ ##################################################################################################################
52
  def perform_discourse_analysis(text1, text2, nlp, lang):
53
  graph1, graph2 = compare_semantic_analysis(text1, text2, nlp, lang)
54
  return graph1, graph2