rete

package
v0.0.0-...-5d14d19 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TestEqual

func TestEqual(args ...GValue) (bool, error)

func TestLess

func TestLess(args ...GValue) (bool, error)

Types

type AliasDeclaration

type AliasDeclaration struct {
	Alias  GVIdentity
	Type   TypeInfo
	Guards []Guard
}

type AlphaMem

type AlphaMem struct {
	// contains filtered or unexported fields
}

AlphaMem store those WMEs that passes constant test

func (*AlphaMem) Activate

func (m *AlphaMem) Activate(w *WME) int

func (*AlphaMem) AddSuccessor

func (m *AlphaMem) AddSuccessor(successors ...alphaMemSuccesor)

func (*AlphaMem) ForEachItem

func (m *AlphaMem) ForEachItem(fn func(*WME) (stop bool))

func (*AlphaMem) IsSuccessorsEmpty

func (m *AlphaMem) IsSuccessorsEmpty() bool

func (*AlphaMem) NItems

func (m *AlphaMem) NItems() int

func (*AlphaMem) RemoveSuccessor

func (m *AlphaMem) RemoveSuccessor(successor alphaMemSuccesor)

type AlphaNetwork

type AlphaNetwork struct {
	// contains filtered or unexported fields
}

func NewAlphaNetwork

func NewAlphaNetwork() *AlphaNetwork

func (*AlphaNetwork) AddFact

func (n *AlphaNetwork) AddFact(f Fact) int

func (*AlphaNetwork) AlphaRoot

func (n *AlphaNetwork) AlphaRoot() AlphaNode

func (*AlphaNetwork) DestoryAlphaMem

func (n *AlphaNetwork) DestoryAlphaMem(alphaMem *AlphaMem)

func (*AlphaNetwork) InitAlphaMem

func (n *AlphaNetwork) InitAlphaMem(am *AlphaMem)

initialize am with any current working memory

func (*AlphaNetwork) InitDummyAlphaMem

func (n *AlphaNetwork) InitDummyAlphaMem(am *AlphaMem, c Guard)

func (*AlphaNetwork) MakeAlphaMem

func (n *AlphaNetwork) MakeAlphaMem(aliasType TypeInfo, guards []Guard) *AlphaMem

func (*AlphaNetwork) RemoveFact

func (n *AlphaNetwork) RemoveFact(f Fact)

type AlphaNode

type AlphaNode interface {
	Hash() uint64
	PerformTest(*WME) (bool, error)
	Parent() AlphaNode
	SetParent(AlphaNode)
	IsParentOf(child AlphaNode) bool
	AddChild(child AlphaNode)
	GetChild(hash uint64) AlphaNode
	RemoveChild(child AlphaNode)
	NChildren() int
	SetOutputMem(mem *AlphaMem)
	OutputMem() *AlphaMem
	ForEachChild(fn func(AlphaNode) (stop bool))
}

Alpha test nodes

func NewConstantTestNode

func NewConstantTestNode(alphaNode *alphaNode, g Guard) AlphaNode

func NewTypeTestNode

func NewTypeTestNode(alphaNode *alphaNode, tf TypeInfo) AlphaNode

type BetaMem

type BetaMem struct {
	ReteNode
	// contains filtered or unexported fields
}

BetaMem holds all the tokens that match all the previous conditions, in another word, all the tokens pass all the join test and usually got activated by an join node

func NewBetaMem

func NewBetaMem(parent ReteNode) *BetaMem

type BetaNetwork

type BetaNetwork struct {
	// contains filtered or unexported fields
}

BetaNetwork manage the whole beta net and all the BetaNode

func NewBetaNetwork

func NewBetaNetwork(an *AlphaNetwork) *BetaNetwork

func (*BetaNetwork) AddFact

func (bn *BetaNetwork) AddFact(fact Fact)

AddFact add a fact, and propagete addition to the entire network

func (*BetaNetwork) AddProduction

func (bn *BetaNetwork) AddProduction(p Production) *PNode

AddProduction add an production and register its unique id

func (*BetaNetwork) GetProduction

func (bn *BetaNetwork) GetProduction(id string) *PNode

GetProduction query an production by its id

func (*BetaNetwork) RemoveFact

func (bn *BetaNetwork) RemoveFact(fact Fact)

RemoveFact remove a fact, and propagete removal to the entire network

func (*BetaNetwork) RemoveProduction

func (bn *BetaNetwork) RemoveProduction(id string) error

RemoveProduction remove a production by a production id, along with all the facts related with it. TODO: provide an option for reserving fact, we can just delete the pnode and its parent, grandparent and grand..grandparent if they are not shared, and leave the alpha mem so that it can still be shared and will not activate any successors if there is none

type BetaNode

type BetaNode interface {
	ReteNode
	// contains filtered or unexported methods
}

type ConstantTestNode

type ConstantTestNode struct {
	Field  string // which field in WME we gonna test
	V      GValue // the value to be compared
	TestOp TestOp // test operation
	// contains filtered or unexported fields
}

ConstantTestNode perform constant test for each WME, and implements by 'Dataflow Network'(see 2.2.1(page 27) in the paper)

func (ConstantTestNode) AddChild

func (n ConstantTestNode) AddChild(child AlphaNode)

func (*ConstantTestNode) Adjust

func (t *ConstantTestNode) Adjust(c Guard)

func (ConstantTestNode) ForEachChild

func (n ConstantTestNode) ForEachChild(fn func(AlphaNode) (stop bool))

func (ConstantTestNode) GetChild

func (n ConstantTestNode) GetChild(h uint64) AlphaNode

func (*ConstantTestNode) GetNegativeNode

func (t *ConstantTestNode) GetNegativeNode() *NegativeTestNode

func (*ConstantTestNode) Hash

func (n *ConstantTestNode) Hash() uint64

func (ConstantTestNode) IsParentOf

func (n ConstantTestNode) IsParentOf(child AlphaNode) bool

func (ConstantTestNode) NChildren

func (n ConstantTestNode) NChildren() int

func (ConstantTestNode) OutputMem

func (n ConstantTestNode) OutputMem() *AlphaMem

func (ConstantTestNode) Parent

func (n ConstantTestNode) Parent() AlphaNode

func (*ConstantTestNode) PerformTest

func (n *ConstantTestNode) PerformTest(w *WME) (bool, error)

func (*ConstantTestNode) RemoveChild

func (t *ConstantTestNode) RemoveChild(child AlphaNode)

func (*ConstantTestNode) SetNegativeNode

func (t *ConstantTestNode) SetNegativeNode(n *NegativeTestNode)

func (ConstantTestNode) SetOutputMem

func (n ConstantTestNode) SetOutputMem(mem *AlphaMem)

func (ConstantTestNode) SetParent

func (n ConstantTestNode) SetParent(p AlphaNode)

type Fact

type Fact struct {
	ID    GVIdentity
	Value GValue
}

func (Fact) GetValue

func (f Fact) GetValue(field string) (GValue, error)

func (Fact) HasField

func (f Fact) HasField(field string) bool

func (Fact) Hash

func (f Fact) Hash() uint64

func (Fact) WMEFromFact

func (f Fact) WMEFromFact() *WME

type Guard

type Guard struct {
	AliasAttr GVString
	Value     GValue // should never be GVIdentity
	Negative  bool
	TestOp    TestOp
}

Guard define constant test on value

func (Guard) Hash

func (c Guard) Hash() uint64

type JoinNode

type JoinNode struct {
	ReteNode
	// contains filtered or unexported fields
}

JoinNode perform join tests between wmes from an alpha memory and tokens from beta mem, that means JoinNode is usually the parent of a beta memory(beta memory store the results of JoinNode)

type JoinTest

type JoinTest struct {
	Alias    []Selector
	TestOp   TestOp
	Negative bool
}

JoinTest define join tests between two or more than two values

type NegativeTestNode

type NegativeTestNode struct {
	// contains filtered or unexported fields
}

func (NegativeTestNode) AddChild

func (n NegativeTestNode) AddChild(child AlphaNode)

func (*NegativeTestNode) Adjust

func (t *NegativeTestNode) Adjust(c Guard)

func (NegativeTestNode) ForEachChild

func (n NegativeTestNode) ForEachChild(fn func(AlphaNode) (stop bool))

func (NegativeTestNode) GetChild

func (n NegativeTestNode) GetChild(h uint64) AlphaNode

func (*NegativeTestNode) Hash

func (n *NegativeTestNode) Hash() uint64

func (NegativeTestNode) IsParentOf

func (n NegativeTestNode) IsParentOf(child AlphaNode) bool

func (NegativeTestNode) NChildren

func (n NegativeTestNode) NChildren() int

func (NegativeTestNode) OutputMem

func (n NegativeTestNode) OutputMem() *AlphaMem

func (NegativeTestNode) Parent

func (n NegativeTestNode) Parent() AlphaNode

func (*NegativeTestNode) PerformTest

func (n *NegativeTestNode) PerformTest(w *WME) (bool, error)

func (NegativeTestNode) RemoveChild

func (n NegativeTestNode) RemoveChild(child AlphaNode)

func (NegativeTestNode) SetOutputMem

func (n NegativeTestNode) SetOutputMem(mem *AlphaMem)

func (NegativeTestNode) SetParent

func (n NegativeTestNode) SetParent(p AlphaNode)

type PNode

type PNode struct {
	ReteNode

	AliasInfo []AliasDeclaration
	// contains filtered or unexported fields
}

PNode, aka production node, store all the tokens that match the lhs(conditions)

func NewPNode

func NewPNode(parent ReteNode, aliasDecls []AliasDeclaration) *PNode

func (*PNode) AnyMatches

func (pn *PNode) AnyMatches() bool

AnyMatches check if there is any match in a production node

func (*PNode) Matches

func (pn *PNode) Matches() ([]map[GVIdentity]any, error)

Matches figure out what the value of the aliases in each match

type Production

type Production struct {
	ID    string
	When  []AliasDeclaration
	Match []JoinTest
}

type ReteNode

type ReteNode interface {
	Parent() ReteNode
	AddChild(children ...ReteNode)
	AnyChild() bool
	ClearAndRestoreChildren(fn func())
	AttachParent(parent ReteNode)
	RemoveChild(child ReteNode) bool
	DetachParent()
	ForEachChild(fn func(child ReteNode) (stop bool))
	ForEachChildNonStop(fn func(child ReteNode))
}

func NewReteNode

func NewReteNode(parent ReteNode, self ReteNode) ReteNode

type Selector

type Selector struct {
	Alias     GVIdentity
	AliasAttr GVString
}

type TestAtJoinNode

type TestAtJoinNode struct {
	AliasOffsets []int
	AliasAttr    []string
	TestOp       TestOp
}

TestAtJoinNode defines join test between WMEs

func (TestAtJoinNode) Hash

func (t TestAtJoinNode) Hash() uint64

func (TestAtJoinNode) String

func (t TestAtJoinNode) String() string

type TestFunc

type TestFunc func(...GValue) (bool, error)

type TestOp

type TestOp int
const (
	TestOpEqual TestOp = iota
	TestOpLess

	NTestOp
)

TestOp

func (TestOp) String

func (t TestOp) String() string

func (TestOp) ToFunc

func (t TestOp) ToFunc() TestFunc

type Token

type Token struct {
	// contains filtered or unexported fields
}

Token stores WMEs that match guards or join test

func (*Token) Hash

func (t *Token) Hash() uint64

func (*Token) String

func (t *Token) String() string

type TypeTestNode

type TypeTestNode struct {
	TypeInfo TypeInfo `hash:"ignore"` // TypeInfo specified in a Cond
	// contains filtered or unexported fields
}

func (TypeTestNode) AddChild

func (n TypeTestNode) AddChild(child AlphaNode)

func (TypeTestNode) ForEachChild

func (n TypeTestNode) ForEachChild(fn func(AlphaNode) (stop bool))

func (TypeTestNode) GetChild

func (n TypeTestNode) GetChild(h uint64) AlphaNode

func (*TypeTestNode) Hash

func (t *TypeTestNode) Hash() uint64

func (TypeTestNode) IsParentOf

func (n TypeTestNode) IsParentOf(child AlphaNode) bool

func (TypeTestNode) NChildren

func (n TypeTestNode) NChildren() int

func (TypeTestNode) OutputMem

func (n TypeTestNode) OutputMem() *AlphaMem

func (TypeTestNode) Parent

func (n TypeTestNode) Parent() AlphaNode

func (*TypeTestNode) PerformTest

func (t *TypeTestNode) PerformTest(w *WME) (bool, error)

func (TypeTestNode) RemoveChild

func (n TypeTestNode) RemoveChild(child AlphaNode)

func (TypeTestNode) SetOutputMem

func (n TypeTestNode) SetOutputMem(mem *AlphaMem)

func (TypeTestNode) SetParent

func (n TypeTestNode) SetParent(p AlphaNode)

type WME

type WME struct {
	ID    GVIdentity
	Value GValue
	// contains filtered or unexported fields
}

WME is the working memory element, use to store the fact when matching

func NewWME

func NewWME(name GVIdentity, value GValue) *WME

func (*WME) FactOfWME

func (w *WME) FactOfWME() Fact

func (*WME) GetAttrValue

func (w *WME) GetAttrValue(attr string) (GValue, error)

func (*WME) GetAttrValueRaw

func (w *WME) GetAttrValueRaw(attr string) (any, error)

func (*WME) HasAttr

func (w *WME) HasAttr(attr string) bool

func (*WME) Hash

func (w *WME) Hash() uint64

Jump to

Keyboard shortcuts

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