Skip to content

where

relationalai.semantics
where(*args: Statement) -> Fragment

Return a fragment filtered by the given conditions.

This is a convenience wrapper around Model.where that operates on the single active model. It returns a composable Fragment that can be further refined with Fragment.define, Fragment.require, and Fragment.select. You can also add additional filters by chaining Fragment.where on an existing fragment.

If you have more than one model, call Model.where on the specific model instead.

  • *args

    (Statement, default: ()) - One or more semantics.frontend.base.Statement items to use as filter conditions. Common examples include:

    • Comparison operators: Person.age > 21
    • String operators: Person.name.startswith("A")
    • Logical operators: not_(Person.name.startswith("A"))
    • Property existence: Person.age (filters to entities with an age property)
  • Fragment - A composable fragment representing the filter(s).
  • relationalai.util.error.RAIException - If there is no active model, or if multiple models exist and the active model would be ambiguous.

Filter and select:

>>> from relationalai.semantics import Model, where, select
>>> m = Model()
>>> Person = m.Concept("Person")
>>> where(Person.age > 21).select(Person.name).to_df()

Filter a definition:

>>> Adult = m.Concept("Adult", extends=[Person])
>>> where(Person.age >= 18).define(Adult(Person))

Multiple conditions are combined with AND:

>>> where(Person.age > 21, Person.name.startswith("A")).select(Person.name).to_df()

Chained filters are also combined with AND:

>>> where(Person.age > 21).where(Person.name.startswith("A")).select(Person.name).to_df()
RelationalAI Documentation
└──  Release Notes
    └──  Python API Release Notes
        └──  What’s New in Version 1.0.0
            └──  Breaking Changes