0
votes

There are nodes with label :Feature and between the feature nodes there is a relationship called parent_of.

So, some features are child features and some are parent features. Child feature of one feature might be the parent of other feature.

Required Cypher : Cypher which takes input as a feature no. and returns output as: what is it's parent feature and the features connected to that parent feature and again the child and parent feature connected to those features (this goes on till the leaf node).

Below is a screenshot of the relationship:

Structure

Example graph

1
So it sounds like, given a feature no., you want the entire connected graph of :Feature nodes connected by :parent_of relationships? Your description didn't seem to specify going only in one direction or the other (just parents of the :Feature, or just children).InverseFalcon
Also a more concrete example image would be helpful, showing on the full graph the starting node and all the nodes you want the query to return.InverseFalcon
@InverseFalcon suppose for an e.g. given feature no. is 123 and 123 has a parent feature no.1234 and this 1234 feature no. can be the child of other feature no. (e.g. 12345)...so it goes on till the hierarchy exists...so i want 123 to be printed along with 1234 as parent feature of 123 and also 12345 that 1234's parent is 12345 and so on....Rajat
@InverseFalcon thanks for your suggestion. I have uploaded an image(link in starting of the question). So, if i give 123 feature no. as input, whole network should come up and it should stop only if further parent_of relationship does't exist. And how can I present the graph output to the outer world so that they would be able to understand that what graph depictsRajat
Thanks for the example graph. Am I correct that you would want feature with number 12345678 in the result set, even if it's the child of 123456, rather than a parent of an ancestor of 123? If so, would you want the results to also include parents and children of 12345678 if there were any present (and continuing to all other connected nodes)?InverseFalcon

1 Answers

0
votes

I think the path expander procedures from APOC Procedures may help here.

If you only need the connected nodes, then use apoc.path.subgraphNodes(). If you want paths, then use apoc.path.spanningTree().

As far as outputting data in a format that captures the relational information between the nodes, you could either output relationships (along with each relationship's start and end nodes), which will involve some duplication of output data, or maybe you could use an APOC Procedure to transform a collection of paths to a nested JSON tree?

One example:

MATCH (f:Feature{feature_no:$startNo})
CALL apoc.path.spanningTree(f, {relationshipFilter:'parent_of', labelFilter:'>Feature'}) YIELD path
WITH collect(path) as paths
CALL apoc.convert.toTree(paths) YIELD value
RETURN value