actr

package
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package actr implements our internal, parsed version of the amod file which is passed to a Framework to generate their code.

Index

Constants

This section is empty.

Variables

View Source
var ACTRLoggingLevels = []string{
	"min",
	"info",
	"detail",
}

Functions

func IsInternalChunkType added in v0.10.0

func IsInternalChunkType(name string) bool

func IsReservedType added in v0.10.0

func IsReservedType(name string) bool

IsReservedType checks if the slot name is reserved. See "Default Chunks" pg. 80 of ACT-R manual.

func ValidLogLevel

func ValidLogLevel(e string) bool

Types

type ACTRLogLevel

type ACTRLogLevel string

type BufferPatternMatch added in v0.12.0

type BufferPatternMatch struct {
	Buffer buffer.Interface

	Pattern *Pattern
}

type BufferStateMatch added in v0.12.0

type BufferStateMatch struct {
	Buffer buffer.Interface

	State string
}

type Chunk

type Chunk struct {
	TypeName  string
	SlotNames []string
	NumSlots  int

	AMODLineNumber int // line number in the amod file of the this chunk declaration
}

func (Chunk) HasSlot

func (chunk Chunk) HasSlot(slot string) bool

HasSlot checks if the slot name exists on this chunk.

func (Chunk) IsInternal

func (c Chunk) IsInternal() bool

func (Chunk) SlotIndex added in v0.7.0

func (chunk Chunk) SlotIndex(slot string) int

SlotIndex returns the slot index (indexed from 1) of the slot name or -1 if not found.

func (Chunk) SlotName added in v0.2.0

func (c Chunk) SlotName(index int) (str string)

SlotName returns the name of the slot given the index.

type ClearStatement

type ClearStatement struct {
	BufferNames []string
}

ClearStatement clears a list of buffers.

type Comparison added in v0.8.0

type Comparison int
const (
	Equal Comparison = iota
	NotEqual
)

func (Comparison) String added in v0.8.0

func (c Comparison) String() string

type Constraint added in v0.8.0

type Constraint struct {
	LHS        *string
	Comparison Comparison
	RHS        *Value
}

func (Constraint) String added in v0.8.0

func (c Constraint) String() string

type Initializer

type Initializer struct {
	Module modules.Interface
	Buffer buffer.Interface

	ChunkName *string // optional chunk name
	Pattern   *Pattern

	AMODLineNumber int
}

type Match

type Match struct {
	BufferPattern *BufferPatternMatch

	// If the buffer and the module's buffer are the same, we will have one of each of these.
	BufferState *BufferStateMatch
	ModuleState *ModuleStateMatch
}

type Model

type Model struct {
	Name        string
	Description string
	Authors     []string
	Examples    []*Pattern

	Modules    []modules.Interface
	Memory     *modules.DeclarativeMemory // memory is always present
	Goal       *modules.Goal              // goal is always present
	Procedural *modules.Procedural        // procedural is always present
	Chunks     []*Chunk

	// ExplicitChunks are ones which are named in the initializer like this:
	// 	castle [meaning: 'castle']
	// We keep track of these to remove them from the implicit list & to check for duplicates.
	ExplicitChunks []string

	// ImplicitChunks are chunks which aren't declared, but need to be created by some frameworks.
	// e.g. by default vanilla will create them and emit a warning:
	// 	#|Warning: Creating chunk SHARK with no slots |#
	// These chunk names come from the initializations & similarities.
	// We keep track of them so we can create them explicitly to avoid the warnings.
	ImplicitChunks []string

	Initializers []*Initializer
	Similarities []*Similarity

	Productions []*Production

	Options
	// contains filtered or unexported fields
}

Model represents a basic ACT-R model. This is used as input to a Framework where it can be run or output to a file. (This is incomplete w.r.t. all of ACT-R's capabilities.)

func (*Model) AddImplicitChunk added in v0.10.0

func (model *Model) AddImplicitChunk(chunkName string)

func (*Model) AddImplicitChunksFromPattern added in v0.10.0

func (model *Model) AddImplicitChunksFromPattern(pattern *Pattern)

AddImplicitChunksFromPattern walks a pattern and adds any IDs to our list of implicit chunks.

func (*Model) AddInitializer added in v0.10.0

func (model *Model) AddInitializer(initializer *Initializer)

AddInitializer adds the initializer to our list and adds any IDs to ImplicitChunks so we can (possibly) create them in the framework output.

func (*Model) AddSimilarity added in v0.10.0

func (model *Model) AddSimilarity(similar *Similarity)

AddSimilarity will add a similarity to the list and keep track of the chunk names.

func (Model) BufferNames added in v0.6.0

func (model Model) BufferNames() (list []string)

BufferNames returns a slice of valid buffer names.

func (Model) Buffers

func (model Model) Buffers() (list buffer.List)

Buffers returns a slice of all valid buffers.

func (*Model) CreateExtraBuffers added in v0.9.0

func (model *Model) CreateExtraBuffers() *modules.ExtraBuffers

CreateExtraBuffers creates the "extra_buffers" module and adds it to the list.

func (*Model) CreateImaginal

func (model *Model) CreateImaginal() *modules.Imaginal

CreateImaginal creates the imaginal module and adds it to the list.

func (*Model) FinalizeImplicitChunks added in v0.10.0

func (model *Model) FinalizeImplicitChunks()

FinalizeImplicitChunks will remove already-declared chunks from the implicit list and make the list unique.

func (Model) HasAnyBufferMatch added in v0.13.0

func (model Model) HasAnyBufferMatch() bool

HasAnyBufferMatch checks if this model uses an "any" match. In this case a framework may need to declare a new chunk type for "any_chunk".

func (Model) HasImplicitChunks added in v0.10.0

func (model Model) HasImplicitChunks() bool

func (Model) HasPrintStatement

func (model Model) HasPrintStatement() bool

HasPrintStatement checks if this model uses the print statement. This is used to include extra code to handle printing in some frameworks.

func (Model) ImaginalModule added in v0.7.0

func (model Model) ImaginalModule() *modules.Imaginal

ImaginalModule gets the imaginal module (or returns nil if it does not exist).

func (*Model) Initialize

func (model *Model) Initialize()

func (Model) LookupBuffer

func (model Model) LookupBuffer(bufferName string) buffer.Interface

LookupBuffer looks up the named buffer in the model and returns it (or nil if it does not exist).

func (Model) LookupChunk

func (model Model) LookupChunk(typeName string) *Chunk

LookupChunk looks up the chunk (by type name) in the model and returns it (or nil if it does not exist).

func (Model) LookupInitializer added in v0.6.0

func (model Model) LookupInitializer(buffer string) *Initializer

LookupInitializer returns an initializer or nil if the buffer does not have one.

func (Model) LookupModule added in v0.2.0

func (model Model) LookupModule(moduleName string) modules.Interface

LookupModule looks up the named module in the model and returns it (or nil if it does not exist).

func (*Model) SetParam added in v0.7.0

func (model *Model) SetParam(kv *keyvalue.KeyValue) (err error)

func (*Model) SetRunOptions added in v0.12.0

func (m *Model) SetRunOptions(options *Options)

type ModuleStateMatch added in v0.12.0

type ModuleStateMatch struct {
	Module modules.Interface

	// The generated code for the frameworks actually uses a buffer name, not the module name.
	// So store (one) here for convenience. If the module has multiple buffers it should not
	// matter which one we pick as the requests should be on its module.
	Buffer buffer.Interface

	State string
}

type Options added in v0.12.0

type Options struct {
	// "log_level": one of 'min', 'info', or 'detail'
	LogLevel ACTRLogLevel

	// "trace_activations": output detailed info about activations
	TraceActivations bool

	// "random_seed": the seed to use for generating pseudo-random numbers (allows for reproducible runs)
	// For all frameworks, if it is not set it uses current system time.
	// Use a uint32 because pyactr uses numpy and that's what its random number seed uses.
	RandomSeed *uint32
}

type Pattern

type Pattern struct {
	AnyChunk bool

	Chunk *Chunk
	Slots []*PatternSlot
}

func (*Pattern) AddSlot

func (p *Pattern) AddSlot(slot *PatternSlot)

func (Pattern) LookupVariable

func (p Pattern) LookupVariable(varName string) *PatternVar

func (Pattern) String

func (p Pattern) String() (str string)

type PatternSlot

type PatternSlot struct {
	// The item is one of the following:
	Nil      bool
	Wildcard bool

	ID  *string
	Str *string
	Var *PatternVar
	Num *string // we don't need to treat this as a number anywhere, so keep as a string

	Negated bool // this item is negated
}

func (PatternSlot) String

func (p PatternSlot) String() (str string)

type PatternVar added in v0.8.0

type PatternVar struct {
	Name        *string
	Constraints []*Constraint // any constraints on this var
}

type PrintStatement

type PrintStatement struct {
	Values *[]*Value
}

PrintStatement outputs the string, id, or number to stdout.

func (PrintStatement) IsBufferOutput added in v0.12.0

func (p PrintStatement) IsBufferOutput() bool

IsBufferOutput returns whether or not we have an argument list consisting of one ID.

type Production

type Production struct {
	Model *Model // link back to its model so we can add implicit chunks

	Name        string
	Description *string // optional description to output as a comment in the generated code

	VarIndexMap map[string]VarIndex // track the buffer and slot name each variable refers to

	Matches      []*Match
	DoStatements []*Statement

	AMODLineNumber int // line number in the amod file of the this production
}

Production stores information on how to match buffers and perform some operations. It uses a small language to modify states upon successful matches.

func (*Production) AddDoStatement added in v0.10.0

func (p *Production) AddDoStatement(statement *Statement)

AddDoStatement adds the statement to our list and adds any IDs to ImplicitChunks so we can (possibly) create them in the framework output.

func (*Production) AddSlotToSetStatement added in v0.10.0

func (p *Production) AddSlotToSetStatement(statement *SetStatement, slot *SetSlot)

AddSlotToSetStatement is used to add slot info to an already-existing set statement. See LookupSetStatementByBuffer() above.

func (Production) LookupMatchByBuffer

func (p Production) LookupMatchByBuffer(bufferName string) *BufferPatternMatch

func (Production) LookupMatchByVariable

func (p Production) LookupMatchByVariable(varName string) *BufferPatternMatch

LookupMatchByVariable checks all matches for a variable by name. This is pretty inefficient, but given the small number of matches in a production, it's probably not worth doing anything more complicated. We could store all the vars used in all the matches on the Match itself and look it up there.

func (Production) LookupSetStatementByBuffer

func (p Production) LookupSetStatementByBuffer(bufferName string) *SetStatement

LookupSetStatementByBuffer is used when combining several set consecutive statements on one buffer. So this:

set goal.foo to 1
set goal.bar to 10

is treated like this:

set foo, bar on goal to 1, 10

type RecallStatement

type RecallStatement struct {
	Pattern           *Pattern
	MemoryModuleName  string
	RequestParameters map[string]string
}

RecallStatement is used to pull information from memory.

type SetSlot

type SetSlot struct {
	Name      string
	SlotIndex int // (this slot index in the chunk)
	Value     *Value
}

type SetStatement

type SetStatement struct {
	Buffer buffer.Interface // buffer we are manipulating

	Slots *[]SetSlot // (1) set this slot
	Chunk *Chunk     // (1) if we are setting slots, point at the chunk they reference for easy lookup

	Pattern *Pattern // (2) pattern if we are setting the whole buffer
}

SetStatement will set a slot or the entire contents of the named buffer to a string or a pattern. There are two forms:

(1) set (Buffer).(SetSlot) to (SetSlot.Value)
(2) set (Buffer) to (Pattern)

type Similarity added in v0.10.0

type Similarity struct {
	ChunkOne string
	ChunkTwo string
	Value    float64

	AMODLineNumber int
}

type Statement

type Statement struct {
	Clear  *ClearStatement
	Print  *PrintStatement
	Recall *RecallStatement
	Set    *SetStatement
	Stop   *StopStatement
}

type StopStatement added in v0.8.0

type StopStatement struct {
}

StopStatement outputs a stop command. There are no parameters.

type Value

type Value struct {
	Nil    *bool // set this to nil
	Var    *string
	ID     *string
	Str    *string
	Number *string
}

Value holds something that may be printed.

func (Value) String added in v0.8.0

func (v Value) String() string

type VarIndex added in v0.2.0

type VarIndex struct {
	Var      *PatternVar
	Buffer   buffer.Interface
	SlotName string
}

VarIndex is used to track which buffer slot a variable refers to

Directories

Path Synopsis
Package buffer implements ACT-R buffers.
Package buffer implements ACT-R buffers.
Package modules implements a module interface and several built-in ACT-R modules.
Package modules implements a module interface and several built-in ACT-R modules.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL