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
