Utility functions
Numeric Functions
Since Neo4j 5, this functionality can also be expressed directly in Cypher using the Inf , Infinity , and NaN literals and the isNaN() function.
|
Name | Parameter | Description |
---|---|---|
|
- |
Returns |
|
- |
Returns |
|
value to be checked if it is finite. |
Return false if the given argument is ±Infinity, NaN, or null. |
|
value to be checked if it is infinite. |
Returns |
Examples
gds.util.isFinite
UNWIND [1.0, gds.util.NaN(), gds.util.infinity()] AS value
RETURN gds.util.isFinite(value) AS isFinite
isFinite |
---|
true |
false |
false |
gds.util.isInfinite
UNWIND [1.0, gds.util.NaN(), gds.util.infinity()] AS value
RETURN gds.util.isInfinite(value) AS isInfinite
isInfinite |
---|
false |
true |
true |
A common usage of gds.util.IsFinite
and gds.util.IsInfinite
is for filtering streamed results, as for instance seen in the examples of gds.allShortestPaths
.
Node id functions
Results in GDS often contain node IDs. You can use the following functions to connect IDs to nodes in the graph.
Name | Parameters | Description |
---|---|---|
|
nodeId of a node in the neo4j-graph |
Return the node object for the given node id or null if none exists. |
|
list of nodeIds of nodes in the neo4j-graph |
Return the node objects for the given node ids or an empty list if none exists. |
Examples
All the examples below should be run in an empty database. The examples use Cypher projections as the norm. Native projections will be deprecated in a future release. |
Consider the graph created by the following Cypher statement:
CREATE (nAlice:User {name: 'Alice'})
CREATE (nBridget:User {name: 'Bridget'})
CREATE (nCharles:User {name: 'Charles'})
CREATE (nAlice)-[:LINK]->(nBridget)
CREATE (nBridget)-[:LINK]->(nCharles)
MATCH (n:User)-[r:LINK]->(m:User)
RETURN gds.graph.project('socialGraph', n, m)