AIdeaText commited on
Commit
bf9549c
·
verified ·
1 Parent(s): ed063c4

Update modules/semantic_analysis.py

Browse files
Files changed (1) hide show
  1. modules/semantic_analysis.py +26 -26
modules/semantic_analysis.py CHANGED
@@ -137,45 +137,45 @@ def extract_entities(doc, lang):
137
 
138
  #####################################################################################################################
139
 
140
- def visualize_context_graph(doc, lang):
141
- G = nx.Graph()
142
- entities = extract_entities(doc, lang)
143
- color_map = ENTITY_LABELS[lang]
144
 
145
  # Add nodes
146
- for category, items in entities.items():
147
- for item in items:
148
- G.add_node(item, category=category)
149
 
150
  # Add edges
151
- for sent in doc.sents:
152
- sent_entities = [ent for ent in sent.ents if ent.text in G.nodes()]
153
- for i in range(len(sent_entities)):
154
- for j in range(i+1, len(sent_entities)):
155
- G.add_edge(sent_entities[i].text, sent_entities[j].text)
156
 
157
  # Visualize
158
- plt.figure(figsize=(30, 22)) # Increased figure size
159
- pos = nx.spring_layout(G, k=0.7, iterations=50) # Adjusted layout
160
 
161
- node_colors = [color_map[G.nodes[node]['category']] for node in G.nodes()]
162
 
163
- nx.draw(G, pos, node_color=node_colors, with_labels=True,
164
- node_size=10000, # Increased node size
165
- font_size=18, # Increased font size
166
- font_weight='bold',
167
- width=2, # Increased edge width
168
- arrowsize=30) # Increased arrow size
169
 
170
  # Add a legend
171
- legend_elements = [plt.Rectangle((0,0),1,1,fc=color, edgecolor='none', label=category)
172
  for category, color in color_map.items()]
173
- plt.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(1, 1), fontsize=16) # Increased legend font size
174
 
175
- plt.title("Análisis del Contexto" if lang == 'es' else "Context Analysis" if lang == 'en' else "Analyse du Contexte", fontsize=24) # Increased title font size
176
- plt.axis('off')
177
 
178
- return plt
179
 
180
  ############################################################################################################################################
181
 
 
137
 
138
  #####################################################################################################################
139
 
140
+ #def visualize_context_graph(doc, lang):
141
+ # G = nx.Graph()
142
+ # entities = extract_entities(doc, lang)
143
+ # color_map = ENTITY_LABELS[lang]
144
 
145
  # Add nodes
146
+ # for category, items in entities.items():
147
+ # for item in items:
148
+ # G.add_node(item, category=category)
149
 
150
  # Add edges
151
+ # for sent in doc.sents:
152
+ # sent_entities = [ent for ent in sent.ents if ent.text in G.nodes()]
153
+ # for i in range(len(sent_entities)):
154
+ # for j in range(i+1, len(sent_entities)):
155
+ # G.add_edge(sent_entities[i].text, sent_entities[j].text)
156
 
157
  # Visualize
158
+ # plt.figure(figsize=(30, 22)) # Increased figure size
159
+ # pos = nx.spring_layout(G, k=0.7, iterations=50) # Adjusted layout
160
 
161
+ # node_colors = [color_map[G.nodes[node]['category']] for node in G.nodes()]
162
 
163
+ # nx.draw(G, pos, node_color=node_colors, with_labels=True,
164
+ # node_size=10000, # Increased node size
165
+ # font_size=18, # Increased font size
166
+ # font_weight='bold',
167
+ # width=2, # Increased edge width
168
+ # arrowsize=30) # Increased arrow size
169
 
170
  # Add a legend
171
+ # legend_elements = [plt.Rectangle((0,0),1,1,fc=color, edgecolor='none', label=category)
172
  for category, color in color_map.items()]
173
+ # plt.legend(handles=legend_elements, loc='upper left', bbox_to_anchor=(1, 1), fontsize=16) # Increased legend font size
174
 
175
+ # plt.title("Análisis del Contexto" if lang == 'es' else "Context Analysis" if lang == 'en' else "Analyse du Contexte", fontsize=24) # Increased title font size
176
+ # plt.axis('off')
177
 
178
+ # return plt
179
 
180
  ############################################################################################################################################
181