From fba4865bb579e02deed26534e12df2f3df300adc Mon Sep 17 00:00:00 2001 From: ind1xa <95344788+ind1xa@users.noreply.github.com> Date: Mon, 14 Aug 2023 11:48:24 +0200 Subject: [PATCH 01/11] add initial structure for node docs --- mage/query-modules/cpp/node.md | 35 +++++++++++++++++++++++++++++++++ mage/templates/_mage_spells.mdx | 1 + sidebars/sidebarsMAGE.js | 1 + 3 files changed, 37 insertions(+) create mode 100644 mage/query-modules/cpp/node.md diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md new file mode 100644 index 00000000000..2f29a2ce916 --- /dev/null +++ b/mage/query-modules/cpp/node.md @@ -0,0 +1,35 @@ +--- +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 diff --git a/mage/templates/_mage_spells.mdx b/mage/templates/_mage_spells.mdx index 83634d4a33b..450762c1ee1 100644 --- a/mage/templates/_mage_spells.mdx +++ b/mage/templates/_mage_spells.mdx @@ -16,6 +16,7 @@ | [kmeans](/mage/query-modules/python/kmeans) | Python | An algorithm for clustering given data. | | [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. | +| [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. | diff --git a/sidebars/sidebarsMAGE.js b/sidebars/sidebarsMAGE.js index 3d940c7c061..9dfd0de6145 100644 --- a/sidebars/sidebarsMAGE.js +++ b/sidebars/sidebarsMAGE.js @@ -52,6 +52,7 @@ module.exports = { "query-modules/python/max-flow", "query-modules/python/meta-util", "query-modules/python/migrate", + "query-modules/cpp/node", "query-modules/python/node-classification-with-gnn", "query-modules/python/node2vec", "query-modules/python/node2vec-online", From 9e6e7dc9f583bff1eca06138bcc07d0d80af437e Mon Sep 17 00:00:00 2001 From: ind1xa <95344788+ind1xa@users.noreply.github.com> Date: Mon, 14 Aug 2023 12:40:58 +0200 Subject: [PATCH 02/11] add rel_exists docs --- mage/query-modules/cpp/node.md | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index 2f29a2ce916..2005fa31987 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -33,3 +33,39 @@ The `node` module provides a comprehensive toolkit for managing graph nodes, ena | **Parallelism** | **sequential** | ### Procedures + +### `relationship_exists(node, pattern)` + +Checks if given node has a relationship of the pattern. + +#### Input: + +- `node: Node` ➡ node whose 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 ingoing 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, [" Date: Thu, 17 Aug 2023 09:23:34 +0200 Subject: [PATCH 03/11] relationship_types --- mage/query-modules/cpp/node.md | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index 2f29a2ce916..8db1dbf75c0 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -33,3 +33,46 @@ The `node` module provides a comprehensive toolkit for managing graph nodes, ena | **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: +- \ - 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"] | ++--------------------------------+ +``` \ No newline at end of file From 088c62e6f120c2468f17bf39bf57974c19bc9c58 Mon Sep 17 00:00:00 2001 From: imilinovic Date: Thu, 17 Aug 2023 09:24:05 +0200 Subject: [PATCH 04/11] newline at end --- mage/query-modules/cpp/node.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index 8db1dbf75c0..aa9af900121 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -75,4 +75,4 @@ MATCH (intern:Intern) CALL node.relationship_types(intern, ["", " +--------------------------------+ | Matija ["SEES", "HEARS"] | +--------------------------------+ -``` \ No newline at end of file +``` From 77de6afac1cbc51ba5754177515ccb817fbd0fe3 Mon Sep 17 00:00:00 2001 From: ind1xa <95344788+ind1xa@users.noreply.github.com> Date: Fri, 18 Aug 2023 08:53:10 +0200 Subject: [PATCH 05/11] add fullstops --- mage/query-modules/cpp/node.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index 2005fa31987..3cbdd3977a2 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -40,8 +40,8 @@ Checks if given node has a relationship of the pattern. #### Input: -- `node: Node` ➡ node whose 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 +- `node: Node` ➡ node whose 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 @@ -52,14 +52,14 @@ Furthermore, if relationship type is not relevant, it is possible to enter only #### Output: -- `exists: bool` ➡ whether or not provided node has a relationship of specified type +- `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, [" Date: Wed, 30 Aug 2023 11:34:35 +0200 Subject: [PATCH 06/11] Add node function (#1014) --- mage/query-modules/cpp/node.md | 51 +++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index aa9af900121..bc82a3ded5d 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -37,7 +37,7 @@ The `node` module provides a comprehensive toolkit for managing graph nodes, ena ### `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: -- \ - outgoing relationship - type - either way @@ -76,3 +76,52 @@ MATCH (intern:Intern) CALL node.relationship_types(intern, ["", " | Matija ["SEES", "HEARS"] | +--------------------------------+ ``` + + +### `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: +- <type - incoming relationship. +- type> - outgoing relationship. +- type - both incoming and outgoing. +- anything else results in an excpetion. + +#### 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} | ++----------------------------------------------------------------------------+ +``` + From 178e022036825419cd58be89a9ef15574e5d1e15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Pintari=C4=87?= <99442742+mpintaric55334@users.noreply.github.com> Date: Wed, 30 Aug 2023 15:43:14 +0200 Subject: [PATCH 07/11] Fix small spelling error --- mage/query-modules/cpp/node.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index bc82a3ded5d..44598c190ae 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -84,7 +84,7 @@ Checks if relationships in the input list exist at the given node. Results are r - <type - incoming relationship. - type> - outgoing relationship. - type - both incoming and outgoing. -- anything else results in an excpetion. +- anything else results in an exception. #### Input: From 035d836144e16e00e4bb48b2e0e20c0443c2b5e7 Mon Sep 17 00:00:00 2001 From: imilinovic Date: Thu, 31 Aug 2023 14:00:15 +0200 Subject: [PATCH 08/11] fix typo --- mage/query-modules/cpp/node.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index aa9af900121..33d22e57de2 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -37,7 +37,7 @@ The `node` module provides a comprehensive toolkit for managing graph nodes, ena ### `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: -- \ - outgoing relationship - type - either way From 08978f004a30aeddc3234d7ba599ae7d607516df Mon Sep 17 00:00:00 2001 From: imilinovic Date: Thu, 31 Aug 2023 14:03:30 +0200 Subject: [PATCH 09/11] fix typos --- mage/query-modules/cpp/node.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index ab66a011208..d9014412068 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -37,7 +37,7 @@ The `node` module provides a comprehensive toolkit for managing graph nodes, ena ### `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 - ingoing relationship +- <type - incoming relationship - type> - outgoing relationship - type - either way @@ -89,7 +89,7 @@ Checks if given node has a relationship of the pattern. :::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 ingoing or outgoing relationships. +Furthermore, if relationship type is not relevant, it is possible to enter only "<" or ">" to check incoming or outgoing relationships. ::: From f68689d64dddb730a16cf030fe1a66cfda1fe444 Mon Sep 17 00:00:00 2001 From: Vlasta <95473291+vpavicic@users.noreply.github.com> Date: Thu, 31 Aug 2023 15:41:02 +0200 Subject: [PATCH 10/11] Apply suggestions from code review --- mage/query-modules/cpp/node.md | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/mage/query-modules/cpp/node.md b/mage/query-modules/cpp/node.md index d9014412068..322a996c762 100644 --- a/mage/query-modules/cpp/node.md +++ b/mage/query-modules/cpp/node.md @@ -32,23 +32,23 @@ The `node` module provides a comprehensive toolkit for managing graph nodes, ena | **Edge weights** | **weighted**/**unweighted** | | **Parallelism** | **sequential** | -### Procedures +## 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 +- <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 +- `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 +- `relationship_types: List[string]` ➡ list of distinct relationship types contained within the given list of types. #### Usage: @@ -113,7 +113,6 @@ YIELD exists RETURN exists; +----------------------------+ ``` - ### `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: From 2b420f55955fbd3312af77902aa79d01bd58df64 Mon Sep 17 00:00:00 2001 From: Vlasta Date: Tue, 12 Sep 2023 13:59:50 +0200 Subject: [PATCH 11/11] change-to-util --- mage/templates/_mage_spells.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mage/templates/_mage_spells.mdx b/mage/templates/_mage_spells.mdx index 827bf9714e0..c09e52bf127 100644 --- a/mage/templates/_mage_spells.mdx +++ b/mage/templates/_mage_spells.mdx @@ -19,7 +19,6 @@ | [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. | @@ -64,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). |