@@ -289,27 +289,34 @@ def construct_unique_nodes_clause(metarels, unique_nodes):
289
289
290
290
def create_path_return_clause (path_style = 'list' , return_property = 'name' ):
291
291
"""
292
- Create a Cypher query clause to return paths either as a list or as a string.
292
+ Create a Cypher query clause to return paths. If path_style is 'list' or 'string',
293
+ then the return_property is extracted for each node along the path. If path_style
294
+ is 'id_lists', then two lists (node_ids and rel_ids) are returned of neo4j databse ids.
293
295
As formatting the output as a string is less efficient in terms of database
294
- hits, 'list' is the default style
296
+ hits, 'list' is the default style.
295
297
296
298
Parameters
297
299
----------
298
300
path_style : str
299
301
the way the user wants the path returned. Currently supported options
300
- are 'list' and 'string '
302
+ are 'list', 'string', and 'id_lists '
301
303
return_property : str
302
304
which node property to use to describe the path
303
305
"""
304
306
if path_style == 'string' :
305
307
return "substring(reduce(s = '', node IN nodes(path)| s + '–' + node.{property}), 1) AS path," .format (property = return_property )
306
308
elif path_style == 'list' :
307
- return "extract(n in nodes(path) | n.{property}) AS path," .format (property = return_property )
309
+ return "[node in nodes(path) | node.{property}] AS path," .format (property = return_property )
310
+ elif path_style == 'id_lists' :
311
+ return (
312
+ '[node IN nodes(path) | id(node)] AS node_ids,\n '
313
+ '[rel IN relationships(path) | id(rel)] AS rel_ids,'
314
+ )
308
315
else :
309
- err_string = ("{style} is not a style currently implemented by "
310
- " create_path_return_clause. Valid styles are "
311
- " 'list' and 'string'" ). format ( style = path_style )
312
-
316
+ err_string = (
317
+ "{style} is not a style currently implemented by create_path_return_clause. "
318
+ "Valid styles are 'list', 'string', and 'id_lists'."
319
+ ). format ( style = path_style )
313
320
raise ValueError (err_string )
314
321
315
322
def construct_dwpc_query (metarels , property = 'name' , join_hint = 'midpoint' , index_hint = False , unique_nodes = True ):
0 commit comments