define
relationalai.semantics
define(*args: Statement) -> FragmentAdd definitions (facts and logic) to the active model.
This is a convenience wrapper around Model.define that operates on the single active model.
Definitions can be unconditional (calling define directly) or conditional by chaining
Fragment.where on the returned fragment. You can also write
conditional definitions in the opposite order (filtering first with where
and then calling Fragment.define).
If you have more than one model, call Model.define on the specific model instead.
Parameters
Section titled “Parameters”-
(*argsStatement, default:()) - One or moresemantics.frontend.base.Statementitems to define. Common examples include:- Creating entities:
Person.new(name="Alice", age=10) - Setting properties/relationships:
Person.age == 10 - Defining derived values:
Person.age_days == (Person.age * 365)
- Creating entities:
Returns
Section titled “Returns”Fragment- A composable fragment representing the definition(s).
Raises
Section titled “Raises”relationalai.util.error.RAIException- If there is no active model, or if multiple models exist and the active model would be ambiguous.
Examples
Section titled “Examples”Define some base facts (data):
>>> from relationalai.semantics import Model, define>>> m = Model()>>> Person = m.Concept("Person")>>> define(... Person.new(name="Alice", age=10),... Person.new(name="Bob", age=30),... )Define a derived property:
>>> define(Person.age_days(Person.age * 365))Define Adult as a derived concept based on age:
>>> Adult = m.Concept("Adult", extends=[Person])>>> define(Adult(Person)).where(Person.age >= 18)Referenced By
Section titled “Referenced By”RelationalAI Documentation └── Release Notes └── Python API Release Notes └── What’s New in Version 1.0.0 └── Breaking Changes