cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Triadic closure - find triangles with edge properties

How can I find all triangles in Neo4j including the edges (and edge properties)

CALL gds.graph.create('g-movies',
    ['Person', 'Movie'],
    {PARTICIPATE_IN_CRIME:{
        type:"ACTED_IN",
        orientation:"UNDIRECTED"
    }
});
        
CALL gds.triangleCount.write('g-movies', {
  writeProperty: 'triangles'
})
YIELD globalTriangleCount, nodeCount;

CALL gds.alpha.triangles('g-movies')
YIELD nodeA, nodeB, nodeC
RETURN
  gds.util.asNode(nodeA) AS nodeA,
  gds.util.asNode(nodeB) AS nodeB,
  gds.util.asNode(nodeC) AS nodeC

LIMIT 25
;

already returns the triangles (on this movie's dummy graph it is 0) (= I was not able to create a person-to-person projection of the graph quickly). But in principle, this returns the 3 nodes forming the triangle.

How can I get the edge properties for these edges as an additional column - i.e. assuming ACTED_IN would hold a property like roles (or date) I would want to retrieve these properties as an additional column i.e. AB_roles, AC_roles, BC_roles. How can I formulate this in neo4j/apoc/cypher?

2 REPLIES 2

If we want to look at just Persons as a mono partite graph - you can do a cypher projection

CALL gds.graph.create.cypher('g-movies5',
'match (n:Person)return id(n) as id','match (s:Person)--(:Movie)--(t:Person) return id(s) as source, id(t) as target '
);
We then get a lot of triangles.
Did you then want something like all the Persons in Triangle Group 1?

Great for sharing this!
After obtaining the triangles from the person to person projected data (I did this projection outside of neo4j so far) but with this I will perhaps do so in the future natively inside neo4j, I want to add additional columns /attriutes to the edges i.e. AB_attr1, AC_attr1, BC_attr1 to compare some attributes (such as timestamps) on the edges.

If I would do it outside neo4j I simply would join i.e. in pandas 3x the edges with the triangles obtained in neo4j and then obtain the desired columns/attribtes on the 3 edges.

But is there a more native way to do so directly?

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

All the sessions of the conference are now available online