Skip to content

Field

relationalai.semantics.frontend.base
Field(
name: str,
type_: Concept,
is_input: bool = False,
is_list: bool = False,
source: SourcePos | None = None,
)

Describe one named field in a relationship or property.

A Field pairs a field name with a Concept type and marks whether the field is an input and/or list-valued.

Fields are usually created implicitly by parsing a reading string. You typically construct Field objects only when creating a relationship or property with the explicit fields= keyword argument via Model.Relationship or Model.Property.

  • name

    (str) - Field name used for indexing and display.
  • type_

    (Concept) - Concept type of the field.
  • is_input

    (bool, default: False) - Whether this field is an input field. In most relationships/properties, all but the last field are inputs and the final field is the output.
  • is_list

    (bool, default: False) - Whether the field represents a list of values.
  • source

    (SourcePos | None, default: None) - Optional source position used for error reporting.

Most fields are created implicitly by parsing a reading string:

>>> from relationalai.semantics import Integer, Model, String
>>> m = Model()
>>> Person = m.Concept("Person", identify_by={"id": Integer})
>>> Person.name = m.Property(f"{Person} has {String:name}")
>>> # The Property constructor parses the reading string and produces an
>>> # input field of type Person and an output field named "name" of type String.

You can also declare fields explicitly via fields=. For example, the following is equivalent to the previous example:

>>> from relationalai.semantics.frontend.base import Field
>>> Person.name = m.Property(
... fields=[Field("person", Person), Field("name", String)],
... short_name="name"
... )
Field.name: str

Field name.

Field.type: Concept

Field concept type.

Field.is_input: bool

True for input fields.

Field.is_list: bool

True for list-valued fields.

 semantics > frontend > base
├──  FieldRef
├──  Model
│   ├──  Property
│   └──  Relationship
├──  Property
├──  Reading
├──  Relationship
└──  Value
RelationalAI Documentation
└──  Build With RelationalAI
    └──  Understand how PyRel works > Build a semantic model
        └──  Declare relationships and properties
            ├──  Declare a property with Model.Property
            └──  Declare a relationship with Model.Relationship