cancel
Showing results for 
Search instead for 
Did you mean: 

Running Centrality algorithm on the result of Cypher query

Hello Everyone,
I want to apply Closeness centrality algorithm on the graph obtained by the following Cypher query.

WITH [uri1, uri2,  uri3] AS StopUris
MATCH(n:label1)-[:abc|pqr|xyz*0..2]->(m)-[:uvw*0..1]-(o)
 WHERE n.uri = uri4 and not m.uri IN StopUris and not o.uri IN StopUris
RETURN n,m,o
union all
WITH [uri1, uri2,  uri3] AS StopUris
MATCH(n:label1)-[:abc|pqr|xyz*0..2]->(m)-[:uvw*0..1]-(o)
 WHERE n.uri = uri5 and not m.uri IN StopUris and not o.uri IN StopUris
RETURN n,m,o

Is there any way to store the Cypher result in a graph so that the algorithm can be applied? Thanks in advance.

3 REPLIES 3

ChakaBrah
Node Link

I believe you're looking for this piece of the documentation - https://neo4j.com/docs/graph-data-science/current/graph-create-cypher/.

What you basically do is create an in-memory named graph projection, using a node- and relationship-projection that you define in Cypher. In your example that means the node-projection has to produce nodes n, m and o, and the relationship-projection has to include relationships abc, pqr, xyz.

After naming the graph, you can then call the closeness centrality algorithm as in the examples.

Thank you for your suggestion @ChakaBrah . I am using Cypher projection now and it's exactly what I wanted..

Good to hear! Cheers