This repository was archived by the owner on Sep 18, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
[master < E-nodes] Write docs for nodes #1016
Open
mpintaric55334
wants to merge
7
commits into
master
Choose a base branch
from
E-mage-nodes-docs
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
93f1ada
Write docs for nodes
mpintaric55334 911d58d
relationship_types docs
imilinovic 30214f5
nodes delete docs
imilinovic f7c76ca
small change
imilinovic 682f9cf
Merge branch 'master' of github.com:memgraph/docs into E-mage-nodes-docs
imilinovic d5f7b18
Apply suggestions from code review
vpavicic 1c437bf
change-to-util
vpavicic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
--- | ||
id: nodes | ||
title: nodes | ||
sidebar_label: nodes | ||
--- | ||
|
||
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 `nodes` module provides a comprehensive toolkit for managing multiple graph nodes, enabling linking, updating, type deduction and more. | ||
|
||
[](https://github.com/memgraph/mage/tree/main/cpp/nodes_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(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 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` and `types`. `node` representing the given node and `types` a list of distinct relationship types contained within the given list of types for the corresponding node. | ||
|
||
#### 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 (n:Intern) WITH collect(n) as interns CALL nodes.relationship_types(interns, ["<KNOWS", "SEES>", "HEARS"]) YIELD relationship_types RETURN relationship_types; | ||
``` | ||
|
||
```plaintext | ||
+---------------------------------------+ | ||
| 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 doing detach delete. | ||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Input: | ||
|
||
- `nodes: int|node|List[int|node]` - nodes to be deleted given as nodes themselves or their IDs. | ||
|
||
#### 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); | ||
``` | ||
|
||
The following query will delete all the created nodes and relationships: | ||
```cypher | ||
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. | ||
- anything else results in an exception. | ||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### 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: | ||
|
||
```cypher | ||
CREATE (d:Dog)-[l:LOVES]->(h:Human)-[t:TAKES_CARE_OF]->(d); | ||
``` | ||
|
||
```cypher | ||
MATCH (d:Dog), (h:Human) CALL nodes.relationships_exist([d,id(h)], ["<LOVES","FOLLOWS"]) YIELD result RETURN result; | ||
``` | ||
|
||
```plaintext | ||
+-----------------------------------------------------------------------------------------------------------------------------------------+ | ||
| 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 which are to be linked. | ||
- `type: string` ➡ type of relationship which will be used in linking. | ||
vpavicic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
#### Usage: | ||
|
||
<Tabs | ||
groupId="example" | ||
defaultValue="visualization" | ||
values={[ | ||
{label: 'Step 1: Input graph without linking', value: 'visualization'}, | ||
{label: 'Step 2: Cypher example', value: 'cypher'}, | ||
{label: 'Step 3: Resulting graph', value: 'result'}, | ||
] | ||
}> | ||
<TabItem value="visualization"> | ||
|
||
<img src={require('../../data/query-modules/cpp/nodes/graph_before.png').default}/> | ||
|
||
</TabItem> | ||
|
||
<TabItem value="cypher"> | ||
|
||
```cypher | ||
MATCH (h:Human), (c:Cat), (m:Mouse), (e:Elephant) CALL nodes.link([e, m, c, h, e],"IS_AFRAID_OF"); | ||
``` | ||
|
||
</TabItem> | ||
|
||
<TabItem value="result"> | ||
|
||
<img src={require('../../data/query-modules/cpp/nodes/graph_after.png').default}/> | ||
|
||
</TabItem> | ||
|
||
</Tabs> | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.