diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md new file mode 100644 index 00000000000..322a996c762 --- /dev/null +++ b/mage/query-modules/cpp/node.md @@ -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}) => ( + +{children} + +); + +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** | **algorithm** | +| **Implementation** | **C++** | +| **Graph direction** | **directed**/**undirected** | +| **Edge weights** | **weighted**/**unweighted** | +| **Parallelism** | **sequential** | + +## 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: +- <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, ["", "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., "' 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, [" - 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", "": true, "TAKES_CARE_OF": true} | ++----------------------------------------------------------------------------+ +``` + +```cypher +MATCH (h:Human) CALL node.relationships_exist(h, ["LOVES>", "TAKES_CARE_OF", "FOLLOWS", "": false, "TAKES_CARE_OF": true} | ++----------------------------------------------------------------------------+ +``` diff --git a/mage/templates/_mage_spells.mdx b/mage/templates/_mage_spells.mdx index 2fb020f459d..c09e52bf127 100644 --- a/mage/templates/_mage_spells.mdx +++ b/mage/templates/_mage_spells.mdx @@ -63,6 +63,7 @@ | [llm_util](/mage/query-modules/python/llm-util) | Python | A module that contains procedures describing graphs in a format best suited for large language models (LLMs). | | [meta_util](/mage/query-modules/python/meta-util) | Python | A module that contains procedures describing graphs on a meta-level. | | [migrate](/mage/query-modules/python/migrate) | Python | A module that can access data from a MySQL, SQL Server or Oracle database. | +| [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. | | [periodic](/mage/query-modules/cpp/periodic) | C++ | A module containing procedures for periodically running difficult and/or memory/time consuming queries. | | rust_example | Rust | Example of a basic module with input parameters forwarding, made in Rust. | | [uuid_generator](/mage/query-modules/cpp/uuid-generator) | C++ | A module that generates a new universally unique identifier (UUID). | diff --git a/sidebars/sidebarsMAGE.js b/sidebars/sidebarsMAGE.js index 40af17b01fb..7beabcf054a 100644 --- a/sidebars/sidebarsMAGE.js +++ b/sidebars/sidebarsMAGE.js @@ -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",