eta.schema
Classes and methods for representing and modifying different types of schemas.
A schema is, in general, a collection of sections. Each section is a sequence of eventualities (natural language
expressions or ULF/ELF formulas with associated episode symbols) under a section label, e.g., types
or preconditions
.
A schema is denoted by a specific predicate string (e.g., dog.n
or eat.v
), and also has a unique header, which is a
formula characterizing the schema episode potentially containing participant variables, e.g., ((^me eat.v ?x) ** ?e1)
.
Classes
A schema representing a prototypical episode. |
|
A schema representing a prototypical episode. |
|
A schema representing a prototypical object. |
|
An abstract schema class. |
|
A library of all generic episode, dialogue, and object schemas. |
- class Schema(predicate='', participants=[], vars=[], bindings={}, header=[], contents=[])[source]
Bases:
object
An abstract schema class.
- participants
All participant roles of a schema, i.e., variables and constants present as arguments in the header.
- Type:
list[s-expr]
- 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]]
- 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.
- 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:
- Returns:
The retrieved schema facts as S-expressions.
- 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.
- get_section_eps(sec, no_bind=False)[source]
Get all episode symbols within a schema section or list of sections.
- class EpiSchema(predicate='', participants=[], vars=[], bindings={}, header=[], contents=[], types=[], rigid_conds=[], static_conds=[], preconds=[], postconds=[], goals=[], episodes=[], episode_relations=[], necessities=[], certainties=[])[source]
Bases:
Schema
A schema representing a prototypical episode.
Sections
types : the nominal types of each participant/variable.
rigid-conds : non-fluent conditions relevant to episode.
static-conds : fluent conditions that are not expected to change during episode.
preconds : fluent conditions that are expected to hold at the beginning of episode.
postconds : fluent conditions that are expected to hold at end of episode.
goals : goals of participants in schema (e.g.,
(^me want.v (that ...))
).episodes : the expected/intended sub-episodes of the schema episode.
episode-relations : the temporal/causal relations between episodes of schema.
necessities : probabilities associated with schema formulas.
certainties : probabilities associated with schema episodes.
- class DialSchema(predicate='', participants=[], vars=[], bindings={}, header=[], contents=[], types=[], rigid_conds=[], static_conds=[], preconds=[], postconds=[], goals=[], episodes=[], episode_relations=[], obligations=[], necessities=[], certainties=[])[source]
Bases:
EpiSchema
A schema representing a prototypical episode.
Sections
types : the nominal types of each participant/variable.
rigid-conds : non-fluent conditions relevant to episode.
static-conds : fluent conditions that are not expected to change during episode.
preconds : fluent conditions that are expected to hold at the beginning of episode.
postconds : fluent conditions that are expected to hold at end of episode.
goals : goals of participants in schema (e.g., (^me want.v (that …))).
episodes : the expected/intended sub-episodes of the schema episode.
episode-relations : the temporal/causal relations between episodes of schema.
obligations : the dialogue obligations associated with episodes within the schema.
necessities : probabilities associated with schema formulas.
certainties : probabilities associated with schema episodes.
- read_param_dict(schema_contents)[source]
Read an S-expression containing schema contents (for a given predicate) into a dict of schema parameters.
- class ObjSchema(predicate='', participants=[], vars=[], bindings={}, header=[], contents=[], types=[], rigid_conds=[], skeletal_prototype='', purposes=[], necessities=[])[source]
Bases:
Schema
A schema representing a prototypical object.
Sections
types : the nominal types of each participant/variable.
rigid-conds : non-fluent conditions relevant to object.
skeletal-prototype : 3D mesh decomposition of object (.obj filenames).
purposes : telic purpose associated with object.
necessities : probabilities associated with schema formulas.
- class SchemaLibrary(embedder=None)[source]
Bases:
object
A library of all generic episode, dialogue, and object schemas.
- Parameters:
embedder (Embedder, optional) – If provided, an embedder to embed all schemas that are added.
- dial
A dict mapping dialogue schema predicates to dialogue schemas.
- Type:
- create(predicate, contents)[source]
Create a schema object from the given predicate and contents (an S-expression) and add it to the library.
- is_schema(predicate, type=None)[source]
Check whether a given predicate exists in the schema library.
- retrieve(type, query=None, m=1)[source]
Retrieve some number of schemas of a particular type (or list of types).
- Parameters:
- Returns:
The retrieved schemas.
- Return type:
- retrieve_knowledge(type, query=None, m=1, n=5, header=True)[source]
Retrieve some number of facts from some number of retrieved schemas of a particular type (or list of types).
- Parameters:
type (str or list[str]) – A schema type (
dial
,epi
, orobj
), or a list of types.query (str, optional) – A query string to use to compute similarity. If not given, or if no embedder is defined, an arbitrary schema is retrieved.
m (int, default=1) – The number of schemas to retrieve.
n (int, default=5) – The number of facts to retrieve from each retrieved schema.
header (bool, default=True) – Whether to prefix the retrieved facts with the schema header.
- Returns:
The facts retrieved from each retrieved schema, as S-expressions.
- Return type:
list[s-expr]