Update modules/syntax_analysis.py
Browse files- modules/syntax_analysis.py +11 -7
modules/syntax_analysis.py
CHANGED
@@ -117,25 +117,29 @@ def create_syntax_graph(doc, lang):
|
|
117 |
def visualize_syntax_graph(doc, lang):
|
118 |
G, word_colors = create_syntax_graph(doc, lang)
|
119 |
|
120 |
-
plt.figure(figsize=(
|
121 |
-
pos = nx.spring_layout(G, k=
|
122 |
|
123 |
node_colors = [data['color'] for _, data in G.nodes(data=True)]
|
124 |
node_sizes = [data['size'] for _, data in G.nodes(data=True)]
|
125 |
|
126 |
-
nx.draw(G, pos, with_labels=False, node_color=node_colors, node_size=node_sizes, arrows=True
|
|
|
127 |
|
128 |
-
nx.draw_networkx_labels(G, pos, {node: data['label'] for node, data in G.nodes(data=True)},
|
|
|
129 |
|
130 |
edge_labels = nx.get_edge_attributes(G, 'label')
|
131 |
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8)
|
132 |
|
133 |
-
plt.title("Syntactic Analysis" if lang == 'en' else "Analyse Syntaxique" if lang == 'fr' else "Análisis Sintáctico"
|
|
|
134 |
plt.axis('off')
|
135 |
|
136 |
-
legend_elements = [plt.Rectangle((0,0),1,1, facecolor=color, edgecolor='none',
|
|
|
137 |
for pos, color in POS_COLORS.items() if pos in set(nx.get_node_attributes(G, 'pos').values())]
|
138 |
-
plt.legend(handles=legend_elements, loc='center left', bbox_to_anchor=(1, 0.5))
|
139 |
|
140 |
return plt
|
141 |
|
|
|
117 |
def visualize_syntax_graph(doc, lang):
|
118 |
G, word_colors = create_syntax_graph(doc, lang)
|
119 |
|
120 |
+
plt.figure(figsize=(24, 18)) # Increase figure size
|
121 |
+
pos = nx.spring_layout(G, k=0.9, iterations=50) # Adjust layout parameters
|
122 |
|
123 |
node_colors = [data['color'] for _, data in G.nodes(data=True)]
|
124 |
node_sizes = [data['size'] for _, data in G.nodes(data=True)]
|
125 |
|
126 |
+
nx.draw(G, pos, with_labels=False, node_color=node_colors, node_size=node_sizes, arrows=True,
|
127 |
+
arrowsize=20, width=2, edge_color='gray') # Adjust node and edge appearance
|
128 |
|
129 |
+
nx.draw_networkx_labels(G, pos, {node: data['label'] for node, data in G.nodes(data=True)},
|
130 |
+
font_size=10, font_weight='bold') # Increase font size and make bold
|
131 |
|
132 |
edge_labels = nx.get_edge_attributes(G, 'label')
|
133 |
nx.draw_networkx_edge_labels(G, pos, edge_labels=edge_labels, font_size=8)
|
134 |
|
135 |
+
plt.title("Syntactic Analysis" if lang == 'en' else "Analyse Syntaxique" if lang == 'fr' else "Análisis Sintáctico",
|
136 |
+
fontsize=20, fontweight='bold') # Increase title font size
|
137 |
plt.axis('off')
|
138 |
|
139 |
+
legend_elements = [plt.Rectangle((0,0),1,1, facecolor=color, edgecolor='none',
|
140 |
+
label=f"{POS_TRANSLATIONS[lang][pos]} ({count_pos(doc)[pos]})")
|
141 |
for pos, color in POS_COLORS.items() if pos in set(nx.get_node_attributes(G, 'pos').values())]
|
142 |
+
plt.legend(handles=legend_elements, loc='center left', bbox_to_anchor=(1, 0.5), fontsize=12) # Increase legend font size
|
143 |
|
144 |
return plt
|
145 |
|