Skip to content

to_concept

relationalai.semantics.inspect
to_concept(obj: Variable, default: object = _MISSING) -> Concept | Any

Return the Concept that obj resolves to.

Works on any DSL VariableConcept, Chain, Expression, Ref, FieldRef, etc.

Parameters

  • obj

    (Variable) - Any DSL variable or expression.
  • default

    (object, default: _MISSING) - Value to return if the concept cannot be determined. If omitted, a TypeError is raised instead.

Returns

  • Concept - The resolved concept, or default if the concept cannot be determined and a default was provided.

Raises

  • TypeError - If the concept cannot be determined and no default was given.

Examples

from relationalai.semantics import Model, String, inspect
m = Model("example")
Person = m.Concept("Person")
Person.name = m.Property(f"{Person} has {String:name}")
inspect.to_concept(Person) is Person
# True
inspect.to_concept(Person.name, default=None) # returns Concept or None