Hi, I'm trying to display a graph using Python and I follow the instruction on Manipulate query results - Neo4j Python Driver Manual for that. I'm using my own database, and an easy query, that in neo4j returns a small subgraph with 5 nodes and 4 relationships.
Unfortunately, python shows nothing. As far as I can see, the graph object (result_transformer_=neo4j.Result.graph) doesn't get the relationships because I can print all results for the nodes, like
for node in graph_result.nodes:
print(node.labels)
print(node.element_id)
print(node[nodes_text_properties[list(node.labels)[0]]])
but doing the same with the relationships doesn't return anything (also no error message):
for relationship in graph_result.relationships:
print("s")
print(relationship.start_node.element_id)
Is there a bug or am I doing something wrong?
This is the whole code (without settings):
def main():
# Verbindung mit der Graph-DB herstellen
with GraphDatabase.driver(URI, auth=AUTH) as driver:
driver.verify_connectivity()
# Query to get a graphy result
graph_result = driver.execute_query("""
MATCH (p:person) --> (m:mail)
WHERE p.email starts with 'pallen'
RETURN p,m
""",
result_transformer_=neo4j.Result.graph,
)
# Draw graph
nodes_text_properties = { # what property to use as text for each node
"person": "contact_name",
"mail": "id",
}
visualize_result(graph_result, nodes_text_properties)
def visualize_result(query_graph, nodes_text_properties):
visual_graph = pyvis.network.Network()
for node in query_graph.nodes:
node_label = list(node.labels)[0]
node_text = node[nodes_text_properties[node_label]]
visual_graph.add_node(node.element_id, node_text, group=node_label)
for relationship in query_graph.relationships:
visual_graph.add_edge(
relationship.start_node.element_id,
relationship.end_node.element_id,
title=relationship.type
)
visual_graph.show('network.html', notebook=False)
if __name__ == "__main__":
main()