semantics
Build and query RelationalAI semantic models.
The relationalai.semantics package provides a small, composable Python
DSL for:
- Creating a
Model - Declaring concepts (entity types) and relationships with
ConceptandRelationship - Adding definitions (base data and logic) with
define - Filtering and composing queries with
where - Selecting values with
selectand materializing results (for example withFragment.to_df)
Most functions in this module are convenience wrappers. They operate on the
single “active” model (the only Model that has been created).
For quick interactive use (e.g., notebooks) these convenience wrappers
(select, where, etc.) can keep code terse. For larger applications
and libraries, prefer calling methods on an explicit model instance
(e.g., Model.select, Model.where,
and Model.define). This avoids ambiguity if another module
(or test) creates a second Model.
In addition to the query helpers, this module re-exports commonly used DSL
types such as Concept, Relationship, and
Property from frontend.base, as well as core value types such as
Any, semantics.frontend.core.String, and semantics.frontend.core.Number from frontend.core.
Examples
Section titled “Examples”Create a semantic model:
>>> from relationalai.semantics import Model, define, select, where, String, Integer>>> m = Model()Declare a Person concept:
>>> Person = m.Concept("Person")Declare properties on Person:
>>> Person.name = m.Property(f"{Person} is named {String:name}")>>> Person.age = m.Property(f"{Person} is {Integer:age} years old")Define some Person entities:
>>> define(... Person.new(name="Alice", age=10),... Person.new(name="Bob", age=30),... )Select names of people over 18:
>>> where(Person.age > 18).select(Person.name).to_df()Attributes
Section titled “Attributes”Attributes exposed by this module.
relationalai.semantics.frontend.base. relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. Number(38, 0). Re-exported from relationalai.semantics.frontend.core`. semantics.frontend.core.Integer. Re-exported from relationalai.semantics.frontend.core. Number(19, 0). Re-exported from relationalai.semantics.frontend.core`. semantics.frontend.core.Integer. Re-exported from relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. semantics.frontend.core.DefaultNumber. Re-exported from relationalai.semantics.frontend.core. semantics.frontend.core.Boolean. Re-exported from relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. relationalai.semantics.frontend.core. Functions
Section titled “Functions”Functions exposed by this module.
select and aggregates. Classes
Section titled “Classes”Classes exposed by this module.
relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. relationalai.semantics.frontend.base. Modules and Subpackages
Section titled “Modules and Subpackages”Submodules and subpackages available under this namespace.