If your query results in the path identified as ‘actual data’, you can construct a virtual path for each of the paths identified as ‘output’ using the apoc procedure/functions described in the link below.
Try these. I matched the full path then returned the path you wanted with virtual relationships. Match sure the match meets your data model. There seems to be a little inconsistency with the Person node and its relationship type and direction to its related node.
Path 1:
match (country:Country)-[r1:CONTAIN]->(state:State)-[r2:CONTAIN]->(district:District)-[r3:CONTAIN]->(tahashil:Tahashil)-[r4:CONTAIN]->(village:Village)<-[r5:LIVES]-(person:Person)
return
country,
r1,
state,
apoc.create.vRelationship(person,'LIVES',{}, state),
person
match (country:Country)-[r1:CONTAIN]->(state:State)-[r2:CONTAIN]->(district:District)-[r3:CONTAIN]->(tahashil:Tahashil)-[r4:CONTAIN]->(village:Village)<-[r5:LIVES]-(person:Person)
return
country,
apoc.create.vRelationship(person,'LIVES',{}, country),
person
@glilienfield Thanks for the response, but can you give me sample example, I am not able to see the sample example in documentation. That will be helpful.
@glilienfield This looks good but every time I have to write separate cypher query for each one, is it possible to make it dynamic with one single query to return result.
Dynamic based on what? You need get the file path and then create the virtual path. This is done with cypher that needs to be written.
One thing I could think of is if you passed a list of ordered pairs of integers that specified the node indexes of the start and end nodes that you want a virtual relationships between. You could write code that would substitute each segment with a virtual relationships, then output the remaining nodes, relationships, and virtual relationships.
This would be a little complicated, and I would think that you would have known scenarios that you wanted to implement, so you would only write the code for each scenario ones and use many times.