Skip to content

define

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

Add 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.

  • *args

    (Statement, default: ()) - One or more semantics.frontend.base.Statement items 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)
  • Fragment - A composable fragment representing the definition(s).
  • relationalai.util.error.RAIException - If there is no active model, or if multiple models exist and the active model would be ambiguous.

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)
RelationalAI Documentation
└──  Release Notes
    └──  Python API Release Notes
        └──  What’s New in Version 1.0.0
            └──  Breaking Changes