Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-30-2020 07:06 PM
Hi,
I am new to Neo4j and I am trying to extract the adjacency matrix of my graph. I found this cypher query (https://github.com/michelcaradec/Graph-Theory#adjacency-matrix) to get the adjacency matrix but it return the matrix without the row names and column names. How is it possible to save the names too?
Here is the cypher query:
// Get all vertices.
MATCH (n)
WITH collect(n) AS Nodes
// For each vertices combination...
WITH [n IN Nodes |
[m IN Nodes |
// ...Check for edge existence.
CASE size((n)--(m))
WHEN 0 THEN 0
ELSE 1
END
]
] AS AdjacencyMatrix
// Unroll rows.
UNWIND AdjacencyMatrix AS AdjacencyRows
RETURN AdjacencyRows;
03-31-2020 07:29 AM
I'm not sure I would do it that way at all, or at least I'd step back to find out more about what you're trying to accomplish before proceeding.
The simplest adjacency matrix would be node IDs as rows, node IDs as columns, and a boolean in a cell i f there was a relationship between those two node IDs.
You might also check out the graph data science library, which has a concept of in-memory graphs on top of Neo4j which is already very similar to what you're trying to do here.
All the sessions of the conference are now available online