neo4j - How to get the minimum relational scope for multiple input nodes? -


the statement below creates representative data set in neo4j.

i want return minimum relational graph given set of input nodes.

e.g., minimum relational graph set of nodes "c", "g", "d" "c, g, d"; , "a", "e" "a, g, e".

the number of specific nodes arbitrary, require returned scope minimum.

how can query written?

sample data

create (a:table {name:'a'}) create (b:table {name:'b'}) create (c:table {name:'c'}) create (d:table {name:'d'}) create (e:table {name:'e'}) create (f:table {name:'f'}) create (g:table {name:'g'}) create   (f)-[:link]->(a),   (a)-[:link]->(g),   (g)-[:link]->(e),   (g)-[:link]->(c),   (g)-[:link]->(d),   (e)-[:link]->(b),   (c)-[:link]->(e) 

data set

here 1 simplistic solution. generate complete list of shortest paths between each pair of nodes in set. reduce resulting paths distinct set of nodes.

// set input nodes collection of attribute values matched ['c','g','d'] inputs  // build list of pairs not same  unwind range(0,size(inputs)-1) unwind range(0,size(inputs)-1) j case    when > j [inputs[i],inputs[j]]   else null end pair  // find of shortest paths each pair match p=allshortestpaths((a:table {name: pair[0]})-[:link*]-(b:table {name: pair[1]})) p  // recollect distinct nodes shortest paths unwind nodes(p) n return collect(distinct n) min_relational_scope 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -