diff --git a/pages/advanced-algorithms/available-algorithms/path.mdx b/pages/advanced-algorithms/available-algorithms/path.mdx index f5a6297e..3acbc854 100644 --- a/pages/advanced-algorithms/available-algorithms/path.mdx +++ b/pages/advanced-algorithms/available-algorithms/path.mdx @@ -145,6 +145,79 @@ The result is returned in shortened form with () signifying nodes and [] signify ## Procedures +The `path` module consist of the following procedures: + +- [`create()`](#create) +- [`expand()`](#expand) +- [`subgraph_all()`](#subgraph_all) +- [`subgraph_nodes()`](#subgraph_nodes) + +The `expand()`, `subgraph_all()` and `subgraph_nodes()` procedures support +additional [relationship and label filtering](#filtering). + +### Filtering rules + +{

Relationship filters

} + +Relationships in the `relationships` list provided as the input can be filtered using the following notation: + +| Option | Explanation | +|--------------------|-------------------------------------------------------------------------------------------------------------| +| `TYPE` | Path will expand with either outgoing or incoming relationships of this type. | +| `` | Path will expand with outgoing relationships of this type. | +| `` | Path will expand if both incoming and outgoing relationship of this type exists between the same two nodes. | +| `>` | Path will expand with all outgoing relationships. | +| `<` | Path will expand will all incoming relationships. | + +If the relationship filter is empty, all relationship types are allowed. + +**Examples:** + +Here are the examples for the `relationships` list argument and how they affect the expansion: +- `[]` : path will expand on incoming relationship of type `LOVES` and on outgoing relationships of any type. +- `[Label filters} + +Labels in the `labels` list provided as the input can be filtered using the following notation: + +|Option | Explanation | +|--------------------|------------------------------------------------------------------------------| +| `+LABEL` | Label is added to the whitelist. All nodes in the path must have a label in the whitelist. If the whitelist is empty, it is as if all nodes are whitelisted. | +| `>LABEL` | Label is added to the end list. When end list has labels, only paths ending with these labels will be returned, but they can be expanded further, to return paths ending in nodes with end labels beyond it, but the expansion will only go through nodes with whitelisted labels. Labels in the end list do not have to respect the whitelist. | +| `-LABEL` | Label is added to the blacklist. No node in the path will contain labels in the blacklist. The blacklist takes precedence over all other filters. | +| `/LABEL` | Label is added to the termination list. When termination list contains labels, only paths ending with these labels will be returned, and any further expansion is stopped. Labels in the termination list do not have to respect the whitelist. | + +Any other label syntax is added to the whitelist. For example, `LABEL` will be +added to the whitelist as `LABEL`, and `!LABEL` will be added to the whitelist +as `!LABEL`. + +To know where the label will be added, look at the first element of the label. +For example, `>LABEL>` will be added to the end list as `LABEL>`. + +**Examples:** + +Below are the examples for the `labels` list argument and how they affect the expansion. + +Imagine a starting node being `Dog` node. +- `["/Mouse"]` - The filtering will return all the paths starting with `Dog` + node and ending with `Mouse` (`Mouse` label is added to the termination list), + regardless of the other labels it's passing through (all labels are + whitelisted since the whitelist is empty). +- `["/Mouse", "Cat"]` - The filtering will return all paths starting with `Dog` + node and ending with `Mouse` that expand exclusively through `Cat` labels + (`Cat` label is **the only** whitelisted label). +- `["/Mouse", "-Cat", "-Human"]` - The filtering will return all paths starting + with `Dog` node and ending with `Mouse` that don't expand through `Cat` or + `Human` labels (those labels are blacklisted). + +Next, let the starting node be a `Cat` node. +- `[">Dog", "+Human", "+Wolf"]` - The filtering will return all paths starting + with `Cat` node and ending with `Dog` node that contain whitelisted `Human` + and `Wolf` nodes. + ### `create()` The procedure creates a path from the given starting node and a list of @@ -204,81 +277,19 @@ The procedure expands from the start node(s) following the given relationships and label filters, from min to max number of allowed hops. Return all paths inside the allowed number of hops, which satisfy relationship and label filters. -{

Input:

} +{

Input:

} - `subgraph: Graph` (**OPTIONAL**) ➡ A specific subgraph, which is an [object of type Graph](/advanced-algorithms/run-algorithms#run-procedures-on-subgraph) returned by the `project()` function, on which the algorithm is run. If subgraph is not specified, the algorithm is computed on the entire graph by default. - `start: any` ➡ A node, node ID, or a list of nodes and/or node IDs from which the function will expand. - `relationships: List[string]` ➡ A list of relationships which the expanding - will follow. Relationships can be filtered using the notation described below. + will follow. Relationships can be filtered using the notation described in the [filtering rules](#filtering-rules). - `labels: List[string]` ➡ A list of labels which will define filtering. Labels - can be filtered using the notation described below. + can be filtered using the notation described in the [filtering rules](#filtering-rules). - `min_hops: int` ➡ The minimum number of hops for a path to be returned. - `max_hops: int` ➡ The maximum number of hops for a path to be returned. -**Relationship filters:** - -| Option | Explanation | -|--------------------|-------------------------------------------------------------------------------------------------------------| -| `TYPE` | Path will expand with either outgoing or incoming relationships of this type. | -| `` | Path will expand with outgoing relationships of this type. | -| `` | Path will expand if both incoming and outgoing relationship of this type exists between the same two nodes. | -| `>` | Path will expand with all outgoing relationships. | -| `<` | Path will expand will all incoming relationships. | - -If the relationship filter is empty, all relationship types are allowed. - -**Examples:** - -- `Relationship list : []` : path will expand on all outgoing relationships, and incoming relationship `LOVES`. -- `Relationship list : [LABEL` | Label is added to the end list. When end list has labels, only paths ending with these labels will be returned, but they can be expanded further, to return paths ending in nodes with end labels beyond it, but the expansion will only go through nodes with whitelisted labels. Labels in the end list do not have to respect the whitelist. | -| `-LABEL` | Label is added to the blacklist. No node in the path will contain labels in the blacklist. The blacklist takes precedence over all other filters. | -| `/LABEL` | Label is added to the termination list. When termination list contains labels, only paths ending with these labels will be returned, and any further expansion is stopped. Labels in the termination list do not have to respect the whitelist. | - -Any other label syntax is added to the whitelist. For example, `LABEL` will be -added to the whitelist as `LABEL`, and `!LABEL` will be added to the whitelist -as `!LABEL`. - -To know where the label will be added, look at the first element of the label. -For example, `>LABEL>` will be added to the end list as `LABEL>`. - -**Examples:** - -Consider the graph provided in the usage section below. In this subsection, -number of hops will be limited from 0 to 2, and the starting node will be `Dog`. - -- `Label list: ["/Mouse"]` - The filtering will return all the paths ending with - `Mouse`. Because no labels were added to the whitelist, all labels are - considered whitelisted. The filtering will return 3 paths: `Dog->Cat->Mouse`, - `Dog<-Human->Mouse`, `Dog->Mouse`. -- `Label list: ["/Mouse", "Cat"]` - Now, label `Cat` is added to the whitelist, - becoming the only whitelisted label. The meaning of the filter can now be - represented as: `"return all paths ending with Mouse, which expand through Cat - and Cat only"`. This filtering will return two paths, one where `Dog` connects - to the `Mouse` directly(`Dog->Mouse`), and one where `Cat` is - included (`Dog->Cat->Mouse`). -- `Label list: ["/Mouse", "-Cat", "-Human"]` - Now, both `Cat` and `Human` are - blacklisted, and there is only one eligible path that can reach `Mouse`: - `Dog->Mouse`. - -For the final example, the starting node is `Cat`, and the maximum number of -hops is increased to 4. - -- `Label list: [">Dog", "+Human", "+Wolf"]` - Now, only paths ending with `Dog` - will be returned, but they can be further expaned through the nodes with - whitelisted labels. This filtering returns 3 paths: `Cat<-Dog`, - `Cat<-Dog<-Human->Wolf->Dog`, `Cat<-Dog<-Wolf<-Human->Dog`. - {

Output:

} - `result: Path` ➡ all paths expanded from the start node. @@ -377,74 +388,10 @@ If subgraph is not specified, the algorithm is computed on the entire graph by d |- |- |- |- | | minHops | Int | 0 | The minimum number of hops in the traversal. Set to `0` if the start node should be included in the subgraph, or `1` otherwise. | | maxHops | Int | -1 | The maximum number of hops in the traversal. | - | relationshipFilter | List | [ ] | List of relationships which the subgraph formation will follow. Relationships - can be filtered using the notation described below. | - | labelFilter | List | [ ] | List of labels which will define filtering. Labels - can be filtered using the notation described below. | + | relationshipFilter | List | [ ] | List of relationships which the subgraph formation will follow. Relationships can be filtered using the notation described in the [filtering rules](#filtering-rules). | + | labelFilter | List | [ ] | List of labels which will define filtering. Labelscan be filtered using the notation described in the [filtering rules](#filtering-rules). | | filterStartNode | Bool | False | Whether the `labelFilter` applies to the start nodes. | -**Relationship filters:** - -| Option | Explanation | -|--------------------|-------------------------------------------------------------------------------------------------------------| -| `TYPE` | Path will expand with either outgoing or incoming relationships of this type. | -| `` | Path will expand with outgoing relationships of this type. | -| `` | Path will expand if both incoming and outgoing relationship of this type exists between the same two nodes. | -| `>` | Path will expand with all outgoing relationships. | -| `<` | Path will expand will all incoming relationships. | - -If the relationship filter is empty, all relationship types are allowed. - -**Examples:** - -- `Relationship list : []` : The path will expand on all outgoing relationships, and incoming relationship `LOVES`. -- `Relationship list : [LABEL` | Label is added to the end list. When end list has labels, only paths ending with these labels will be returned, but they can be expanded further, to return paths ending in nodes with end labels beyond it, but the expansion will only go through nodes with whitelisted labels. Labels in the end list do not have to respect the whitelist. | -| `-LABEL` | Label is added to the blacklist. No node in the path will contain labels in the blacklist. The blacklist takes precedence over all other filters. | -| `/LABEL` | Label is added to the termination list. When termination list contains labels, only paths ending with these labels will be returned, and any further expansion is stopped. Labels in the termination list do not have to respect the whitelist. | - -Any other label syntax is added to the whitelist. For example, `LABEL` will be -added to the whitelist as `LABEL`, and `!LABEL` will be added to the whitelist -as `!LABEL`. - -To know where the label will be added, look at the first element of the label. -For example, `>LABEL>` will be added to the end list as `LABEL>`. - -**Examples** - -Consider the graph provided in the usage section below. In this subsection, number of hops will be limited from 0 to 2, and the starting node will be `Dog`. - -- `Label list: ["/Mouse"]` - The filtering will return all the paths ending with - `Mouse`. Because no labels were added to the whitelist, all labels are - considered whitelisted. This filtering will return 3 paths: `Dog->Cat->Mouse`, - `Dog<-Human->Mouse`, `Dog->Mouse`. -- `Label list: ["/Mouse", "Cat"]` - Now, label `Cat` is added to the whitelist, - becoming the only whitelisted label. The meaning of the filter can now be - represented as: `"return all paths ending with Mouse, which expand through Cat and Cat only"`. - This filtering will return two paths, one where `Dog` connects - to the `Mouse` directly (`Dog->Mouse`), and one where `Cat` is - included (`Dog->Cat->Mouse`). -- `Label list: ["/Mouse", "-Cat", "-Human"]` - Now, both `Cat` and `Human` are - blacklisted, and there is only one eligible path that can reach `Mouse`: - `Dog->Mouse`. - -For the final example, the starting node is `Cat`, and the maximum number of -hops is increased to 4. - -- `Label list: [">Dog", "+Human", "+Wolf"]` - Now, only paths ending with `Dog` - will be returned, but they can be further expaned through the nodes with - whitelisted labels. This filtering returns 3 paths: `Cat<-Dog`, - `Cat<-Dog<-Human->Wolf->Dog`, `Cat<-Dog<-Wolf<-Human->Dog`. {

Output:

} @@ -581,66 +528,10 @@ If subgraph is not specified, the algorithm is computed on the entire graph by d |- |- |- |- | | minHops | Int | 0 | The minimum number of hops in the traversal. Set to `0` if the start node should be included in the subgraph, or `1` otherwise. | | maxHops | Int | -1 | The maximum number of hops in the traversal. | - | relationshipFilter | List | [ ] | List of relationships which the subgraph formation will follow. Explained in detail below. | - | labelFilter | List | [ ] | List of labels which will define filtering. Explained in detail below. | + | relationshipFilter | List | [ ] | List of relationships which the subgraph formation will follow. Relationships can be filtered using the notation described in the [filtering rules](#filtering-rules) | + | labelFilter | List | [ ] | List of labels which will define filtering. Labels can be filtered using the notation described in the [filtering rules](#filtering-rules) | | filterStartNode | Bool | False | Whether the labelFilter applies to the start nodes. | -**Relationship filters** - -| Option | Explanation | -|--------------------|-------------------------------------------------------------------------------------------------------------| -| `TYPE` | Path will expand with either outgoing or incoming relationships of this type. | -| `` | Path will expand with outgoing relationships of this type. | -| `` | Path will expand if both incoming and outgoing relationship of this type exists between the same two nodes. | -| `>` | Path will expand with all outgoing relationships. | -| `<` | Path will expand will all incoming relationships. | - - -If the relationship filter is empty, all relationship types are allowed. - -**Examples:** - -- `Relationship list : []` : The path will expand on all outgoing relationships, and incoming relationship `LOVES`. -- `Relationship list : [LABEL` | Label is added to the end list. When end list has labels, only paths ending with these labels will be returned, but they can be expanded further, to return paths ending in nodes with end labels beyond it, but the expansion will only go through nodes with whitelisted labels. Labels in the end list do not have to respect the whitelist. | -| `-LABEL` | Label is added to the blacklist. No node in the path will contain labels in the blacklist. The blacklist takes precedence over all other filters. | -| `/LABEL` | Label is added to the termination list. When termination list contains labels, only paths ending with these labels will be returned, and any further expansion is stopped. Labels in the termination list do not have to respect the whitelist. | - -Any other label syntax is added to the whitelist. For example, `LABEL` will be added to the whitelist as `LABEL`, and `!LABEL` will be added to the whitelist as `!LABEL`. NOTE: when deciding where the label will be added, it is done by looking at the first element of the label. For example, `>LABEL>` will be added to the end list as `LABEL>`. - -**Examples:** - -Consider the graph provided in the usage section below. In this subsection, number of hops will be limited from 0 to 2, and the starting node will be `Dog`. - -- `Label list: ["/Mouse"]` - The filtering will return all the paths ending with - `Mouse`. Because no labels were added to the whitelist, all labels are - considered whitelisted. This filtering will return 3 paths: `Dog->Cat->Mouse`, - `Dog<-Human->Mouse`, `Dog->Mouse`. -- `Label list: ["/Mouse", "Cat"]` - Now, label `Cat` is added to the whitelist, - becoming the only whitelisted label. The meaning of the filter can now be - represented as: `"return all paths ending with Mouse, which expand through Cat and Cat only"`. - This filtering will return two paths, one where `Dog` connects - to the `Mouse` directly (`Dog->Mouse`), and one where `Cat` is - included (`Dog->Cat->Mouse`). -- `Label list: ["/Mouse", "-Cat", "-Human"]` - Now, both `Cat` and `Human` are - blacklisted, and there is only one eligible path that can reach `Mouse`: - `Dog->Mouse`. - -For the final example, the starting node is `Cat`, and the maximum number of -hops is increased to 4. - -- `Label list: [">Dog", "+Human", "+Wolf"]` - Now, only paths ending with `Dog` - will be returned, but they can be further expaned through the nodes with - whitelisted labels. This filtering returns 3 paths: `Cat<-Dog`, - `Cat<-Dog<-Human->Wolf->Dog`, `Cat<-Dog<-Wolf<-Human->Dog`. {

Output:

} @@ -648,8 +539,6 @@ hops is increased to 4. {

Usage:

} -{

Usage:

} - The database contains the following data: ![](/pages/advanced-algorithms/available-algorithms/path/graph.png)