relationalai.std.strings.String()
String(item: Producer) -> Expression
Filters values produced by a Producer
to only include strings.
Must be called in a rule or query context.
Parameters
Section titled “Parameters”Name | Type | Description |
---|---|---|
item | Producer | The Producer object to filter. |
Returns
Section titled “Returns”An Expression
object.
Example
Section titled “Example”Use String()
to filter string values:
import relationalai as raifrom 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") # id is a string.
# ========# EXAMPLES# ========
# Get people whose id is a string.with model.query() as select: person = Person() strings.String(person.id) response = select(person.id, person.name)
print(response.results)# id name# 0 1 Bob
# Get people whose id is not a string.with model.query() as select: person = Person() with model.not_found(): strings.String(person.id) response = select(person.id, person.name)
print(response.results)# id name# 0 2 Alice