Utility functions
This section provides explanations and examples for each of the utility functions in the Neo4j Graph Data Science library.
1. System Functions
Name | Description |
---|---|
|
Return the version of the installed Neo4j Graph Data Science library. |
RETURN gds.version() AS version
version |
---|
"1.5.2" |
2. Numeric Functions
Name | Description |
---|---|
|
Returns NaN as a Cypher value. |
|
Return infinity as a Cypher value. |
|
Return true iff the given argument is a finite value (not ±Infinity, NaN, or null). |
|
Return true iff the given argument is not a finite value (not ±Infinity, NaN, or null). |
2.1. Syntax
Name | Parameter |
---|---|
|
- |
|
- |
|
value to be checked if it is finite |
|
value to be checked if it is infinite. |
2.2. Examples
UNWIND [1.0, gds.util.NaN(), gds.util.infinity()] AS value
RETURN gds.util.isFinite(value) AS isFinite
isFinite |
---|
true |
false |
false |
UNWIND [1.0, gds.util.NaN(), gds.util.infinity()] AS value
RETURN gds.util.isInfinite(value) AS isInfinite
isInfinite |
---|
false |
true |
true |
The utility function gds.util.NaN
can be used as an default value for input parameters, as shown in the examples of cosine similarity.
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.alpha.allShortestPaths
.
3. Node and Path Functions
Name | Description |
---|---|
|
|
|
|
3.1. Syntax
Name | Parameters |
---|---|
|
nodeId of a node in the neo4j-graph |
|
list of nodeIds of nodes in the neo4j-graph |
3.2. Examples
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 (u:User{name: 'Alice'})
WITH id(u) AS nodeId
RETURN gds.util.asNode(nodeId).name AS node
node |
---|
"Alice" |
MATCH (u:User)
WHERE NOT u.name = 'Charles'
WITH collect(id(u)) AS nodeIds
RETURN [x in gds.util.asNodes(nodeIds)| x.name] AS nodes
nodes |
---|
[Alice, Bridget] |
As many algorithms streaming mode only return the node id, gds.util.asNode
and gds.util.asNodes
can be used to retrieve the whole node from the neo4j database.
4. Catalog Functions
Catalog functions allow accessing in-memory graphs directly from a Cypher query.
Name | Description |
---|---|
|
Allows accessing a node property stored in a named graph. |
4.1. Syntax
Name | Description |
---|---|
|
Named graph in the catalog, Neo4j node id, node property key and optional node label present in the named-graph. |
If a node label is given, the property value for the corresponding projection and the given node is returned.
If no label or '*'
is given, the property value is retrieved and returned from an arbitrary projection that contains the given propertyKey.
If the property value is missing for the given node, null
is returned.
4.2. Examples
CALL gds.graph.create('my-graph', 'User', 'LINK');
CALL gds.pageRank.mutate('my-graph', { mutateProperty: 'score' })
We can now access the property score
without writing the data to Neo4j.
MATCH (alice:User)
WHERE alice.name = 'Alice'
RETURN
alice.name AS name,
gds.util.nodeProperty('my-graph', id(alice), 'score') AS score
name | score |
---|---|
"Alice" |
0.15000000000000002 |
We can also specifically return the score
property from the User
projection in case other projections also have a score
property as follows.
MATCH (alice:User)
WHERE alice.name = 'Alice'
RETURN
alice.name AS name,
gds.util.nodeProperty('my-graph', id(alice), 'score', 'User') AS score
name | score |
---|---|
"Alice" |
0.15000000000000002 |
Was this page helpful?