Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-06-2021 08:41 PM
I'm using the result.graph()
to try and get graph info from a cypher call.
however, even using a debugger it's hard to tell how to extract anything useful from this API.
How do I iterate through or otherwise use a neo4j.graph.Graph
object?
g.relationships()
.data()
so basically wut can I do with this graph
instance?
code and query are like below, debugger output to after
def path_from(self, start_page, flow='BILL'):
q6 = """
MATCH
path = (n1:page{cname:$start_page})
-[*..5]->
(n2:page {flow:'BILL'})
WITH n1
AS startPage,
[p IN relationships(path) | properties(p)] AS edges,
n2 AS endPage,
path as path
RETURN startPage, edges, endPage, path
ORDER BY edges[0].weight DESC
LIMIT 1
"""
result = neolib.get_cursor(q6, start_page=start_page)
path = result.get('path')
g = result.graph()
logging.info('graph %s', g)
In a bit more detail my cypher query is trying to return a few things - nodes, edges and a 'path'
but not sure if i need to apply the .graph
somehow on only part of this result?
Or do I need to do an even more complex query with subgraphs for graph to return anything? Maybe that's the problem above.
07-07-2021 02:30 AM
see
07-07-2021 04:12 PM
yes seems like returning anything else with a path
causes the issue.
07-07-2021 04:42 PM
If I change my statement to
cypher_query = "MATCH p=(n)-[r]->(m) RETURN n,r,m,p LIMIT 5"
it still works for me.
Oh I just saw, you broke the relationships :), because you only return their properties but all the other entity-data (start,end,type) is missing. if you just return relationships(path)
it should work.
07-07-2021 04:50 PM
because you only return their properties
hmm ok how did I break it? With this filter part maybe?
I recall seeing a warning on that and elsewhere have used a WHERE
clause on that.
So perhaps filtering on edge properties in the query breaks things?
Or the important part is to wrap the path in relationships(path)
?
Which actually your other query example did not do and still works:
"MATCH p=(n)-[r]->(m) RETURN p LIMIT 5"
The queries were tested out / built up in the neo-browser, so it's a bit puzzling I can see a graph there but not get the data from the same query in python driver.
07-09-2021 02:48 PM
The bit where you do this:
[p IN relationships(path) | properties(p)] AS edges,
There the relationship objects are replaced by simple dicts of their properties.
So there is no way to reconstruct them as relationships
just return relationships(path) as edges
All the sessions of the conference are now available online