Skip to content

Algorithms section & degree docs #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
50 changes: 35 additions & 15 deletions algorithms/degree.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
---
title: "Degree"
description: "Measures the number of incoming or outgoing conections for all nodes."
parent: "Algorithms"
---
Comment on lines +1 to +5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix typo in front-matter description.

There's a misspelling in the description field.

- description: "Measures the number of incoming or outgoing conections for all nodes."
+ description: "Measures the number of incoming or outgoing connections for all nodes."
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
---
title: "Degree"
description: "Measures the number of incoming or outgoing conections for all nodes."
parent: "Algorithms"
---
---
title: "Degree"
description: "Measures the number of incoming or outgoing connections for all nodes."
parent: "Algorithms"
---
🤖 Prompt for AI Agents
In algorithms/degree.md at lines 1 to 5, fix the typo in the front-matter
description by correcting "conections" to "connections" to ensure the
description reads accurately.


# Degree Procedure Documentation

## Introduction
Expand All @@ -20,20 +26,24 @@ Here are some practical scenarios where the **Degree Procedure** can be applied:

## Syntax

```plaintext
CALL algo.degree(config)
The procedure has the following call signature:
```procedure input:
CALL algo.dgree({
'srcLabels': [<label>, ...],
'dir': 'incoming' / 'outgoing' / 'both',
'relationshipTypes': [<type>, ...],
'destLabels': [<label>, ...],
})
```

### Parameters

The `config` parameter is a Map object containing the following optional keys:

| Key | Type | Default | Description |
| ------------- | ------ | ---------- | ---------------------------------------------------------------------- |
| `source` | String | `null` | Specifies the label of nodes for which the degree is computed. |
| `dir` | String | `outgoing` | Direction of edges to consider: `incoming` or `outgoing`. |
| `relation` | String | `null` | Specifies the type of edges to consider. |
| `destination` | String | `null` | Specifies the label of nodes reachable via the edges being considered. |
| Name | Type | Description | Default |
|---------------------|-----------------------|--------------------------------------------|-----------|
| `srcLabels` | [optional] [string[]] | type of nodes for which degree is computed | All Nodes |
| `dir` | [optional] [string] | 'incoming', 'outgoing', or 'both' | outgoing |
| `relationshipTypes` | [optional] [string[]] | the type of edges to consider | All edges |
| `destLabels` | [optional] [string[]] | type of reachable nodes | All Nodes |

---

Expand Down Expand Up @@ -90,7 +100,7 @@ CREATE (p2)-[:VISITED]->(c2:City {id: 4})
### Example 1: Compute the outgoing degree for all nodes

```plaintext
CALL algo.degree({})
CALL algo.degree()
```

#### Result:
Expand All @@ -107,7 +117,7 @@ CALL algo.degree({})
### Example 2: Compute the outgoing degree for specific node types

```plaintext
CALL algo.degree({source: 'Person'})
CALL algo.degree({srcLabels: ['Person']})
```

#### Result:
Expand All @@ -119,24 +129,25 @@ CALL algo.degree({source: 'Person'})

---

### Example 3: Compute the outgoing degree for a specific relationship type
### Example 3: Compute the total degree for a specific relationship type

```plaintext
CALL algo.degree({source: 'Person', relation: 'FRIEND', dir: 'outgoing'})
CALL algo.degree({srcLabels: ['Person'], relationshipTypes: ['FRIEND'], dir: 'total'})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dir can't be 'total'

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the default if not specified ? is it 'outgoing' ?

```

#### Result:

| Node | Degree |
| ---- | ------ |
| 1 | 1 |
| 2 | 1 |

---

### Example 4: Compute the incoming degree for reachable nodes of a specific type

```plaintext
CALL algo.degree({source: 'Person', relation: 'VISITED', dir: 'incoming', destination: 'City'})
CALL algo.degree({srcLabels: ['Person'], relationshipTypes: ['VISITED'], dir: 'incoming', destLabels: ['City']})
```

#### Result:
Expand All @@ -146,4 +157,13 @@ CALL algo.degree({source: 'Person', relation: 'VISITED', dir: 'incoming', destin
| 3 | 2 |
| 4 | 1 |

## Usage Notes

- When `both` is specified, the in and out degrees of the node are summed. So if
(a)-[:R]->(b) and (b)-[:R]->(a) then (a) would have a degree of 2 when
`both` is specified.
- When multiple labels are specified, the nodes' degrees accross each of those
labels are summed together.
- This algorithm counts multi-edges and self-edges towards the degree.
- Computationally cheapest when computing the outdegree, especially on
undirected graphs.