diff --git a/pages/advanced-algorithms/available-algorithms/text.mdx b/pages/advanced-algorithms/available-algorithms/text.mdx index fa0cbe23a..cdacb0e7b 100644 --- a/pages/advanced-algorithms/available-algorithms/text.mdx +++ b/pages/advanced-algorithms/available-algorithms/text.mdx @@ -120,7 +120,7 @@ If subgraph is not specified, the algorithm is computed on the entire graph by d {

Usage:

} -Use the following query to insert the parameters to the placeholders in the sentence: +Use the following queries to insert the parameters to the placeholders in the sentence: ```cypher CALL text.format("Memgraph is the number {} {} in the world.", [1, "graph database"]) @@ -137,3 +137,106 @@ Result: | "Memgraph is the number 1 graph database in the world. "| +---------------------------------------------------------+ ``` + +### `replace()` + +Replace each substring of the given string that matches the given regular expression with the given replacement. + +{

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. +- `text: string` ➡ Text that needs to be replaced. +- `regex: string` ➡ Regular expression by which to replace the string. +- `replacement: string` ➡ Target string to replace the matched string. + +{

Usage:

} + +Use the following queries to do text replacement: + +```cypher +RETURN text.replace('Hello World!', '[^a-zA-Z]', '') AS result; +``` + +Result: + +```plaintext ++--------------+ +| result | ++--------------+ +| "HelloWorld" | ++--------------+ +``` + +```cypher +RETURN text.replace('MAGE is a Memgraph Product', 'MAGE', 'GQLAlchemy') AS result; +``` + +Result: + +```plaintext ++------------------------------------+ +| result | ++---------- -------------------------+ +| "GQLAlchemy is a Memgraph Product" | ++------------------------------------+ +``` + +### `regReplace()` + +Replace each substring of the given string that matches the given regular expression with the given replacement. + +{

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. +- `text: string` ➡ Text that needs to be replaced. +- `regex: string` ➡ Regular expression by which to replace the string. +- `replacement: string` ➡ Target string to replace the matched string. + +{

Usage:

} + +Use the following query to do text replacement: + +```cypher +RETURN text.regreplace("Memgraph MAGE Memgraph MAGE", "MAGE", "GQLAlchemy") AS output; +``` + +Result: + +```plaintext ++---------------------------------------+ +| result | ++---------------------------------------+ +| "GQLAlchemy MAGE Memgraph GQLAlchemy" | ++---------------------------------------+ +``` + +### `distance()` + +Compare the given strings with the Levenshtein distance algorithm. + +{

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. +- `text1: string` ➡ Source string. +- `text2: string` ➡ Destination string for comparison. + +{

Usage:

} + +Use the following query to calculate distance between texts: + +```cypher +RETURN text.distance("Levenshtein", "Levenstein") AS result; +``` + +Result: + +```plaintext ++--------+ +| result | ++--------+ +| 1 | ++--------+ +```