Update modules/semantic_analysis.py
Browse files
modules/semantic_analysis.py
CHANGED
|
@@ -150,11 +150,11 @@ def create_semantic_graph(doc, lang):
|
|
| 150 |
if token.pos_ != 'PUNCT':
|
| 151 |
G.add_node(token.text,
|
| 152 |
pos=token.pos_,
|
| 153 |
-
color=POS_COLORS.get(token.pos_, '#
|
| 154 |
-
size=pos_counts
|
| 155 |
|
| 156 |
for token in doc:
|
| 157 |
-
if token.dep_ != "ROOT":
|
| 158 |
G.add_edge(token.head.text, token.text, label=token.dep_)
|
| 159 |
|
| 160 |
return G, pos_counts
|
|
@@ -165,8 +165,8 @@ def visualize_semantic_relations(doc, lang):
|
|
| 165 |
plt.figure(figsize=(24, 18))
|
| 166 |
pos = nx.spring_layout(G, k=0.9, iterations=50)
|
| 167 |
|
| 168 |
-
node_colors = [
|
| 169 |
-
node_sizes = [
|
| 170 |
|
| 171 |
nx.draw(G, pos, node_color=node_colors, node_size=node_sizes, with_labels=True,
|
| 172 |
font_size=8, font_weight='bold', arrows=True, arrowsize=20, width=2, edge_color='gray')
|
|
@@ -179,7 +179,7 @@ def visualize_semantic_relations(doc, lang):
|
|
| 179 |
plt.axis('off')
|
| 180 |
|
| 181 |
legend_elements = [plt.Rectangle((0,0),1,1, facecolor=color, edgecolor='none',
|
| 182 |
-
label=f"{POS_TRANSLATIONS[lang]
|
| 183 |
for pos, color in POS_COLORS.items() if pos in pos_counts]
|
| 184 |
plt.legend(handles=legend_elements, loc='center left', bbox_to_anchor=(1, 0.5), fontsize=12)
|
| 185 |
|
|
|
|
| 150 |
if token.pos_ != 'PUNCT':
|
| 151 |
G.add_node(token.text,
|
| 152 |
pos=token.pos_,
|
| 153 |
+
color=POS_COLORS.get(token.pos_, '#CCCCCC'), # Color gris por defecto
|
| 154 |
+
size=pos_counts.get(token.pos_, 1) * 100) # Tamaño mínimo si no hay conteo
|
| 155 |
|
| 156 |
for token in doc:
|
| 157 |
+
if token.dep_ != "ROOT" and token.head.text in G.nodes and token.text in G.nodes:
|
| 158 |
G.add_edge(token.head.text, token.text, label=token.dep_)
|
| 159 |
|
| 160 |
return G, pos_counts
|
|
|
|
| 165 |
plt.figure(figsize=(24, 18))
|
| 166 |
pos = nx.spring_layout(G, k=0.9, iterations=50)
|
| 167 |
|
| 168 |
+
node_colors = [G.nodes[node].get('color', '#CCCCCC') for node in G.nodes()]
|
| 169 |
+
node_sizes = [G.nodes[node].get('size', 100) for node in G.nodes()]
|
| 170 |
|
| 171 |
nx.draw(G, pos, node_color=node_colors, node_size=node_sizes, with_labels=True,
|
| 172 |
font_size=8, font_weight='bold', arrows=True, arrowsize=20, width=2, edge_color='gray')
|
|
|
|
| 179 |
plt.axis('off')
|
| 180 |
|
| 181 |
legend_elements = [plt.Rectangle((0,0),1,1, facecolor=color, edgecolor='none',
|
| 182 |
+
label=f"{POS_TRANSLATIONS[lang].get(pos, pos)} ({pos_counts.get(pos, 0)})")
|
| 183 |
for pos, color in POS_COLORS.items() if pos in pos_counts]
|
| 184 |
plt.legend(handles=legend_elements, loc='center left', bbox_to_anchor=(1, 0.5), fontsize=12)
|
| 185 |
|