liveBook · Manning

Cypher projection

As explained in Graph Algorithms for Data Science

Cypher projection is a graph projection technique that uses Cypher queries to select, filter, and transform a graph subgraph before loading it into memory.

Cypher projection uses Cypher statements to select, filter, and transform nodes and relationships into an optimized in-memory graph for graph algorithms. It can create virtual relationships without storing them in the database, making it useful for exploratory graph analysis. section 5.2 section 6.1

A Cypher projection workflow typically involves:

  • Match the source and target nodes for the relationships to project. section 6.1.1
  • Define existing or virtual relationships, optionally calculating properties such as weights. section 6.1 section 6.1.1
  • Call gds.graph.project with a graph name, source nodes, target nodes, and optional configuration. section 6.1.1
  • Reuse the named in-memory graph for multiple algorithm runs when appropriate. section 5.2

Projecting an amplified retweet network

Match paths from a publishing user through a retweet to another publishing user, count each source–target pair as a weight, and project the result as amplify. The resulting example contains 1,828 nodes and 2,719 relationships. A second projection named amplify-noselfloops can exclude relationships whose source and target are the same node. section 6.3.1

Listing 6.2 Cypher projection syntax
MATCH (sourceNode)-[relationship]->(targetNode)  #1
RETURN gds.graph.project(
   'graph',                                      #2
   sourceNode,                                   #3
   targetNode,                                   #4
   {dataConfig},                                 #5
   {configuration}                               #6
) YIELD
    graphName,
    nodeCount,
    relationshipCount

Use the syntax listing to see how MATCH supplies projected relationships and how gds.graph.project returns the graph name and counts. section 6.1.1

How Graph Algorithms for Data Science covers it

How deep it goes
Explains query structure, projection parameters, virtual relationships, filtering, weights, and performance tradeoffs, but not implementation internals.
Examples
Demonstrates weighted retweet amplification, self-loop exclusion, and hashtag co-occurrence networks represented with directed relationships.
What it assumes
Assumes familiarity with Cypher nodes, relationships, and matching while teaching projection structure and virtual graph construction.
What you can do after
Build it from scratch by defining and loading filtered or transformed in-memory graphs with gds.graph.project.
How it connects
Connects Cypher projection with native projection, in-memory graphs, graph catalogs, virtual graphs, and graph algorithms.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.