Training GDS Auxiliary - tomgeudens/practical-neo4j GitHub Wiki
Context: Cut-and-paste commands for the Graph Data Science - Auxiliary algorithms session.
Prerequisite: This document will assume you have a Neo4j instance running and are connected to it with the Neo4j Browser. You also need to have the Game of Thrones database loaded.
Setup
001
// Make sure you're in the correct database
:use gameofthrones
Stuff you've used before
002
// A very efficient Cypher query
MATCH (x)
WHERE id(x) = 1
RETURN x;
003
// Recognize this?
RETURN gds.util.asNode(1)
Do you remember ...
004
// Project the bipartite
CALL gds.graph.create('shared-fighters',
['King', 'Knight', 'Battle'],{
FIGHTER: { type: 'ATTACKER_KING', orientation: 'NATURAL' },
HAS_FIGHTER: { type: 'ATTACKER_KING', orientation: 'REVERSE' }
});
005
// Collapse into a monopartite
CALL gds.alpha.collapsePath.mutate('shared-fighters', {
relationshipTypes: ['HAS_FIGHTER', 'FIGHTER'],
allowSelfLoops: false,
mutateRelationshipType: 'SHARED_FIGHTERS'
}) YIELD relationshipsWritten;
006
// Remove projection relationship we no longer need
CALL gds.graph.deleteRelationships('shared-fighters', 'FIGHTER');
007
// Remove projection relationship we no longer need
CALL gds.graph.deleteRelationships('shared-fighters', 'HAS_FIGHTER');
008
// Write back the mutation
CALL gds.graph.writeRelationship('shared-fighters', 'SHARED_FIGHTERS');
009
// Cleanup the projection
CALL gds.graph.drop('shared-fighters');
A lot more
010
// Dead Kings are hot!
CALL db.labels() YIELD label WITH collect(label) as allLabels
MATCH (p:Person:King:Dead)
RETURN gds.alpha.ml.oneHotEncoding(allLabels,labels(p));