Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-21-2022 09:29 AM
Hi, everyone!
How to project the following Cypher pattern:
MATCH (c1:Company)<-[:MEMBER_OF]-(e1:employee
)-[*1..3]-(e2:employee
)-[:MEMBER_OF]->(c2:Company) RETURN c1.id as source, c2.id as target
so i can use it in GDS collapse path?
And get from that input graph below (red nodes are (Company), yellow nodes are (employee)
That graph in result
Any tips on how to improve performance or improve the query are welcome
08-21-2022 11:05 AM
Collapse path doesn't support variable length paths at this time. As per the documentation -
Starting from every node in the specified graph, these relationship types are traversed one after the other using the order specified in the configuration. Only nodes reached after traversing every relationship type specified are used as end nodes.
I think you can apply collapse path repeatedly to get what you are looking for. For example,
CALL gds.graph.project(
'employee_company',
['Company', 'Employee'],
{
MEMBER_OF: {
type: 'MEMBER_OF',
orientation: 'NATURAL'
},
MEMBER_OF_REV: {
type: 'MEMBER_OF',
orientation: 'REVERSE'
},
FOLLOWING: {
type: 'FOLLOWING',
orientation: 'NATURAL'
}
});
CALL gds.alpha.collapsePath.mutate(
'employee_company',
{
relationshipTypes: ['MEMBER_OF_REV', 'FOLLOWING', 'MEMBER_OF'],
allowSelfLoops: false,
mutateRelationshipType: 'COLLAPSED_1HOP'
}
) YIELD relationshipsWritten;
CALL gds.alpha.collapsePath.mutate(
'employee_company',
{
relationshipTypes: ['MEMBER_OF_REV', 'FOLLOWING', 'FOLLOWING', 'MEMBER_OF'],
allowSelfLoops: false,
mutateRelationshipType: 'COLLAPSED_2HOP'
}
) YIELD relationshipsWritten;
...
08-22-2022 01:40 PM
Thanks for the answer, but this code does not work, and I need one name for mutateRelationshipType
All the sessions of the conference are now available online