cognition.knowledge.representation

Knowledge representation

Attributes

Fact

Graphical representation of concepts and relationships

Classes

Freezable

Produces an immutable version

Thawable

Produces a mutable version

BaseSchema

Freezable base model with a fixed set of required (immutable) fields.

Entity

Distinct object, concept, or event

BinaryRelation

A relationship between two entities

Module Contents

class cognition.knowledge.representation.Freezable

Bases: Protocol

Produces an immutable version

freeze()
Returns:

immutable version

Return type:

Self

class cognition.knowledge.representation.Thawable[T]

Bases: Protocol

Produces a mutable version

thaw()
Returns:

mutable version

Return type:

T

class cognition.knowledge.representation.BaseSchema

Bases: cognition.util.misc.TypedMixin, pydantic.BaseModel, abc.ABC

Freezable base model with a fixed set of required (immutable) fields.

As necessary, provides support to freeze custom fields via (a) automatic detection of list->tuple, set->frozenset; or (b) recursive freezing via Freezable; or (c) subtype implementations of freeze_fieldname method.

Frozen instance is a subtype that is then thawable to produce a copy of the original instance.

classmethod fixed_field_names()
Abstractmethod:

Returns:

frozen required field names

Return type:

tuple[str, Ellipsis]

property custom_fields: collections.abc.Iterable[tuple[str, Any]]

Non-fixed fields

Returns:

name/value pairs for non-required fields, if any

Return type:

collections.abc.Iterable[tuple[str, Any]]

__str__()

KR representation

Returns:

e.type(fixed1=’e.fixed1’[, …][, custom1=e.custom1, …])

Return type:

str

replace(**fields)

Produces a copy with optional field changes

Parameters:

fields (Any) – name=new value

Returns:

copy

Raises:
  • KeyError – invalid (non-required) field

  • ValidationError – violates schema

Return type:

Self

classmethod __pydantic_init_subclass__(**kwargs)
Parameters:

kwargs (Any)

Return type:

None

CUSTOM_FREEZE_METHOD: ClassVar[string.Template]

field name (via field parameter)-> custom freeze method name

freeze()

See Freezable

Return type:

Self

class cognition.knowledge.representation.Entity

Bases: BaseSchema

Distinct object, concept, or event that is named

name: str
classmethod fixed_field_names()
Returns:

frozen required field names

Return type:

tuple[str, Ellipsis]

class cognition.knowledge.representation.BinaryRelation

Bases: BaseSchema

A relationship between two entities

entity1: Entity
entity2: Entity
classmethod fixed_field_names()
Returns:

frozen required field names

Return type:

tuple[str, Ellipsis]

type cognition.knowledge.representation.Fact = Entity | BinaryRelation

Graphical representation of concepts and relationships