Update app.py
Browse files
app.py
CHANGED
|
@@ -46,17 +46,29 @@ def run_query_and_visualize(qtext, jsonld_url):
|
|
| 46 |
G.add_node(str(s), label=str(s).split('/')[-1]) # Usar o último segmento da URI como rótulo
|
| 47 |
G.add_node(str(o), label=str(o).split('/')[-1])
|
| 48 |
G.add_edge(str(s), str(o), label=str(p).split('/')[-1])
|
| 49 |
-
|
| 50 |
-
# Define posições para os nós
|
| 51 |
-
pos =
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
# Desenha o gráfico usando NetworkX e Matplotlib
|
| 54 |
-
plt.figure(figsize=(
|
| 55 |
nx.draw_networkx_nodes(G, pos, node_size=3000, node_color="skyblue", alpha=0.9)
|
| 56 |
nx.draw_networkx_edges(G, pos, width=2, alpha=0.5, edge_color='gray')
|
| 57 |
nx.draw_networkx_labels(G, pos, labels=nx.get_node_attributes(G, 'label'), font_size=9, font_color="black")
|
| 58 |
nx.draw_networkx_edge_labels(G, pos, edge_labels=nx.get_edge_attributes(G, 'label'), font_size=9, font_color="red")
|
| 59 |
|
|
|
|
|
|
|
|
|
|
| 60 |
plt.title("Resultado da Consulta SPARQL", size=15)
|
| 61 |
plt.axis('off')
|
| 62 |
|
|
|
|
| 46 |
G.add_node(str(s), label=str(s).split('/')[-1]) # Usar o último segmento da URI como rótulo
|
| 47 |
G.add_node(str(o), label=str(o).split('/')[-1])
|
| 48 |
G.add_edge(str(s), str(o), label=str(p).split('/')[-1])
|
| 49 |
+
|
| 50 |
+
# Define posições específicas para os nós importantes
|
| 51 |
+
pos = {
|
| 52 |
+
"https://huggingface.co/spaces/histlearn/MachadodeAssis/Aden": (0, 0.5),
|
| 53 |
+
"https://huggingface.co/spaces/histlearn/MachadodeAssis/Aden-geo": (-0.6, -0.5),
|
| 54 |
+
"http://dados.literaturabrasileira.ufsc.br/resource/O_imortal_(Machado_de_Assis)#o-imortal": (0.6, -0.5)
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
# Preencher posições para todos os nós se não definidos
|
| 58 |
+
for node in G.nodes():
|
| 59 |
+
if node not in pos:
|
| 60 |
+
pos[node] = (0, 0) # Posição padrão para nós não especificados
|
| 61 |
+
|
| 62 |
# Desenha o gráfico usando NetworkX e Matplotlib
|
| 63 |
+
plt.figure(figsize=(10, 8))
|
| 64 |
nx.draw_networkx_nodes(G, pos, node_size=3000, node_color="skyblue", alpha=0.9)
|
| 65 |
nx.draw_networkx_edges(G, pos, width=2, alpha=0.5, edge_color='gray')
|
| 66 |
nx.draw_networkx_labels(G, pos, labels=nx.get_node_attributes(G, 'label'), font_size=9, font_color="black")
|
| 67 |
nx.draw_networkx_edge_labels(G, pos, edge_labels=nx.get_edge_attributes(G, 'label'), font_size=9, font_color="red")
|
| 68 |
|
| 69 |
+
plt.xlim(-1, 1)
|
| 70 |
+
plt.ylim(-1, 1)
|
| 71 |
+
|
| 72 |
plt.title("Resultado da Consulta SPARQL", size=15)
|
| 73 |
plt.axis('off')
|
| 74 |
|