apoc icon indicating copy to clipboard operation
apoc copied to clipboard

Add option to include direction of relations in apoc.convert.toTree

Open neo-technology-build-agent opened this issue 2 years ago • 3 comments

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. image

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"
        }
      ]
    }
  ]
}