ast

package
v1.6.1 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2020 License: Apache-2.0, Apache-2.0 Imports: 12 Imported by: 43

Documentation

Index

Constants

View Source
const (
	// ARGUMENTLIST signature for argument list snapshot
	ARGUMENTLIST = "AL"
	// MAPARRAYSELECTOR signature for map array snapshot
	MAPARRAYSELECTOR = "MAS"
	// ASSIGMENT signature for assignment snapshot
	ASSIGMENT = "AS"
	// CONSTANT signature for constant snapshot
	CONSTANT = "C"
	// EXPRESSION signature for expression snapshot
	EXPRESSION = "E"
	// EXPRESSIONATOM signature for expression atom snapshot
	EXPRESSIONATOM = "A"
	// FUNCTIONCALL signature for function call snapshot
	FUNCTIONCALL = "F"
	// RULEENTRY signature for rule entry snapshot
	RULEENTRY = "R"
	// THENEXPRESSION signature for then expression snapshot
	THENEXPRESSION = "TE"
	// THENEXPRESSIONLIST signature for then expression list snapshot
	THENEXPRESSIONLIST = "TEL"
	// THENSCOPE signature for then scope snapshot
	THENSCOPE = "TS"
	// WHENSCOPE signature for when scope snapshot
	WHENSCOPE = "WS"
	// VARIABLE signature for variable snapshot
	VARIABLE = "V"
)
View Source
const (
	// OpMul Multiplication operator
	OpMul int = iota
	// OpDiv Divisioon operator
	OpDiv
	// OpMod Modulus operator
	OpMod
	// OpAdd Addition operator
	OpAdd
	// OpSub Substraction operator
	OpSub
	// OpBitAnd Bitwise And operator
	OpBitAnd
	// OpBitOr Bitwise Or operator
	OpBitOr
	// OpGT Greater Than operator
	OpGT
	// OpLT Lesser Than operator
	OpLT
	// OpGTE Greater Than or Equal operator
	OpGTE
	// OpLTE Lesser Than or Equal operator
	OpLTE
	// OpEq Equals operator
	OpEq
	// OpNEq Not Equals operator
	OpNEq
	// OpAnd Logical And operator
	OpAnd
	// OpOr Logical Or operator
	OpOr
)

Variables

View Source
var (
	// AstLog is a logrus instance twith default fields for grule
	AstLog = logrus.WithFields(logrus.Fields{
		"lib":     "grule",
		"package": "AST",
	})
)
View Source
var (
	// GrlLogger is the logger that be used from within the rule engine GRL
	GrlLogger = logrus.WithFields(logrus.Fields{
		"lib":     "grule",
		"package": "AST",
		"source":  "GRL",
	})
)

Functions

This section is empty.

Types

type ArgumentList

type ArgumentList struct {
	AstID   string
	GrlText string

	Arguments []*Expression
}

ArgumentList stores AST graph for ArgumentList that contains expression.

func NewArgumentList

func NewArgumentList() *ArgumentList

NewArgumentList create a new instance of ArgumentList

func (*ArgumentList) AcceptExpression

func (e *ArgumentList) AcceptExpression(exp *Expression) error

AcceptExpression will accept an expression AST graph into this ast graph

func (*ArgumentList) Clone added in v1.4.0

func (e *ArgumentList) Clone(cloneTable *pkg.CloneTable) *ArgumentList

Clone will clone this ArgumentList. The new clone will have an identical structure

func (*ArgumentList) Evaluate

func (e *ArgumentList) Evaluate(dataContext IDataContext, memory *WorkingMemory) ([]reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*ArgumentList) GetAstID

func (e *ArgumentList) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*ArgumentList) GetGrlText

func (e *ArgumentList) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*ArgumentList) GetSnapshot

func (e *ArgumentList) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*ArgumentList) SetGrlText

func (e *ArgumentList) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ArgumentListReceiver

type ArgumentListReceiver interface {
	AcceptArgumentList(argList *ArgumentList) error
}

ArgumentListReceiver will accept an ArgumentList AST graph into this ast graph

type ArrayMapSelector added in v1.6.0

type ArrayMapSelector struct {
	AstID   string
	GrlText string

	Expression *Expression

	Value reflect.Value
}

ArrayMapSelector an array selector graph containing an expression that act ass array or map selector

func NewArrayMapSelector added in v1.6.0

func NewArrayMapSelector() *ArrayMapSelector

NewArrayMapSelector create a new array selector graph

func (*ArrayMapSelector) AcceptExpression added in v1.6.0

func (e *ArrayMapSelector) AcceptExpression(exp *Expression) error

AcceptExpression will accept Expression AST graph node into this node

func (*ArrayMapSelector) Clone added in v1.6.0

func (e *ArrayMapSelector) Clone(cloneTable *pkg.CloneTable) *ArrayMapSelector

Clone will clone this ArgumentList. The new clone will have an identical structure

func (*ArrayMapSelector) Evaluate added in v1.6.0

func (e *ArrayMapSelector) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*ArrayMapSelector) GetAstID added in v1.6.0

func (e *ArrayMapSelector) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*ArrayMapSelector) GetGrlText added in v1.6.0

func (e *ArrayMapSelector) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*ArrayMapSelector) GetSnapshot added in v1.6.0

func (e *ArrayMapSelector) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*ArrayMapSelector) SetGrlText added in v1.6.0

func (e *ArrayMapSelector) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ArrayMapSelectorReceiver added in v1.6.0

type ArrayMapSelectorReceiver interface {
	AcceptArrayMapSelector(sel *ArrayMapSelector) error
}

ArrayMapSelectorReceiver must be implemented by all other ast graph that uses map/array selector

type Assignment

type Assignment struct {
	AstID   string
	GrlText string

	Variable   *Variable
	Expression *Expression
}

Assignment ast node to store assigment expression.

func NewAssignment

func NewAssignment() *Assignment

NewAssignment will create new instance of Assignment AST Node

func (*Assignment) AcceptExpression

func (e *Assignment) AcceptExpression(exp *Expression) error

AcceptExpression will accept an Expression AST graph into this ast graph

func (*Assignment) AcceptVariable

func (e *Assignment) AcceptVariable(vari *Variable) error

AcceptVariable will accept an Variable AST graph into this ast graph

func (*Assignment) Clone added in v1.4.0

func (e *Assignment) Clone(cloneTable *pkg.CloneTable) *Assignment

Clone will clone this Assignment. The new clone will have an identical structure

func (*Assignment) Execute

func (e *Assignment) Execute(dataContext IDataContext, memory *WorkingMemory) error

Execute will execute this graph in the Then scope

func (*Assignment) GetAstID

func (e *Assignment) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*Assignment) GetGrlText

func (e *Assignment) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*Assignment) GetSnapshot

func (e *Assignment) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*Assignment) SetGrlText

func (e *Assignment) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type AssignmentReceiver added in v1.6.0

type AssignmentReceiver interface {
	AcceptAssignment(assignment *Assignment) error
}

AssignmentReceiver must be implemented by all other ast graph that uses an assigment expression

type BuiltInFunctions added in v1.5.0

type BuiltInFunctions struct {
	Knowledge     *KnowledgeBase
	WorkingMemory *WorkingMemory
	DataContext   IDataContext
}

BuiltInFunctions struct hosts the built-in functions ready to invoke from the rule engine execution.

func (*BuiltInFunctions) Changed added in v1.5.0

func (gf *BuiltInFunctions) Changed(variableName string)

Changed will enable Grule's working memory to forget about a variable, so in the next cycle grue will re-valuate that variable instead of just use the value from its working memory. If you change the variable from within grule DRL (using assignment expression, you dont need to call this function on that variable since grule will automaticaly see the change. So only call this function if the variable got changed from your internal struct logic.

func (*BuiltInFunctions) Complete added in v1.5.0

func (gf *BuiltInFunctions) Complete()

Complete will cause the engine to stop processing further rules in the current cycle.

func (*BuiltInFunctions) GetTimeDay added in v1.5.0

func (gf *BuiltInFunctions) GetTimeDay(time time.Time) int

GetTimeDay will get the day value of time

func (*BuiltInFunctions) GetTimeHour added in v1.5.0

func (gf *BuiltInFunctions) GetTimeHour(time time.Time) int

GetTimeHour will get the hour value of time

func (*BuiltInFunctions) GetTimeMinute added in v1.5.0

func (gf *BuiltInFunctions) GetTimeMinute(time time.Time) int

GetTimeMinute will get the minute value of time

func (*BuiltInFunctions) GetTimeMonth added in v1.5.0

func (gf *BuiltInFunctions) GetTimeMonth(time time.Time) int

GetTimeMonth will get the month value of time

func (*BuiltInFunctions) GetTimeSecond added in v1.5.0

func (gf *BuiltInFunctions) GetTimeSecond(time time.Time) int

GetTimeSecond will get the second value of time

func (*BuiltInFunctions) GetTimeYear added in v1.5.0

func (gf *BuiltInFunctions) GetTimeYear(time time.Time) int

GetTimeYear will get the year value of time

func (*BuiltInFunctions) IsNil added in v1.5.0

func (gf *BuiltInFunctions) IsNil(i interface{}) bool

IsNil Enables nill checking on variables.

func (*BuiltInFunctions) IsTimeAfter added in v1.5.0

func (gf *BuiltInFunctions) IsTimeAfter(time, after time.Time) bool

IsTimeAfter will check if the 1st argument is after the 2nd argument.

func (*BuiltInFunctions) IsTimeBefore added in v1.5.0

func (gf *BuiltInFunctions) IsTimeBefore(time, before time.Time) bool

IsTimeBefore will check if the 1st argument is before the 2nd argument.

func (*BuiltInFunctions) IsZero added in v1.5.0

func (gf *BuiltInFunctions) IsZero(i interface{}) bool

IsZero Enable zero checking

func (*BuiltInFunctions) Log added in v1.5.0

func (gf *BuiltInFunctions) Log(text string)

Log extension to log.Print

func (*BuiltInFunctions) LogFormat added in v1.5.0

func (gf *BuiltInFunctions) LogFormat(format string, i interface{})

LogFormat extension to log.Printf

func (*BuiltInFunctions) MakeTime added in v1.5.0

func (gf *BuiltInFunctions) MakeTime(year, month, day, hour, minute, second int64) time.Time

MakeTime will create a Time struct according to the argument values.

func (*BuiltInFunctions) Now added in v1.5.0

func (gf *BuiltInFunctions) Now() time.Time

Now is an extension tn time.Now().

func (*BuiltInFunctions) Retract added in v1.5.0

func (gf *BuiltInFunctions) Retract(ruleName string)

Retract will retract a rule from next evaluation cycle.

func (*BuiltInFunctions) StringContains added in v1.5.0

func (gf *BuiltInFunctions) StringContains(str, substr string) bool

StringContains extension to strings.Contains

func (*BuiltInFunctions) TimeFormat added in v1.5.0

func (gf *BuiltInFunctions) TimeFormat(time time.Time, layout string) string

TimeFormat will format a time according to format layout.

type Constant

type Constant struct {
	AstID         string
	GrlText       string
	Snapshot      string
	DataContext   IDataContext
	WorkingMemory *WorkingMemory
	Value         reflect.Value
}

Constant AST node that stores AST graph for Constants

func NewConstant

func NewConstant() *Constant

NewConstant will create new instance of Constant

func (*Constant) Clone added in v1.4.0

func (e *Constant) Clone(cloneTable *pkg.CloneTable) *Constant

Clone will clone this Constant. The new clone will have an identical structure

func (*Constant) Evaluate

func (e *Constant) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*Constant) GetAstID

func (e *Constant) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*Constant) GetGrlText

func (e *Constant) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*Constant) GetSnapshot

func (e *Constant) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*Constant) SetGrlText

func (e *Constant) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ConstantReceiver

type ConstantReceiver interface {
	AcceptConstant(con *Constant) error
}

ConstantReceiver should be implemented by AST Graph node to receive a Constant Graph Node.

type DataContext

type DataContext struct {
	ObjectStore map[string]interface{}
	// contains filtered or unexported fields
}

DataContext holds all structs instance to be used in rule execution environment.

func (*DataContext) Add

func (ctx *DataContext) Add(key string, obj interface{}) error

Add will add struct instance into rule execution context

func (*DataContext) Complete added in v1.5.0

func (ctx *DataContext) Complete()

Complete marks the DataContext as completed, telling the engine to stop processing rules

func (*DataContext) Get added in v1.6.0

func (ctx *DataContext) Get(key string) model.ValueNode

Get will extract the struct instance

func (*DataContext) HasVariableChange added in v1.5.0

func (ctx *DataContext) HasVariableChange() bool

HasVariableChange returns true if there are variable changes

func (*DataContext) IncrementVariableChangeCount added in v1.5.0

func (ctx *DataContext) IncrementVariableChangeCount()

IncrementVariableChangeCount will increment the variable change count

func (*DataContext) IsComplete added in v1.5.0

func (ctx *DataContext) IsComplete() bool

IsComplete checks whether the DataContext has been completed

func (*DataContext) IsRetracted added in v1.3.0

func (ctx *DataContext) IsRetracted(key string) bool

IsRetracted checks if a key fact is currently retracted.

func (*DataContext) Reset

func (ctx *DataContext) Reset()

Reset will un-retract all fact, making them available for evaluation and modification.

func (*DataContext) ResetVariableChangeCount added in v1.5.0

func (ctx *DataContext) ResetVariableChangeCount()

ResetVariableChangeCount will reset the variable change count

func (*DataContext) Retract

func (ctx *DataContext) Retract(key string)

Retract temporary retract a fact from data context, making it unavailable for evaluation or modification.

func (*DataContext) Retracted

func (ctx *DataContext) Retracted() []string

Retracted returns list of retracted key facts.

type Expression

type Expression struct {
	AstID   string
	GrlText string

	LeftExpression   *Expression
	RightExpression  *Expression
	SingleExpression *Expression
	ExpressionAtom   *ExpressionAtom
	Operator         int
	Value            reflect.Value

	Evaluated bool
}

Expression AST Graph node

func NewExpression

func NewExpression() *Expression

NewExpression creates new Expression instance

func (*Expression) AcceptExpression

func (e *Expression) AcceptExpression(exp *Expression) error

AcceptExpression will accept an Expression AST graph into this ast graph

func (*Expression) AcceptExpressionAtom added in v1.6.0

func (e *Expression) AcceptExpressionAtom(atom *ExpressionAtom) error

AcceptExpressionAtom will accept ExpressionAtom into this Expression

func (*Expression) Clone added in v1.4.0

func (e *Expression) Clone(cloneTable *pkg.CloneTable) *Expression

Clone will clone this Expression. The new clone will have an identical structure

func (*Expression) Evaluate

func (e *Expression) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*Expression) GetAstID

func (e *Expression) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*Expression) GetGrlText

func (e *Expression) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*Expression) GetSnapshot

func (e *Expression) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*Expression) SetGrlText

func (e *Expression) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ExpressionAtom

type ExpressionAtom struct {
	AstID   string
	GrlText string

	Variable     *Variable
	FunctionCall *FunctionCall
	Value        reflect.Value

	Evaluated bool
}

ExpressionAtom AST node graph

func NewExpressionAtom

func NewExpressionAtom() *ExpressionAtom

NewExpressionAtom create new instance of ExpressionAtom

func (*ExpressionAtom) AcceptFunctionCall

func (e *ExpressionAtom) AcceptFunctionCall(fun *FunctionCall) error

AcceptFunctionCall will accept an FunctionCall AST graph into this ast graph

func (*ExpressionAtom) AcceptVariable

func (e *ExpressionAtom) AcceptVariable(vari *Variable) error

AcceptVariable will accept an Variable AST graph into this ast graph

func (*ExpressionAtom) Clone added in v1.4.0

func (e *ExpressionAtom) Clone(cloneTable *pkg.CloneTable) *ExpressionAtom

Clone will clone this ExpressionAtom. The new clone will have an identical structure

func (*ExpressionAtom) Evaluate

func (e *ExpressionAtom) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*ExpressionAtom) GetAstID

func (e *ExpressionAtom) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*ExpressionAtom) GetGrlText

func (e *ExpressionAtom) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*ExpressionAtom) GetSnapshot

func (e *ExpressionAtom) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*ExpressionAtom) SetGrlText

func (e *ExpressionAtom) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ExpressionAtomReceiver added in v1.6.0

type ExpressionAtomReceiver interface {
	AcceptExpressionAtom(exp *ExpressionAtom) error
}

ExpressionAtomReceiver contains function to be implemented by other AST graph to receive an ExpressionAtom AST graph

type ExpressionReceiver

type ExpressionReceiver interface {
	AcceptExpression(exp *Expression) error
}

ExpressionReceiver contains function to be implemented by other AST graph to receive an Expression AST graph

type FunctionCall

type FunctionCall struct {
	AstID   string
	GrlText string

	FunctionName string
	ArgumentList *ArgumentList
	Value        reflect.Value
}

FunctionCall AST graph node

func NewFunctionCall

func NewFunctionCall() *FunctionCall

NewFunctionCall creates new instance of FunctionCall

func (*FunctionCall) AcceptArgumentList

func (e *FunctionCall) AcceptArgumentList(argList *ArgumentList) error

AcceptArgumentList will accept an ArgumentList AST graph into this ast graph

func (*FunctionCall) Clone added in v1.4.0

func (e *FunctionCall) Clone(cloneTable *pkg.CloneTable) *FunctionCall

Clone will clone this FunctionCall. The new clone will have an identical structure

func (*FunctionCall) EvaluateArgumentList added in v1.6.0

func (e *FunctionCall) EvaluateArgumentList(dataContext IDataContext, memory *WorkingMemory) ([]reflect.Value, error)

EvaluateArgumentList will evaluate all arguments and ensure it can be passed into function.

func (*FunctionCall) GetAstID

func (e *FunctionCall) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*FunctionCall) GetGrlText

func (e *FunctionCall) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*FunctionCall) GetSnapshot

func (e *FunctionCall) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*FunctionCall) SetGrlText

func (e *FunctionCall) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type FunctionCallReceiver

type FunctionCallReceiver interface {
	AcceptFunctionCall(fun *FunctionCall) error
}

FunctionCallReceiver should be implemented bu AST graph node to receive a FunctionCall AST graph mode

type Grl added in v1.6.0

type Grl struct {
	RuleEntries map[string]*RuleEntry
}

Grl will contains multiple RuleEntries

func NewGrl added in v1.6.0

func NewGrl() *Grl

NewGrl creates new GRL instance

func (*Grl) ReceiveRuleEntry added in v1.6.0

func (g *Grl) ReceiveRuleEntry(entry *RuleEntry) error

ReceiveRuleEntry will make this GRL to accept rule entries created by ANTLR walker

type GrlReceiver added in v1.6.0

type GrlReceiver interface {
	AcceptGrl(grl *Grl) error
}

GrlReceiver is interface for objects that should hold a GRL, will be called by ANTLR walker.

type IDataContext added in v1.5.0

type IDataContext interface {
	ResetVariableChangeCount()
	IncrementVariableChangeCount()
	HasVariableChange() bool

	Add(key string, obj interface{}) error
	Get(key string) model.ValueNode

	Retract(key string)
	IsRetracted(key string) bool
	Complete()
	IsComplete() bool
	Retracted() []string
	Reset()
}

IDataContext is the interface for the DataContext struct.

func NewDataContext

func NewDataContext() IDataContext

NewDataContext will create a new DataContext instance

type KnowledgeBase

type KnowledgeBase struct {
	Name          string
	Version       string
	DataContext   IDataContext
	WorkingMemory *WorkingMemory
	RuleEntries   map[string]*RuleEntry
	// contains filtered or unexported fields
}

KnowledgeBase is a collection of RuleEntries. It has a name and version.

func (*KnowledgeBase) AddRuleEntry added in v1.2.4

func (e *KnowledgeBase) AddRuleEntry(entry *RuleEntry) error

AddRuleEntry add ruleentry into this knowledge base. return an error if a rule entry with the same name already exist in this knowledge base.

func (*KnowledgeBase) Clone added in v1.4.0

func (e *KnowledgeBase) Clone(cloneTable *pkg.CloneTable) *KnowledgeBase

Clone will clone this instance of KnowledgeBase and produce another (structure wise) identical instance.

func (*KnowledgeBase) ContainsRuleEntry added in v1.2.4

func (e *KnowledgeBase) ContainsRuleEntry(name string) bool

ContainsRuleEntry will check if a rule with such name is already exist in this knowledge base.

func (*KnowledgeBase) GetSnapshot added in v1.6.0

func (e *KnowledgeBase) GetSnapshot() string

GetSnapshot will create this knowledge base signature

func (*KnowledgeBase) InitializeContext

func (e *KnowledgeBase) InitializeContext(dataCtx IDataContext)

InitializeContext will initialize this AST graph with data context and working memory before running rule on them.

func (*KnowledgeBase) IsIdentical added in v1.6.0

func (e *KnowledgeBase) IsIdentical(that *KnowledgeBase) bool

IsIdentical will validate if two KnoledgeBase is identical. Used to validate if the origin and clone is identical.

func (*KnowledgeBase) IsRuleRetracted

func (e *KnowledgeBase) IsRuleRetracted(ruleName string) bool

IsRuleRetracted will check if a certain rule denoted by its rule name is currently retracted

func (*KnowledgeBase) RemoveRuleEntry added in v1.2.4

func (e *KnowledgeBase) RemoveRuleEntry(name string)

RemoveRuleEntry remove the rule entry with specified name from this knowledge base

func (*KnowledgeBase) Reset

func (e *KnowledgeBase) Reset()

Reset will restore all rule in the knowledge

func (*KnowledgeBase) RetractRule

func (e *KnowledgeBase) RetractRule(ruleName string)

RetractRule will retract the selected rule for execution on the next cycle.

type KnowledgeLibrary added in v1.4.0

type KnowledgeLibrary struct {
	Library map[string]*KnowledgeBase
}

KnowledgeLibrary is a knowledgebase store.

func NewKnowledgeLibrary added in v1.4.0

func NewKnowledgeLibrary() *KnowledgeLibrary

NewKnowledgeLibrary create a new instance KnowledgeLibrary

func (*KnowledgeLibrary) GetKnowledgeBase added in v1.4.0

func (lib *KnowledgeLibrary) GetKnowledgeBase(name, version string) *KnowledgeBase

GetKnowledgeBase will get the actual KnowledgeBase blue print that will be used to create instances. Although this KnowledgeBase blueprint works, It SHOULD NOT be used directly in the engine. You should obtain KnowledgeBase instance by calling NewKnowledgeBaseInstance

func (*KnowledgeLibrary) NewKnowledgeBaseInstance added in v1.4.0

func (lib *KnowledgeLibrary) NewKnowledgeBaseInstance(name, version string) *KnowledgeBase

NewKnowledgeBaseInstance will create a new instance based on KnowledgeBase blue print identified by its name and version

type Node

type Node interface {
	GetAstID() string
	GetGrlText() string
	GetSnapshot() string
	SetGrlText(grlText string)
}

Node defines interface to implement by all AST node models

type RuleDescription added in v1.6.0

type RuleDescription struct {
	Text string
}

RuleDescription is a simple AST object to store rule description

func NewRuleDescription added in v1.6.0

func NewRuleDescription(text string) *RuleDescription

NewRuleDescription will create new rule description

type RuleDescriptionReceiver added in v1.6.0

type RuleDescriptionReceiver interface {
	AcceptRuleDescription(ruleDiscription *RuleDescription) error
}

RuleDescriptionReceiver must be implemented by any object that will receive rule description

type RuleEntry

type RuleEntry struct {
	AstID   string
	GrlText string

	RuleName        *RuleName
	RuleDescription *RuleDescription
	Salience        *Salience
	WhenScope       *WhenScope
	ThenScope       *ThenScope

	Retracted bool
}

RuleEntry AST graph node

func NewRuleEntry

func NewRuleEntry() *RuleEntry

NewRuleEntry create new instance of RuleEntry

func (*RuleEntry) AcceptRuleDescription added in v1.6.0

func (e *RuleEntry) AcceptRuleDescription(ruleDescription *RuleDescription) error

AcceptRuleDescription will accept rule description ast object into this rule entry

func (*RuleEntry) AcceptRuleName added in v1.6.0

func (e *RuleEntry) AcceptRuleName(ruleName *RuleName) error

AcceptRuleName will accept rule name ast object into this rule entry

func (*RuleEntry) AcceptSalience added in v1.6.0

func (e *RuleEntry) AcceptSalience(salience *Salience) error

AcceptSalience will accept rule salience ast object into this rule entry

func (*RuleEntry) AcceptThenScope added in v1.6.0

func (e *RuleEntry) AcceptThenScope(then *ThenScope) error

AcceptThenScope will accept then scope ast object into this rule entry

func (*RuleEntry) AcceptWhenScope added in v1.6.0

func (e *RuleEntry) AcceptWhenScope(when *WhenScope) error

AcceptWhenScope will accept when scope ast object into this rule entry

func (*RuleEntry) Clone added in v1.4.0

func (e *RuleEntry) Clone(cloneTable *pkg.CloneTable) *RuleEntry

Clone will clone this RuleEntry. The new clone will have an identical structure

func (*RuleEntry) Evaluate

func (e *RuleEntry) Evaluate(dataContext IDataContext, memory *WorkingMemory) (bool, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*RuleEntry) Execute

func (e *RuleEntry) Execute(dataContext IDataContext, memory *WorkingMemory) (err error)

Execute will execute this graph in the Then scope

func (*RuleEntry) GetAstID

func (e *RuleEntry) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*RuleEntry) GetGrlText

func (e *RuleEntry) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*RuleEntry) GetSnapshot

func (e *RuleEntry) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*RuleEntry) SetGrlText

func (e *RuleEntry) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type RuleEntryReceiver added in v1.6.0

type RuleEntryReceiver interface {
	ReceiveRuleEntry(entry *RuleEntry) error
}

RuleEntryReceiver should be implemented by any rule AST object that receive a RuleEntry

type RuleName added in v1.6.0

type RuleName struct {
	SimpleName string
}

RuleName is a simple ast object to hold rule name

func NewRuleName added in v1.6.0

func NewRuleName(simpleName string) *RuleName

NewRuleName creates RuleName ast object

type RuleNameReceiver added in v1.6.0

type RuleNameReceiver interface {
	AcceptRuleName(ruleName *RuleName) error
}

RuleNameReceiver should be implemented by AST object who stores RuleName

type Salience added in v1.6.0

type Salience struct {
	SalienceValue int
}

Salience is a simple AST object that stores salience

func NewSalience added in v1.6.0

func NewSalience(val int) *Salience

NewSalience create new Salience AST object

type SalienceReceiver added in v1.6.0

type SalienceReceiver interface {
	AcceptSalience(salience *Salience) error
}

SalienceReceiver must be implemented by any AST object that stores salience

type ThenExpression

type ThenExpression struct {
	AstID   string
	GrlText string

	Assignment   *Assignment
	FunctionCall *FunctionCall
	Variable     *Variable
}

ThenExpression AST graph node

func NewThenExpression

func NewThenExpression() *ThenExpression

NewThenExpression create new instance of ThenExpression

func (*ThenExpression) AcceptAssignment added in v1.6.0

func (e *ThenExpression) AcceptAssignment(assignment *Assignment) error

AcceptAssignment will accept Assignment AST graph into this Then ast graph

func (*ThenExpression) AcceptFunctionCall

func (e *ThenExpression) AcceptFunctionCall(fun *FunctionCall) error

AcceptFunctionCall will accept an FunctionCall AST graph into this ast graph

func (*ThenExpression) AcceptVariable added in v1.6.0

func (e *ThenExpression) AcceptVariable(vari *Variable) error

AcceptVariable will accept variable AST object into this then expression

func (*ThenExpression) Clone added in v1.4.0

func (e *ThenExpression) Clone(cloneTable *pkg.CloneTable) *ThenExpression

Clone will clone this ThenExpression. The new clone will have an identical structure

func (*ThenExpression) Execute

func (e *ThenExpression) Execute(dataContext IDataContext, memory *WorkingMemory) error

Execute will execute this graph in the Then scope

func (*ThenExpression) GetAstID

func (e *ThenExpression) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*ThenExpression) GetGrlText

func (e *ThenExpression) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*ThenExpression) GetSnapshot

func (e *ThenExpression) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*ThenExpression) SetGrlText

func (e *ThenExpression) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ThenExpressionList

type ThenExpressionList struct {
	AstID   string
	GrlText string

	ThenExpressions []*ThenExpression
}

ThenExpressionList AST graph node

func NewThenExpressionList

func NewThenExpressionList() *ThenExpressionList

NewThenExpressionList creates new instance of ThenExpressionList

func (*ThenExpressionList) AcceptThenExpression added in v1.6.0

func (e *ThenExpressionList) AcceptThenExpression(expr *ThenExpression) error

AcceptThenExpression will accept ThenExpression AST graph into this ExpressionList

func (*ThenExpressionList) Clone added in v1.4.0

func (e *ThenExpressionList) Clone(cloneTable *pkg.CloneTable) *ThenExpressionList

Clone will clone this ThenExpressionList. The new clone will have an identical structure

func (*ThenExpressionList) Execute

func (e *ThenExpressionList) Execute(dataContext IDataContext, memory *WorkingMemory) error

Execute will execute this graph in the Then scope

func (*ThenExpressionList) GetAstID

func (e *ThenExpressionList) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*ThenExpressionList) GetGrlText

func (e *ThenExpressionList) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*ThenExpressionList) GetSnapshot

func (e *ThenExpressionList) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*ThenExpressionList) SetGrlText

func (e *ThenExpressionList) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ThenExpressionListReceiver added in v1.6.0

type ThenExpressionListReceiver interface {
	AcceptThenExpressionList(list *ThenExpressionList) error
}

ThenExpressionListReceiver must be implemented by any AST object that hold a ThenExpression list AST object

type ThenExpressionReceiver added in v1.6.0

type ThenExpressionReceiver interface {
	AcceptThenExpression(expr *ThenExpression) error
}

ThenExpressionReceiver must be implemented by any AST object that will store a Then expression

type ThenScope

type ThenScope struct {
	AstID   string
	GrlText string

	ThenExpressionList *ThenExpressionList
}

ThenScope AST graph node

func NewThenScope

func NewThenScope() *ThenScope

NewThenScope will create new instance of ThenScope

func (*ThenScope) AcceptThenExpressionList added in v1.6.0

func (e *ThenScope) AcceptThenExpressionList(list *ThenExpressionList) error

AcceptThenExpressionList will accept ThenExpressionList graph into this ThenScope

func (*ThenScope) Clone added in v1.4.0

func (e *ThenScope) Clone(cloneTable *pkg.CloneTable) *ThenScope

Clone will clone this ThenScope. The new clone will have an identical structure

func (*ThenScope) Execute

func (e *ThenScope) Execute(dataContext IDataContext, memory *WorkingMemory) error

Execute will execute this graph in the Then scope

func (*ThenScope) GetAstID

func (e *ThenScope) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*ThenScope) GetGrlText

func (e *ThenScope) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*ThenScope) GetSnapshot

func (e *ThenScope) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*ThenScope) SetGrlText

func (e *ThenScope) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type ThenScopeReceiver added in v1.6.0

type ThenScopeReceiver interface {
	AcceptThenScope(thenScope *ThenScope) error
}

ThenScopeReceiver must be implemented by any AST object that will hold a ThenScope

type Variable

type Variable struct {
	AstID   string
	GrlText string

	Name             string
	Constant         *Constant
	Variable         *Variable
	FunctionCall     *FunctionCall
	ArrayMapSelector *ArrayMapSelector

	ValueNode model.ValueNode
	Value     reflect.Value
}

Variable AST graph node

func NewVariable

func NewVariable() *Variable

NewVariable create new instance of Variable

func (*Variable) AcceptArrayMapSelector added in v1.6.0

func (e *Variable) AcceptArrayMapSelector(sel *ArrayMapSelector) error

AcceptArrayMapSelector accept an array map selector into this variable graph

func (*Variable) AcceptConstant added in v1.6.0

func (e *Variable) AcceptConstant(con *Constant) error

AcceptConstant accept a constant AST graph into this variable graph.

func (*Variable) AcceptFunctionCall added in v1.6.0

func (e *Variable) AcceptFunctionCall(fu *FunctionCall) error

AcceptFunctionCall accept a function call AST graph into this variable graph

func (*Variable) AcceptVariable added in v1.6.0

func (e *Variable) AcceptVariable(vari *Variable) error

AcceptVariable accept a variable AST graph into this Variable graph

func (*Variable) Assign added in v1.6.0

func (e *Variable) Assign(newVal reflect.Value, dataContext IDataContext, memory *WorkingMemory) error

Assign will assign the specified value to the variable

func (*Variable) Clone added in v1.4.0

func (e *Variable) Clone(cloneTable *pkg.CloneTable) *Variable

Clone will clone this Variable. The new clone will have an identical structure

func (*Variable) Evaluate

func (e *Variable) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*Variable) GetAstID

func (e *Variable) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*Variable) GetGrlText

func (e *Variable) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*Variable) GetSnapshot

func (e *Variable) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*Variable) SetGrlText

func (e *Variable) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type VariableReceiver

type VariableReceiver interface {
	AcceptVariable(exp *Variable) error
}

VariableReceiver should be implemented by AST graph node to receive Variable AST graph node

type WhenScope

type WhenScope struct {
	AstID   string
	GrlText string

	Expression *Expression
}

WhenScope AST graph node

func NewWhenScope

func NewWhenScope() *WhenScope

NewWhenScope creates new instance of WhenScope

func (*WhenScope) AcceptExpression

func (e *WhenScope) AcceptExpression(exp *Expression) error

AcceptExpression will accept Expression AST graph node into this node

func (*WhenScope) Clone added in v1.4.0

func (e *WhenScope) Clone(cloneTable *pkg.CloneTable) *WhenScope

Clone will clone this Clone. The new clone will have an identical structure

func (*WhenScope) Evaluate

func (e *WhenScope) Evaluate(dataContext IDataContext, memory *WorkingMemory) (reflect.Value, error)

Evaluate will evaluate this AST graph for when scope evaluation

func (*WhenScope) GetAstID

func (e *WhenScope) GetAstID() string

GetAstID get the UUID asigned for this AST graph node

func (*WhenScope) GetGrlText

func (e *WhenScope) GetGrlText() string

GetGrlText get the expression syntax related to this graph when it wast constructed

func (*WhenScope) GetSnapshot

func (e *WhenScope) GetSnapshot() string

GetSnapshot will create a structure signature or AST graph

func (*WhenScope) SetGrlText

func (e *WhenScope) SetGrlText(grlText string)

SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.

type WhenScopeReceiver added in v1.6.0

type WhenScopeReceiver interface {
	AcceptWhenScope(whenScope *WhenScope) error
}

WhenScopeReceiver must be implemented by AST object that stores WhenScope

type WorkingMemory

type WorkingMemory struct {
	Name    string
	Version string

	ID string
	// contains filtered or unexported fields
}

WorkingMemory handles states of expression evaluation status

func NewWorkingMemory

func NewWorkingMemory(name, version string) *WorkingMemory

NewWorkingMemory create new instance of WorkingMemory

func (*WorkingMemory) AddExpression added in v1.6.0

func (e *WorkingMemory) AddExpression(exp *Expression) *Expression

AddExpression will add expression into its map if the expression signature is unique if the expression is already in its map, it will return one from the map.

func (*WorkingMemory) AddExpressionAtom added in v1.6.0

func (e *WorkingMemory) AddExpressionAtom(exp *ExpressionAtom) *ExpressionAtom

AddExpressionAtom will add expression atom into its map if the expression signature is unique if the expression is already in its map, it will return one from the map.

func (*WorkingMemory) AddVariable added in v1.6.0

func (e *WorkingMemory) AddVariable(vari *Variable) *Variable

AddVariable will add variable into its map if the expression signature is unique if the expression is already in its map, it will return one from the map.

func (*WorkingMemory) Clone added in v1.4.0

func (e *WorkingMemory) Clone(cloneTable *pkg.CloneTable) *WorkingMemory

Clone will clone this WorkingMemory. The new clone will have an identical structure

func (*WorkingMemory) DebugContent added in v1.6.0

func (e *WorkingMemory) DebugContent()

DebugContent will shows the working memory mapping content

func (*WorkingMemory) Equals added in v1.6.0

func (e *WorkingMemory) Equals(that *WorkingMemory) bool

Equals shallowly equals check this Working Memory against other working memory

func (*WorkingMemory) IndexVariables added in v1.6.0

func (e *WorkingMemory) IndexVariables()

IndexVariables will index all expression and expression atoms that contains a speciffic variable name

func (*WorkingMemory) Reset

func (e *WorkingMemory) Reset(varName string) bool

Reset will reset the evaluated status of a specific variable if its contains a variable name in its signature. Returns true if any expression was reset, false if otherwise

func (*WorkingMemory) ResetAll

func (e *WorkingMemory) ResetAll() bool

ResetAll sets all expression evaluated status to false. Returns true if any expression was reset, false if otherwise

func (*WorkingMemory) ResetVariable added in v1.6.0

func (e *WorkingMemory) ResetVariable(variable *Variable) bool

ResetVariable will reset the evaluated status of a specific expression if its contains a variable name in its signature. Returns true if any expression was reset, false if otherwise

Jump to

Keyboard shortcuts

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