nodes
The nodes
module provides a comprehensive toolkit for managing multiple graph nodes, enabling linking, updating, type deduction and more.
Trait | Value |
---|---|
Module type | algorithm |
Implementation | C++ |
Graph direction | directed/undirected |
Edge weights | weighted/unweighted |
Parallelism | sequential |
Procedures
You can execute this algorithm on graph projections, subgraphs or portions of the graph.
relationship_types(nodes, types)
Returns a list of distinct relationship types of the given node(s) contained within the given list of types. If the list of types is empty, the procedure returns all distinct relationship types. Relationship types can also be directed:
- <type - incoming relationship.
- type> - outgoing relationship.
- type - either way.
Input:
node: int|node|List[int|node]
➡ input nodes given as nodes themselves or their IDs.types: List[string] (default = [])
➡ list of relationship types to filter by.
Output:
relationship_types: List[Map]
➡ Each list element is a map with two keys:node
andtypes
.node
representing the given node andtypes
a list of distinct relationship types contained within the given list of types for the corresponding node.
Usage:
CREATE (ivan: Intern {name: 'Ivan'})
CREATE (idora: Intern {name: 'Idora'})
CREATE (matija: Intern {name: 'Matija'})
MERGE (ivan)-[:KNOWS]->(idora)
MERGE (matija)-[:HEARS]->(idora)
MERGE (matija)-[:SEES]->(ivan);
MATCH (n:Intern) WITH collect(n) as interns CALL nodes.relationship_types(interns, ["<KNOWS", "SEES>", "HEARS"]) YIELD relationship_types RETURN relationship_types;
+---------------------------------------+
| relationship_types |
| [ |
| { |
| "node": { |
| "labels": [ |
| "Intern" |
| ], |
| "properties": { |
| "name": "Ivan" |
| }, |
| "type": "node" |
| }, |
| "types": [] |
| }, |
| { |
| "node": { |
| "labels": [ |
| "Intern" |
| ], |
| "properties": { |
| "name": "Idora" |
| }, |
| "type": "node" |
| }, |
| "types": [ |
| "HEARS", |
| "KNOWS" |
| ] |
| }, |
| { |
| "node": { |
| "labels": [ |
| "Intern" |
| ], |
| "properties": { |
| "name": "Matija" |
| }, |
| "type": "node" |
| }, |
| "types": [ |
| "SEES", |
| "HEARS" |
| ] |
| } |
| ] |
+---------------------------------------+
delete(nodes)
Deletes the given node(s) from the graph. Equivalent to running a DETACH DELETE
query.
Input:
nodes: int|node|List[int|node]
- nodes to be deleted given as nodes themselves or their IDs.
Usage:
CREATE (ivan: Intern {name: 'Ivan'})
CREATE (idora: Intern {name: 'Idora'})
CREATE (matija: Intern {name: 'Matija'})
MERGE (ivan)-[:KNOWS]->(idora)
MERGE (matija)-[:HEARS]->(idora)
MERGE (matija)-[:SEES]->(ivan);
The following query will delete all the created nodes and relationships:
MATCH (n:Intern) WITH collect(n) as interns CALL nodes.delete(interns);
relationships_exist(nodes, relationships)
Checks if relationships in the input list exist at the given nodes. Results are returned as a map, which contains two smaller maps. The first map represents the node, and the second map represents the relationship status map of the node. Relationships can be directed, and the syntax for direction specification is provided below:
- <type - incoming relationship.
- type> - outgoing relationship.
- type - both incoming and outgoing.
Any other syntax results in an exception.
Input:
nodes: List[Any]
➡ list of input nodes. Elements of the list can be either nodes themselves or their IDs.relationships: List[string]
➡ list of relationships to be checked.
Output:
result: Map
➡ result map, containing two smaller maps. The first map represents the node, and the second represents the status of relationships checked in the function. Example of the map:{"Node": {"id": 0, "labels": ["Dog"], "properties": {},"type": "node"}, "Relationships_exist_status": {"RUNS": false}}
Usage:
CREATE (d:Dog)-[l:LOVES]->(h:Human)-[t:TAKES_CARE_OF]->(d);
MATCH (d:Dog), (h:Human) CALL nodes.relationships_exist([d,id(h)], ["<LOVES","FOLLOWS"]) YIELD result RETURN result;
+-----------------------------------------------------------------------------------------------------------------------------------------+
| result |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| {"Node": {"id": 0,"labels": ["Dog"],"properties": {},"type": "node"},"Relationships_exist_status": {"<LOVES": false,"FOLLOWS": false}} |
+-----------------------------------------------------------------------------------------------------------------------------------------+
| {"Node": {"id": 1,"labels": ["Human"],"properties": {},"type": "node"},"Relationships_exist_status": {"<LOVES": true,"FOLLOWS": false}} |
+-----------------------------------------------------------------------------------------------------------------------------------------+
link(nodes, type)
Links the provided nodes sequentially with the relationship type provided in the input, essentially creating a linked list of nodes.
Input:
nodes: List[Node]
➡ list of input nodes that need to be linked.type: string
➡ type of relationship that will link two nodes.
Usage:
The database contains the following graph objects:
Run the following query
MATCH (h:Human), (c:Cat), (m:Mouse), (e:Elephant) CALL nodes.link([e, m, c, h, e],"IS_AFRAID_OF");
The database changes to the following state: