Add option to include direction of relations in apoc.convert.toTree
Issue by mrveld94
Wednesday Sep 08, 2021 at 09:54 GMT
Originally opened as https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/2199
The output of apoc.convert.toTree does not include the direction of the relations.
For example, consider the following path.

I can turn this path into a tree (with the pink node as root node) using the following query.
CALL apoc.convert.toTree(path, false) YIELD output RETURN output
This results in the following json.
{
"_type": "Resource:prov__Entity:provone__Data",
"uri": "urn:uuid:output_adaguc_Zmax_202108091550.h5",
"prov__hadMember": [
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:output_collection_Output_202108091550",
"prov__wasDerivedFrom": [
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:input_collection_Model_202108091550"
},
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:input_collection_Radar_202108091550"
},
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:input_collection_IVS_202108091550"
}
]
}
]
}
Looking at this output I cannot determine if urn:uuid:output_adaguc_Zmax_202108091550.h5 <prov__hadMember urn:uuid:output_collection_Output_202108091550 or if urn:uuid:output_adaguc_Zmax_202108091550.h5 prov__hadMember> urn:uuid:output_collection_Output_202108091550.
In other words I cannot determine which entity is a member of which.
I would like to see an option in apoc.convert.toTree, which would return the direction of the relations. For example by using the following query.
CALL apoc.convert.toTree(path, false, { includeDirection: true }) YIELD output RETURN output
Which would return something like this.
{
"_type": "Resource:prov__Entity:provone__Data",
"uri": "urn:uuid:output_adaguc_Zmax_202108091550.h5",
"<prov__hadMember": [
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:output_collection_Output_202108091550",
"prov__wasDerivedFrom>": [
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:input_collection_Model_202108091550"
},
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:input_collection_Radar_202108091550"
},
{
"_type": "Resource:prov__Entity:prov__Collection",
"uri": "urn:uuid:input_collection_IVS_202108091550"
}
]
}
]
}
Comment by conker84
Thursday Nov 18, 2021 at 13:00 GMT
{
"_type": "Resource:prov__Entity:provone__Data",
"uri": "urn:uuid:output_adaguc_Zmax_202108091550.h5",
"prov__hadMember": [
{
"_type": "Resource:prov__Entity:prov__Collection",
"_direction": "OUT",
"uri": "urn:uuid:output_collection_Output_202108091550"
...
}
]
}
Comment by mrveld94
Thursday Nov 18, 2021 at 13:05 GMT
Yes that would be perfect. Is this something that will be in the next version? (Sorry used the wrong account earlier...)
Comment by mrveld94
Wednesday Mar 30, 2022 at 07:07 GMT
Hi, is this something that is going to be implemented? And if so, when?
apoc.convert.toTree is deprecated according to https://neo4j.com/docs/apoc/current/overview/apoc.convert/apoc.convert.toTree/
The replacement is apoc.convert.toJsonTree, cf. https://neo4j.com/docs/apoc/current/overview/apoc.paths/apoc.paths.toJsonTree/
If the feature request is still relevant, please raise it for apoc.convert.toJsonTree.
Thanks.