lowercase()#
relationalai.std.strings
#lowercase(string: str|Producer) -> Expression
Converts a string to lowercase.
If string
is a Producer
, then lowercase()
acts as a filter and removes non-string values from the producer.
Must be called in a rule or query context.
Parameters#
Name | Type | Description |
---|---|---|
string | Producer or Python str object | The string to convert to lowercase. |
Returns#
An Expression
object.
Example#
Use lowercase()
to convert a string to lowercase:
#import relationalai as rai
from relationalai.std import strings
# =====
# SETUP
# =====
model = rai.Model("MyModel")
Person = model.Type("Person")
with model.rule():
Person.add(id=1).set(name="Alice")
Person.add(id=2).set(name="Bob")
Person.add(id=3).set(name=-1) # Non-string name
# =======
# EXAMPLE
# =======
# Set a lowercase_name property equal to the name property converted to lowercase.
with model.rule():
person = Person()
person.set(lowercase_name=strings.lowercase(person.name))
# Since lowercase() filters out non-string values, the lowercase_name property
# is not set for the person with id=3.
with model.query() as select:
person = Person()
response = select(person.id, person.lowercase_name)
print(response.results)
# id lowercase_name
# 0 1 alice
# 1 2 bob
# 2 3 NaN