Skip to content

Not

relationalai.semantics.frontend.base
Not(*items: Statement, model: Model)

Represents a negated condition for use in query filters.

Not is the object created by Model.not_ (and the convenience function not_). Use it inside Model.where to exclude bindings that match a pattern; multiple items are treated as a single grouped condition (NOT (a AND b)).

  • *items

    (Statement, default: ()) - One or more statements to negate.
  • model

    (Model) - The model this negation belongs to.

Most users should not instantiate this class directly. Prefer Model.not_.

Not.__or__(other) -> Match

Return a match expression (self | other).

a | b builds a Match with two branches. At execution time, the match picks the first branch (left-to-right) that can succeed for the current bindings.

Parameters:

Returns:

  • Match - A composable match expression.
Not.__and__(other) -> Fragment

Return a fragment that combines conditions with AND (self & other).

Use & to explicitly conjoin conditions when building filters. This is equivalent to passing multiple conditions to Model.where.

If other is a Fragment, this returns a new fragment with self added to other’s filters (roughly other.where(self)).

Parameters:

  • other

    (Statement or Fragment) - The right-hand operand. This is typically a condition expression, but it may also be an existing fragment to extend.

Returns:

  • Fragment - A composable fragment representing the conjunction.

Raises:

  • relationalai.util.error.RAIException - If other is not a valid statement in a filter.
  • NotImplementedError - If a Python value cannot be converted to a supported literal.

Examples:

Extend an existing fragment by adding another condition, then continue chaining:

>>> from relationalai.semantics import Model
>>> m = Model()
>>> User = m.Concept("User")
>>> m.define(
... User.new(username="alice", age=30, status="active"),
... User.new(username="bob", age=15, status="inactive"),
... User.new(username="carol", age=40, status="active"),
... )
>>> active_users = m.where(User.status == "active")
>>> active_adults = active_users & m.not_(User.age < 18)
>>> active_adults.select(User.username).to_df()

Notes:

Do not use Python’s boolean and with DSL values. Use & (or pass multiple conditions to where) instead.

NotDSLBase
 semantics
├──  frontend > base
│   └──  Model
│       └──  not_
└──  not_