strings#

relationalai.std

RAI string values are represented by Expression objects. The relationalai.std.strings module contains analogs of Python string methods for working with RAI strings.

NOTE

The actual values of properties and other data in a RAI model are only determined during query evaluation in the RAI Native App. As a result, the Python interpreter can’t access the types or values of data in the model, which means string data can’t be represented as Python str objects.

To import the strings module, add the following to the top of your Python file or notebook:

#import relationalai.std.strings as strings

Table Of Contents#

Basic Operations#

These functions perform essential string manipulations, like concatenation, trimming, and substring extraction.

FunctionDescription
concat()Concatenates two or more strings.
length()Gets the length of a string.
strip()Removes leading and trailing whitespace from a string.
substring()Extracts a substring from a string.
replace()Replaces all occurrences of a substring with another substring.

Case Conversion#

Use these functions to convert strings between uppercase and lowercase formats.

FunctionDescription
lowercase()Converts a string to lowercase.
uppercase()Converts a string to uppercase.

String Filters#

Filter strings based on specific criteria, such as containing a substring or matching a pattern.

FunctionDescription
String()Filters string values from a Producer.
contains()Filters strings that contain a substring.
like()Filters strings that match a SQL LIKE pattern.
starts_with()Filters strings that start with a substring.
ends_with()Filters strings that end with a substring.

Splitting and Joining Strings#

These functions allow you to split strings into parts or join multiple strings into a single one.

FunctionDescription
split()Splits strings into substrings.
split_part()Splits strings and returns the substring at a specified index.
join()Joins strings with a separator.

Fuzzy Matching#

Use this function to measure string similarity for approximate matching tasks.

FunctionDescription
levenshtein()Calculates the Levenshtein distance between two strings.

Regular Expressions#

IMPORTANT

The functions in this section are deprecated and will be removed in a future release. Use the functions in the relationalai.std.re module instead.

FunctionDescriptionNotes
regex_compile()Compiles a regular expression pattern. Deprecated
regex_match()Matches a string to a regular expression pattern. Deprecated