eta.schema.SchemaLibrary

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:

dict[str, DialSchema]

epi

A dict mapping episode schema predicates to episode schemas.

Type:

dict[str, EpiSchema]

obj

A dict mapping object schema predicates to object schemas.

Type:

dict[str, ObjSchema]

embedder
Type:

Embedder

Methods

add

Add a schema object to the library.

create

Create a schema object from the given predicate and contents (an S-expression) and add it to the library.

from_lisp_dirs

Recursively read schemas from all LISP files in a given directory or list of directories.

from_lisp_file

Read a set of schemas from a LISP file, storing them in the library.

get_schemas

Get all schemas of a particular type or list of types.

is_schema

Check whether a given predicate exists in the schema library.

retrieve

Retrieve some number of schemas of a particular type (or list of types).

retrieve_knowledge

Retrieve some number of facts from some number of retrieved schemas of a particular type (or list of types).

add(schema)[source]

Add a schema object to the library.

create(predicate, contents)[source]

Create a schema object from the given predicate and contents (an S-expression) and add it to the library.

get_schemas(type)[source]

Get all schemas of a particular type or list of types.

Parameters:

type (str or list[str]) – A schema type (dial, epi, or obj), or a list of types.

Return type:

list[Schema]

is_schema(predicate, type=None)[source]

Check whether a given predicate exists in the schema library.

Parameters:
  • predicate (str) – The predicate to check.

  • type (str, optional) – If a type is given, only check that type of schema.

Return type:

bool

retrieve(type, query=None, m=1)[source]

Retrieve some number of schemas of a particular type (or list of types).

Parameters:
  • type (str or list[str]) – A schema type (dial, epi, or obj), 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.

Returns:

The retrieved schemas.

Return type:

list[Schema]

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, or obj), 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]

from_lisp_file(fname)[source]

Read a set of schemas from a LISP file, storing them in the library.

Parameters:

fname (str) – The LISP file to read.

from_lisp_dirs(dirs)[source]

Recursively read schemas from all LISP files in a given directory or list of directories.

Parameters:

dirs (str or list[str]) – Either a directory name or a list of directory names to read.

__str__()[source]

Return str(self).