text

This algorithm is not available in MAGE 1.14 and newer versions.

The text module offers a toolkit for manipulating strings.

TraitValue
Module typeutil
ImplementationC++
Parallelismsequential

Procedures

join()

Joins all the strings into a single one with the given delimiter between them.

Input:

  • strings: List[string] ➡ A list of strings to be joined.
  • delimiter: string ➡ A string to be inserted between the given strings.

Output:

  • string: string ➡ The joined string.

Usage:

To join strings, use the following query:

CALL text.join(["idora", " ", "ivan", "", "matija"], ",") 
YIELD string 
RETURN string;

Result:

+----------------------------+
| string                     |
+----------------------------+
| "idora, ,ivan,,matija"     |
+----------------------------+

regexGroups()

The procedure returns all matched subexpressions of the regex on the provided text using the C++ regex (opens in a new tab) library.

Input:

  • input: string ➡ Text that will be searched for regex subexpressions.
  • regex: string ➡ Regex subexpression searched for in the text.

Output:

  • results: List[List[string]] ➡ All matched subexpressions. The inner list contains the whole subexpression and tokens matched inside.

Usage:

Use the following query to search for expressions:

CALL text.regexGroups("Memgraph: 1\nSQL: 2", "(\\w+): (\\d+)")
YIELD results
RETURN results;

Result:

+------------------------------------------------------------+
| results                                                    |
+------------------------------------------------------------+
| [["Memgraph: 1", "Memgraph", "1"], ["SQL: 2", "SQL", "2"]] |
+------------------------------------------------------------+

format()

The procedure formats strings using the C++ fmt library (opens in a new tab).

Input:

  • text: string ➡ Text that needs to be formatted.
  • parameters: string ➡ Parameters which will be applied to the text.

Output:

  • result: string ➡ Formatted string.

Usage:

Use the following query to insert the parameters to the placeholders in the sentence:

CALL text.format("Memgraph is the number {} {} in the world.", [1, "graph database"])
YIELD result
RETURN result;

Result:

+---------------------------------------------------------+
| result                                                  |
+---------------------------------------------------------+
| "Memgraph is the number 1 graph database in the world. "|
+---------------------------------------------------------+