Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

[master < E-node] Add docs for node module #1013

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
161 changes: 161 additions & 0 deletions mage/query-modules/cpp/node.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
---
id: node
title: node
sidebar_label: node
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import RunOnSubgraph from '../../templates/_run_on_subgraph.mdx';

export const Highlight = ({children, color}) => (
<span
style={{
backgroundColor: color,
borderRadius: '2px',
color: '#fff',
padding: '0.2rem',
}}>
{children}
</span>
);

The `node` module provides a comprehensive toolkit for managing graph nodes, enabling creation, deletion, updating, merging, and more.

[![docs-source](https://img.shields.io/badge/source-node-FB6E00?logo=github&style=for-the-badge)](https://github.com/memgraph/mage/tree/main/cpp/node_module)

| Trait | Value |
| ------------------- | ----------------------------------------------------- |
| **Module type** | <Highlight color="#FB6E00">**algorithm**</Highlight> |
| **Implementation** | <Highlight color="#FB6E00">**C++**</Highlight> |
| **Graph direction** | <Highlight color="#FB6E00">**directed**</Highlight>/<Highlight color="#FB6E00">**undirected**</Highlight> |
| **Edge weights** | <Highlight color="#FB6E00">**weighted**</Highlight>/<Highlight color="#FB6E00">**unweighted**</Highlight> |
| **Parallelism** | <Highlight color="#FB6E00">**sequential**</Highlight> |

## Procedures

### `relationship_types(node, types)`

Returns a list of distinct relationship types of the given node contained within the given list of types. If the list of types is empty returns all distinct relationship types. Relationship types can also be directed:
- &lt;type - incoming relationship.
- type> - outgoing relationship.
- type - either way.

#### Input:

- `node: Node` ➡ the given node.
- `types: List[string] (default = [])` ➡ list of relationship types to filter by.

#### Output:

- `relationship_types: List[string]` ➡ list of distinct relationship types contained within the given list of types.

#### Usage:

```cypher
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);
```

```cypher
MATCH (intern:Intern) CALL node.relationship_types(intern, ["<KNOWS", "SEES>", "HEARS"]) yield relationship_types return intern.name as name, relationship_types;
```

```plaintext
+--------------------------------+
| name relationship_types |
+--------------------------------+
| Ivan [] |
+--------------------------------+
| Idora ["HEARS", "KNOWS"] |
+--------------------------------+
| Matija ["SEES", "HEARS"] |
+--------------------------------+
```

### `relationship_exists(node, pattern)`

Checks if given node has a relationship of the pattern.

#### Input:

- `node: Node` ➡ node for which relationship existance is to be verified.
- `pattern: List[string] (optional)` ➡ list of relationship types for which it will be checked if at least one of them exists; if nothing is stated, procedure checks all types of relationships.

:::info

If '<' is added in front of the relationship type, only relationships coming into the node will be checked (e.g., "<KNOWS"), while if '>' is added at the end of the relationship type, only relationships coming from the node will be checked (e.g., "KNOWS>").
Furthermore, if relationship type is not relevant, it is possible to enter only "<" or ">" to check incoming or outgoing relationships.

:::

#### Output:

- `exists: bool` ➡ whether or not provided node has a relationship of specified type.

#### Usage:

```cypher
MERGE (a:Person {name: "Phoebe"}) MERGE (b:Person {name: "Joey"}) CREATE (a)-[f:FRIENDS]->(b);
MATCH (a:Person {name: "Joey"}) CALL node.relationship_exists(a, ["<FRIENDS"])
YIELD exists RETURN exists;
```

```plaintext
+----------------------------+
| exists |
+----------------------------+
| True |
+----------------------------+
```

### `relationships_exist(node, relationships)`

Checks if relationships in the input list exist at the given node. Results are returned as a map, represented as string-bool pair, where string represents the relationship, and bool represents if the relationship exists or not. Relationships can be directed, and the syntax for direction specification is provided below:
- &lt;type - incoming relationship.
- type> - outgoing relationship.
- type - both incoming and outgoing.
- anything else results in an exception.

#### Input:

- `node: Node` ➡ the input node.
- `relationships: List[string]` ➡ list of relationships to be checked.

#### Output:

- `result: Map` ➡ map of string-bool pairs, where string represents the relationship, and bool represents if the relationship exist or not. Example: `{rel1: true, rel2>: false}` means rel1 exists, and outgoing rel2 doesn't exist.

#### Usage:

```cypher
CREATE (d:Dog)-[l:LOVES]->(h:Human)-[t:TAKES_CARE_OF]->(d);
```

```cypher
MATCH (d:Dog) CALL node.relationships_exist(d, ["LOVES>", "TAKES_CARE_OF", "FOLLOWS", "<LOVES"]) YIELD result RETURN result;
```

```plaintext
+----------------------------------------------------------------------------+
| result |
+----------------------------------------------------------------------------+
| {"<LOVES": false, "FOLLOWS": false, "LOVES>": true, "TAKES_CARE_OF": true} |
+----------------------------------------------------------------------------+
```

```cypher
MATCH (h:Human) CALL node.relationships_exist(h, ["LOVES>", "TAKES_CARE_OF", "FOLLOWS", "<LOVES"]) YIELD result RETURN result;
```

```plaintext
+----------------------------------------------------------------------------+
| result |
+----------------------------------------------------------------------------+
| {"<LOVES": true, "FOLLOWS": false, "LOVES>": false, "TAKES_CARE_OF": true} |
+----------------------------------------------------------------------------+
```
1 change: 1 addition & 0 deletions mage/templates/_mage_spells.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
| [map](/mage/query-modules/cpp/map) | C++ | The map module offers a versatile toolkit for manipulating collections of key-value pairs, enabling advanced data operations within a graph database context |
| [max_flow](/mage/query-modules/python/max-flow) | Python | An algorithm for finding a flow through a graph such that it is the maximum possible flow. |
| [neighbors](/mage/query-modules/cpp/neighbors) | C++ | The neighbors module allows users to interact with and query nodes that have direct relationships to a specified node. |
| [node](/mage/query-modules/cpp/node) | C++ | A module that provides a comprehensive toolkit for managing graph nodes, enabling creation, deletion, updating, merging, and more. |
| [node_similarity](/mage/query-modules/cpp/node-similarity) | C++ | A module that contains similarity measures for calculating the similarity between two nodes. |
| [pagerank](/mage/query-modules/cpp/pagerank) | C++ | Algorithm that yields the influence measurement based on the recursive information about the connected nodes influence. |
| [set_cover](/mage/query-modules/python/set-cover) | Python | An algorithm for finding the minimum cost subcollection of sets that covers all elements of a universe. |
Expand Down
1 change: 1 addition & 0 deletions sidebars/sidebarsMAGE.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ module.exports = {
"query-modules/python/meta-util",
"query-modules/python/migrate",
"query-modules/cpp/neighbors",
"query-modules/cpp/node",
"query-modules/python/node-classification-with-gnn",
"query-modules/python/node2vec",
"query-modules/python/node2vec-online",
Expand Down