AIdeaText commited on
Commit
6668945
1 Parent(s): b9011ad

Update modules/discourse_analysis.py

Browse files
Files changed (1) hide show
  1. modules/discourse_analysis.py +16 -15
modules/discourse_analysis.py CHANGED
@@ -12,25 +12,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 a new figure with two subplots side by side
16
- fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(72, 27))
 
17
 
18
  # Draw the first graph
19
  pos1 = nx.spring_layout(G1, k=0.7, iterations=50)
20
  nx.draw(G1, pos1, ax=ax1, node_color=[POS_COLORS.get(G1.nodes[node]['pos'], '#CCCCCC') for node in G1.nodes()],
21
- with_labels=True, node_size=5000, font_size=12, font_weight='bold',
22
- arrows=True, arrowsize=20, width=2, edge_color='gray')
23
- nx.draw_networkx_edge_labels(G1, pos1, edge_labels=nx.get_edge_attributes(G1, 'label'), font_size=10, ax=ax1)
24
 
25
  # Draw the second graph
26
  pos2 = nx.spring_layout(G2, k=0.7, iterations=50)
27
  nx.draw(G2, pos2, ax=ax2, node_color=[POS_COLORS.get(G2.nodes[node]['pos'], '#CCCCCC') for node in G2.nodes()],
28
- with_labels=True, node_size=5000, font_size=12, font_weight='bold',
29
- arrows=True, arrowsize=20, width=2, edge_color='gray')
30
- nx.draw_networkx_edge_labels(G2, pos2, edge_labels=nx.get_edge_attributes(G2, 'label'), font_size=10, ax=ax2)
31
 
32
- ax1.set_title("Documento 1: Relaciones Semánticas Relevantes", fontsize=24, fontweight='bold')
33
- ax2.set_title("Documento 2: Relaciones Semánticas Relevantes", fontsize=24, fontweight='bold')
34
 
35
  ax1.axis('off')
36
  ax2.axis('off')
@@ -39,13 +40,13 @@ def compare_semantic_analysis(text1, text2, nlp, lang):
39
  legend_elements = [plt.Rectangle((0,0),1,1,fc=POS_COLORS.get(pos, '#CCCCCC'), edgecolor='none',
40
  label=f"{POS_TRANSLATIONS[lang].get(pos, pos)}")
41
  for pos in ['NOUN', 'VERB']]
42
- ax1.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, 1), fontsize=12)
43
- ax2.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(0, 1), fontsize=12)
44
 
45
  plt.tight_layout()
46
 
47
- return fig
48
 
49
  def perform_discourse_analysis(text1, text2, nlp, lang):
50
- comparison_graph = compare_semantic_analysis(text1, text2, nlp, lang)
51
- return comparison_graph
 
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
  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