eta.schema.Schema

class Schema(predicate='', participants=[], vars=[], bindings={}, header=[], contents=[])[source]

Bases: object

An abstract schema class.

id

A unique ID for this schema.

Type:

str

predicate

The main predicate of the schema (e.g., dog.n or eat.v).

Type:

str

participants

All participant roles of a schema, i.e., variables and constants present as arguments in the header.

Type:

list[s-expr]

vars

All variables scoped within a schema.

Type:

list[str]

bindings

A mapping from variables to bound values.

Type:

dict

header

The ELF formula for the header of the schema.

Type:

ELF

contents

The ELF formula for the contents of the schema.

Type:

ELF

sections

A dict mapping each section label (e.g., types) to a list of eventualities created from the schema contents.

Type:

dict[str, list[Eventuality]]

embedding

A vector embedding of this schema.

Type:

list[float]

Methods

bind

Bind the given variable symbol to the given value.

bind_args

Bind variables in the schema header with a list of respective argument values.

duplicate_variables

Duplicate all variables across a schema, mapping the original variables to the duplicated ones.

embed

Embed the schema based on the natural language representation of its contents, given an embedder object.

format

Format the contents of this schema as an S-expression string.

get_contents

Get the schema contents as an S-expression.

get_participants

Get the schema participants.

get_section

Get the eventualities within a given schema section or list of sections.

get_section_eps

Get all episode symbols within a schema section or list of sections.

get_section_wffs

Get all wffs within a schema section or list of sections.

instantiate

Instantiate a specific instance of a schema given a list of argument values for each variable in the header.

read_param_dict

Read an S-expression containing schema contents (for a given predicate) into a dict of schema parameters.

retrieve

Retrieve some number of facts from the schema according to similarity with a query string, given an embedder object.

subst_mappings

Given a list of variable replacement mappings, apply the mappings to each part of the schema.

to_probability_dict

Given a list of certainty or necessity eventualities, create a probability dict with entries of form {<ep>:<prob>}.

unbind

Unbind the given variable symbol.

read_param_dict(schema_contents)[source]

Read an S-expression containing schema contents (for a given predicate) into a dict of schema parameters.

to_probability_dict(eventualities, swap_duals=False)[source]

Given a list of certainty or necessity eventualities, create a probability dict with entries of form {<ep>:<prob>}.

If swap_duals is True, swap episode constants in the resulting probability dict with the dual var (e.g., ?e1 for !e1).

subst_mappings(mappings)[source]

Given a list of variable replacement mappings, apply the mappings to each part of the schema.

duplicate_variables()[source]

Duplicate all variables across a schema, mapping the original variables to the duplicated ones.

Note that this needs to be done in two steps to avoid mapping conflicts.

instantiate(args)[source]

Instantiate a specific instance of a schema given a list of argument values for each variable in the header.

This creates a deep copy of the schema, with duplicate variables to ensure that no collisions occur if the events in the schema are added to a plan.

Parameters:

args (list[s-expr]) – A list of expressions to bind to each respective header variable.

Return type:

Schema

bind(var, val)[source]

Bind the given variable symbol to the given value.

unbind(var)[source]

Unbind the given variable symbol.

bind_args(args)[source]

Bind variables in the schema header with a list of respective argument values.

Generally, we assume that args should correspond to the variables in the participants list of the schema, but we allow for the possibility of ^me and ^you as implicit arguments if fewer arguments than variables are given - in which case, they’re added to the arguments list in that order.

On the other hand, if more arguments than variables are given, we assume that ^me and ^you might be provided as redundant arguments, and remove those from the front of the list if present. Otherwise, we remove superfluous arguments starting from the end of the list.

Parameters:

args (list[s-expr]) – A list of expressions to bind to each respective header variable.

embed(embedder)[source]

Embed the schema based on the natural language representation of its contents, given an embedder object.

retrieve(embedder, query, n=5, header=True)[source]

Retrieve some number of facts from the schema according to similarity with a query string, given an embedder object.

Parameters:
  • embedder (Embedder) – An Embedder object.

  • query (str) – A query string to use to compute similarity.

  • n (int, default=5) – The number of facts to retrieve.

  • header (bool, default=True) – Whether to prefix the retrieved facts with the schema header.

Returns:

The retrieved schema facts as S-expressions.

Return type:

list[s-expr]

get_participants(no_bind=False)[source]

Get the schema participants.

Parameters:

no_bind (bool, default=False) – Do not make variable substitutions.

Return type:

list[s-expr]

get_contents(no_bind=False)[source]

Get the schema contents as an S-expression.

Parameters:

no_bind (bool, default=False) – Do not make variable substitutions.

Return type:

s-expr

get_section(sec)[source]

Get the eventualities within a given schema section or list of sections.

Parameters:

sec (str or list[str]) – A section label or list of section labels, or the keyword :all to return all sections.

Return type:

list[Eventuality]

get_section_eps(sec, no_bind=False)[source]

Get all episode symbols within a schema section or list of sections.

Parameters:
  • sec (str or list[str]) – A section label or list of section labels, or the keyword :all to return all sections.

  • no_bind (bool, default=False) – Do not make variable substitutions.

Return type:

list[str]

get_section_wffs(sec, no_bind=False)[source]

Get all wffs within a schema section or list of sections.

Parameters:
  • sec (str or list[str]) – A section label or list of section labels, or the keyword :all to return all sections.

  • no_bind (bool, default=False) – Do not make variable substitutions.

Return type:

list[s-expr]

format(no_bind=False)[source]

Format the contents of this schema as an S-expression string.

__str__()[source]

Return str(self).