liveBook · Manning

Graph filtering

As explained in Graph Algorithms for Data Science

Graph filtering is the selection of nodes and relationships from an existing graph according to structural, label, property, or predicate-based conditions.

Graph filtering creates a smaller in-memory graph by selecting nodes and relationships from an existing projected graph. Node filters can use labels or properties; relationship filters can use types or properties. Each filter is a Cypher predicate that must evaluate to true or false, using n for nodes and r for relationships. section 7.5

Use graph filtering when an analysis should focus on a structurally or semantically selected part of a graph:

  • Filter a community after label propagation has stored community identifiers as mutated node properties. section 7.5
  • Project the selected subgraph and run another algorithm on it, such as PageRank. section 7.5
  • Restrict algorithm input with node labels, relationship types, relationship direction, or undirected treatment during projection. section 7.7
Listing 7.20 Projecting a subgraph that contains only the largest community of hashtags
MATCH (h:Tag {id:"#ml"})
WITH h.community AS communityId
CALL gds.graph.filter(
  'ml-community',
  'tags',
  'n.community = $communityId',                  #1
 '*',                                            #2
{ parameters: { communityId: communityId } })    #3
YIELD graphName, fromGraphName, nodeCount, relationshipCount
RETURN graphName, fromGraphName, nodeCount, relationshipCount

This listing shows how to match a hashtag's community, pass it as a parameter, and retain only nodes with that community property. section 7.5

Finding representatives of a hashtag community

A projected hashtag graph contains a community identified through the #ml tag. Filtering produces the ml-community subgraph, after which PageRank ranks its members. The top results are #serverless, #iiot, #usa?, #coders, and #frenchtech. section 7.5

How Graph Algorithms for Data Science covers it

How deep it goes
Explains node and relationship predicates and demonstrates parameterized subgraph projection, but does not develop filtering internals.
Examples
Uses a hashtag co-occurrence graph, the #ml community, parameterized Cypher, and a five-item PageRank ranking.
What it assumes
Assumes an existing in-memory graph and mutated community properties, while introducing predicate-based node and relationship selection.
What you can do after
Apply it via GDS graph.filter to create a focused in-memory graph for subsequent algorithms.
How it connects
Connects graph projection with label propagation, PageRank, communities, node properties, and relationship types.

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.