learning-neo4j

Graph Academy › Introduction to Neo4j Graph Data Science

Graph Management › Challenge: Native Projection

source, related docs

Challenge

Create a native graph projection

Create a native graph projection representing Users rating Movies and ensure the RATED relationship is undirected.

What is the relationship count of the native projection?
200008

My take

CALL gds.graph.drop( 'userRatedMovies', false);

CALL gds.graph.project(
  'userRatedMovies',
  ['User', 'Movie'],
  { RATED: { orientation: 'UNDIRECTED' } }
);
╒══════════════════════════════════════════════════════════════════════╤══════════════════════════════════════════════════════════════════════╤═════════════════╤═══════════╤═══════════════════╤═══════════════╕
│"nodeProjection"                                                      │"relationshipProjection"                                              │"graphName"      │"nodeCount"│"relationshipCount"│"projectMillis"│
╞══════════════════════════════════════════════════════════════════════╪══════════════════════════════════════════════════════════════════════╪═════════════════╪═══════════╪═══════════════════╪═══════════════╡
│{"Movie":{"label":"Movie","properties":{}},"User":{"label":"User","pro│{"RATED":{"orientation":"UNDIRECTED","aggregation":"DEFAULT","type":"R│"userRatedMovies"│9796       │200008             │13             │
│perties":{}}}                                                         │ATED","properties":{}}}                                               │                 │           │                   │               │
└──────────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────┴─────────────────┴───────────┴───────────────────┴───────────────┘

Solution

You can run the following Cypher statement to create the graph projection.

The statement returns a single value from the procedure call, relationshipCount, which can be copied and pasted into the textbox above.

CALL gds.graph.project(
  // Name of the projection
  'user-rated-movie',
  // Labels of nodes to include in the projection
  ['User', 'Movie'],
  // Relationship types to include in the projection
  {
    RATED: {
        type: 'RATED',
        orientation: 'UNDIRECTED'
    }
  }
)
YIELD relationshipCount;
╒═══════════════════╕
│"relationshipCount"│
╞═══════════════════╡
│200008             │
└───────────────────┘