cancel
Showing results for 
Search instead for 
Did you mean: 

Aggregate Parallel Relationships after gds.alpha.collapsePaths

Minyall
Node Link

Main query
Is it possible to either...

  • a) Aggregate parallel relationships on an existing GDS graph projection after it has been created.
  • b) Create a new graph projection using the content of an existing one?

Why?
I have a projected graph...

CALL gds.graph.create('test','USER',{
     REPRESENTS: {type: 'REPRESENTS',orientation: 'NATURAL'},
     FOLLOWS: {type: 'FOLLOWS', orientation: 'NATURAL'}}) 
YIELD graphName, nodeCount,relationshipCount

and I have mutated it using gds.alpha.collapsePath.mutate

CALL gds.alpha.collapsePath.mutate('test', {
    relationshipTypes:['FOLLOWS','REPRESENTS'],
    allowSelfLoops:false,
    mutateRelationshipType:'META_FOLLOWS'}) 
Yield relationshipsWritten

The point of it is to collapse down the current relationship to a simplified version.

(a: USER)-[:REPRESENTS]->(:USER)-[:FOLLOWS]->(:USER)<-[:REPRESENTS]-(b:USER)
(a:USER)-[:META_FOLLOWS]->(b:USER)

After my original test graph has been mutated, and had the META_FOLLOWS relationship added, I wanted to aggregate all parallel relationships so that I would have distinct relationships between nodes, each with a weight property that was equal to the count of parallel relationships. If collapsePath had written directly to the database I (think i) would do the following..

CALL gds.graph.create('final_graph', 'USER', {
    META_FOLLOWS: {
        properties:{
           weight:{property: '*', aggregation: 'COUNT'}
                 }
            }
        }
)

Is the only way ahead to manually stream out the META_FOLLOWS relationship from the first graph, save it to the DB and then run the second projection with the aggregation, or is there a way to do this all in one projection?

Any advice would be very helpful, thanks!

*NB for reasons I can't just export the projection to another database.

1 ACCEPTED SOLUTION

Right now, we don't have the option to have collapsePath output a relationship weight, or to re-aggregate relationships on an existing in memory graph, but those are both great feature requests!


For now, you can either write the new relationship back to the database & re-load or use gds.graph.export to dump the in-memory graph to a new database and load from that . Since it sounds like graph.export isn't an option, you'll want to use gds.graph.writeRelationship.

View solution in original post

6 REPLIES 6

sam_gijare
Graph Buddy

May be you can take a export dump of a data model in neo4j browser and then import it into another preconfigured instance.( If you have bloom installed ?)

Right now, we don't have the option to have collapsePath output a relationship weight, or to re-aggregate relationships on an existing in memory graph, but those are both great feature requests!


For now, you can either write the new relationship back to the database & re-load or use gds.graph.export to dump the in-memory graph to a new database and load from that . Since it sounds like graph.export isn't an option, you'll want to use gds.graph.writeRelationship.

Thanks Alicia,

I did try gds.graph.writeRelationship which did work, though the output of collapsePath for my project is a few million new relationships so it is rather slow going - may still be faster to do that than my current more manual cyper query which collapses the paths and aggregates the relationships so I'll have a go.

Is there a formal way to do feature requests? I think being able to re-aggregate existing in memory graphs would be a great addition given the number of mutate features in GDS.

The best way to make a feature request is to open an issue our our github: Issues · neo4j/graph-data-science · GitHub

sam_gijare
Graph Buddy

I think a possible feature could be a mechanism to attach and detach a Property SubGraph to existing node.
Thanks
Sameer G

nebuchadnezzar
Node Link

Hi, Minyall

Did I understand correctly that you get parallel META_FOLLOWS relations between a pair of nodes? I asking because the "gds.alpha.collapsePaths" documentation says that only one connection is created between a pair of nodes.

Thanks in advance for your answer