Documentation ¶
Index ¶
- Constants
- Variables
- type ArgumentList
- func (e *ArgumentList) AcceptExpression(exp *Expression) error
- func (e ArgumentList) Clone(cloneTable *pkg.CloneTable) *ArgumentList
- func (e *ArgumentList) Evaluate() ([]reflect.Value, error)
- func (e *ArgumentList) GetAstID() string
- func (e *ArgumentList) GetGrlText() string
- func (e *ArgumentList) GetSnapshot() string
- func (e *ArgumentList) InitializeContext(dataCtx IDataContext, workingMemory *WorkingMemory)
- func (e *ArgumentList) SetGrlText(grlText string)
- type ArgumentListReceiver
- type Assignment
- func (e *Assignment) AcceptExpression(exp *Expression) error
- func (e *Assignment) AcceptVariable(vari *Variable) error
- func (e Assignment) Clone(cloneTable *pkg.CloneTable) *Assignment
- func (e *Assignment) Execute() error
- func (e *Assignment) GetAstID() string
- func (e *Assignment) GetGrlText() string
- func (e *Assignment) GetSnapshot() string
- func (e *Assignment) InitializeContext(dataCtx IDataContext, workingMemory *WorkingMemory)
- func (e *Assignment) SetGrlText(grlText string)
- type BuiltInFunctions
- func (gf *BuiltInFunctions) Changed(variableName string)
- func (gf *BuiltInFunctions) Complete()
- func (gf *BuiltInFunctions) GetTimeDay(time time.Time) int
- func (gf *BuiltInFunctions) GetTimeHour(time time.Time) int
- func (gf *BuiltInFunctions) GetTimeMinute(time time.Time) int
- func (gf *BuiltInFunctions) GetTimeMonth(time time.Time) int
- func (gf *BuiltInFunctions) GetTimeSecond(time time.Time) int
- func (gf *BuiltInFunctions) GetTimeYear(time time.Time) int
- func (gf *BuiltInFunctions) IsNil(i interface{}) bool
- func (gf *BuiltInFunctions) IsTimeAfter(time, after time.Time) bool
- func (gf *BuiltInFunctions) IsTimeBefore(time, before time.Time) bool
- func (gf *BuiltInFunctions) IsZero(i interface{}) bool
- func (gf *BuiltInFunctions) Log(text string)
- func (gf *BuiltInFunctions) LogFormat(format string, i interface{})
- func (gf *BuiltInFunctions) MakeTime(year, month, day, hour, minute, second int64) time.Time
- func (gf *BuiltInFunctions) Now() time.Time
- func (gf *BuiltInFunctions) Retract(ruleName string)
- func (gf *BuiltInFunctions) StringContains(str, substr string) bool
- func (gf *BuiltInFunctions) TimeFormat(time time.Time, layout string) string
- type Constant
- func (e Constant) Clone(cloneTable *pkg.CloneTable) *Constant
- func (e *Constant) Evaluate() (reflect.Value, error)
- func (e *Constant) GetAstID() string
- func (e *Constant) GetGrlText() string
- func (e *Constant) GetSnapshot() string
- func (e *Constant) InitializeContext(dataCtx IDataContext, memory *WorkingMemory)
- func (e *Constant) SetGrlText(grlText string)
- type ConstantReceiver
- type DataContext
- func (ctx *DataContext) Add(key string, obj interface{}) error
- func (ctx *DataContext) Complete()
- func (ctx *DataContext) ExecMethod(methodName string, args []reflect.Value) (reflect.Value, error)
- func (ctx *DataContext) GetType(variable string) (reflect.Type, error)
- func (ctx *DataContext) GetValue(variable string) (reflect.Value, error)
- func (ctx *DataContext) HasVariableChange() bool
- func (ctx *DataContext) IncrementVariableChangeCount()
- func (ctx *DataContext) IsComplete() bool
- func (ctx *DataContext) IsRetracted(key string) bool
- func (ctx *DataContext) Reset()
- func (ctx *DataContext) ResetVariableChangeCount()
- func (ctx *DataContext) Retract(key string)
- func (ctx *DataContext) Retracted() []string
- func (ctx *DataContext) SetValue(variable string, newValue reflect.Value) error
- type Expression
- func (e *Expression) AcceptExpression(exp *Expression) error
- func (e Expression) Clone(cloneTable *pkg.CloneTable) *Expression
- func (e *Expression) Evaluate() (reflect.Value, error)
- func (e *Expression) GetAstID() string
- func (e *Expression) GetGrlText() string
- func (e *Expression) GetSnapshot() string
- func (e *Expression) InitializeContext(dataCtx IDataContext, memory *WorkingMemory)
- func (e *Expression) SetGrlText(grlText string)
- type ExpressionAtom
- func (e *ExpressionAtom) AcceptConstant(con *Constant) error
- func (e *ExpressionAtom) AcceptFunctionCall(fun *FunctionCall) error
- func (e *ExpressionAtom) AcceptMethodCall(fun *MethodCall) error
- func (e *ExpressionAtom) AcceptVariable(vari *Variable) error
- func (e ExpressionAtom) Clone(cloneTable *pkg.CloneTable) *ExpressionAtom
- func (e *ExpressionAtom) Evaluate() (reflect.Value, error)
- func (e *ExpressionAtom) GetAstID() string
- func (e *ExpressionAtom) GetGrlText() string
- func (e *ExpressionAtom) GetSnapshot() string
- func (e *ExpressionAtom) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *ExpressionAtom) SetGrlText(grlText string)
- type ExpressionReceiver
- type FunctionCall
- func (e *FunctionCall) AcceptArgumentList(argList *ArgumentList)
- func (e FunctionCall) Clone(cloneTable *pkg.CloneTable) *FunctionCall
- func (e *FunctionCall) Evaluate() (reflect.Value, error)
- func (e *FunctionCall) GetAstID() string
- func (e *FunctionCall) GetGrlText() string
- func (e *FunctionCall) GetSnapshot() string
- func (e *FunctionCall) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *FunctionCall) SetGrlText(grlText string)
- type FunctionCallReceiver
- type IDataContext
- type KnowledgeBase
- func (e *KnowledgeBase) AddRuleEntry(entry *RuleEntry) error
- func (e *KnowledgeBase) Clone(cloneTable *pkg.CloneTable) *KnowledgeBase
- func (e *KnowledgeBase) ContainsRuleEntry(name string) bool
- func (e *KnowledgeBase) InitializeContext(dataCtx IDataContext)
- func (e *KnowledgeBase) IsRuleRetracted(ruleName string) bool
- func (e *KnowledgeBase) RemoveRuleEntry(name string)
- func (e *KnowledgeBase) Reset()
- func (e *KnowledgeBase) RetractRule(ruleName string)
- type KnowledgeLibrary
- type MethodCall
- func (e *MethodCall) AcceptArgumentList(argList *ArgumentList)
- func (e MethodCall) Clone(cloneTable *pkg.CloneTable) *MethodCall
- func (e *MethodCall) Evaluate() (reflect.Value, error)
- func (e *MethodCall) GetAstID() string
- func (e *MethodCall) GetGrlText() string
- func (e *MethodCall) GetSnapshot() string
- func (e *MethodCall) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *MethodCall) SetGrlText(grlText string)
- type MethodCallReceiver
- type Node
- type RuleEntry
- func (e RuleEntry) Clone(cloneTable *pkg.CloneTable) *RuleEntry
- func (e *RuleEntry) Evaluate() (bool, error)
- func (e *RuleEntry) Execute() error
- func (e *RuleEntry) GetAstID() string
- func (e *RuleEntry) GetGrlText() string
- func (e *RuleEntry) GetSnapshot() string
- func (e *RuleEntry) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *RuleEntry) SetGrlText(grlText string)
- type ThenExpression
- func (e *ThenExpression) AcceptFunctionCall(fun *FunctionCall) error
- func (e *ThenExpression) AcceptMethodCall(fun *MethodCall) error
- func (e ThenExpression) Clone(cloneTable *pkg.CloneTable) *ThenExpression
- func (e *ThenExpression) Execute() error
- func (e *ThenExpression) GetAstID() string
- func (e *ThenExpression) GetGrlText() string
- func (e *ThenExpression) GetSnapshot() string
- func (e *ThenExpression) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *ThenExpression) SetGrlText(grlText string)
- type ThenExpressionList
- func (e ThenExpressionList) Clone(cloneTable *pkg.CloneTable) *ThenExpressionList
- func (e *ThenExpressionList) Execute() error
- func (e *ThenExpressionList) GetAstID() string
- func (e *ThenExpressionList) GetGrlText() string
- func (e *ThenExpressionList) GetSnapshot() string
- func (e *ThenExpressionList) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *ThenExpressionList) SetGrlText(grlText string)
- type ThenScope
- func (e ThenScope) Clone(cloneTable *pkg.CloneTable) *ThenScope
- func (e *ThenScope) Execute() error
- func (e *ThenScope) GetAstID() string
- func (e *ThenScope) GetGrlText() string
- func (e *ThenScope) GetSnapshot() string
- func (e *ThenScope) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *ThenScope) SetGrlText(grlText string)
- type Variable
- func (e Variable) Clone(cloneTable *pkg.CloneTable) *Variable
- func (e *Variable) Evaluate() (reflect.Value, error)
- func (e *Variable) GetAstID() string
- func (e *Variable) GetGrlText() string
- func (e *Variable) GetSnapshot() string
- func (e *Variable) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *Variable) SetGrlText(grlText string)
- type VariableReceiver
- type WhenScope
- func (e *WhenScope) AcceptExpression(exp *Expression) error
- func (e WhenScope) Clone(cloneTable *pkg.CloneTable) *WhenScope
- func (e *WhenScope) Evaluate() (reflect.Value, error)
- func (e *WhenScope) GetAstID() string
- func (e *WhenScope) GetGrlText() string
- func (e *WhenScope) GetSnapshot() string
- func (e *WhenScope) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
- func (e *WhenScope) SetGrlText(grlText string)
- type WorkingMemory
Constants ¶
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 ¶
var ( // AstLog is a logrus instance twith default fields for grule AstLog = logrus.WithFields(logrus.Fields{ "lib": "grule", "package": "AST", }) )
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 DataContext IDataContext WorkingMemory *WorkingMemory 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() ([]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) InitializeContext ¶
func (e *ArgumentList) InitializeContext(dataCtx IDataContext, workingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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)
}
ArgumentListReceiver will accept an ArgumentList AST graph into this ast graph
type Assignment ¶
type Assignment struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory 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() 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) InitializeContext ¶
func (e *Assignment) InitializeContext(dataCtx IDataContext, workingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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 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 (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) GetGrlText ¶
GetGrlText get the expression syntax related to this graph when it wast constructed
func (*Constant) GetSnapshot ¶
GetSnapshot will create a structure signature or AST graph
func (*Constant) InitializeContext ¶
func (e *Constant) InitializeContext(dataCtx IDataContext, memory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
func (*Constant) SetGrlText ¶
SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.
type ConstantReceiver ¶
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) ExecMethod ¶
ExecMethod will execute instance member variable using the supplied arguments.
func (*DataContext) GetType ¶
func (ctx *DataContext) GetType(variable string) (reflect.Type, error)
GetType will extract type information of data in this context.
func (*DataContext) GetValue ¶
func (ctx *DataContext) GetValue(variable string) (reflect.Value, error)
GetValue will get member variables Value information. Used by the rule execution to obtain variable value.
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 DataContext IDataContext WorkingMemory *WorkingMemory LeftExpression *Expression RightExpression *Expression SingleExpression *Expression ExpressionAtom *ExpressionAtom Operator int Value reflect.Value Evaluated bool }
Expression AST Graph node
func (*Expression) AcceptExpression ¶
func (e *Expression) AcceptExpression(exp *Expression) error
AcceptExpression will accept an Expression AST graph into this ast graph
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() (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) InitializeContext ¶
func (e *Expression) InitializeContext(dataCtx IDataContext, memory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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 DataContext IDataContext WorkingMemory *WorkingMemory Constant *Constant Variable *Variable FunctionCall *FunctionCall MethodCall *MethodCall Value reflect.Value }
ExpressionAtom AST node graph
func NewExpressionAtom ¶
func NewExpressionAtom() *ExpressionAtom
NewExpressionAtom create new instance of ExpressionAtom
func (*ExpressionAtom) AcceptConstant ¶
func (e *ExpressionAtom) AcceptConstant(con *Constant) error
AcceptConstant will accept an Constant AST graph into this ast graph
func (*ExpressionAtom) AcceptFunctionCall ¶
func (e *ExpressionAtom) AcceptFunctionCall(fun *FunctionCall) error
AcceptFunctionCall will accept an FunctionCall AST graph into this ast graph
func (*ExpressionAtom) AcceptMethodCall ¶
func (e *ExpressionAtom) AcceptMethodCall(fun *MethodCall) error
AcceptMethodCall will accept an MethodCall 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() (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) InitializeContext ¶
func (e *ExpressionAtom) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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 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 DataContext IDataContext WorkingMemory *WorkingMemory 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)
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) Evaluate ¶
func (e *FunctionCall) Evaluate() (reflect.Value, error)
Evaluate will evaluate this AST graph for when scope evaluation
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) InitializeContext ¶
func (e *FunctionCall) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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 IDataContext ¶ added in v1.5.0
type IDataContext interface { ResetVariableChangeCount() IncrementVariableChangeCount() HasVariableChange() bool Add(key string, obj interface{}) error Retract(key string) IsRetracted(key string) bool Complete() IsComplete() bool Retracted() []string Reset() ExecMethod(methodName string, args []reflect.Value) (reflect.Value, error) GetType(variable string) (reflect.Type, error) GetValue(variable string) (reflect.Value, error) SetValue(variable string, newValue reflect.Value) error }
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 Publisher *eventbus.Publisher // 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) 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) 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 MethodCall ¶
type MethodCall struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory MethodName string ArgumentList *ArgumentList Value reflect.Value }
MethodCall AST node graph
func NewMethodCall ¶
func NewMethodCall() *MethodCall
NewMethodCall create new instance of MethodCall
func (*MethodCall) AcceptArgumentList ¶
func (e *MethodCall) AcceptArgumentList(argList *ArgumentList)
AcceptArgumentList will accept an ArgumentList AST graph into this ast graph
func (MethodCall) Clone ¶ added in v1.4.0
func (e MethodCall) Clone(cloneTable *pkg.CloneTable) *MethodCall
Clone will clone this MethodCall. The new clone will have an identical structure
func (*MethodCall) Evaluate ¶
func (e *MethodCall) Evaluate() (reflect.Value, error)
Evaluate will evaluate this AST graph for when scope evaluation
func (*MethodCall) GetAstID ¶
func (e *MethodCall) GetAstID() string
GetAstID get the UUID asigned for this AST graph node
func (*MethodCall) GetGrlText ¶
func (e *MethodCall) GetGrlText() string
GetGrlText get the expression syntax related to this graph when it wast constructed
func (*MethodCall) GetSnapshot ¶
func (e *MethodCall) GetSnapshot() string
GetSnapshot will create a structure signature or AST graph
func (*MethodCall) InitializeContext ¶
func (e *MethodCall) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
func (*MethodCall) SetGrlText ¶
func (e *MethodCall) SetGrlText(grlText string)
SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.
type MethodCallReceiver ¶
type MethodCallReceiver interface {
AcceptMethodCall(fun *MethodCall) error
}
MethodCallReceiver should be implemented by AST graph node to receive MethodCall AST graph node
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 RuleEntry ¶
type RuleEntry struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory Name string Description string Salience int WhenScope *WhenScope ThenScope *ThenScope Retracted bool }
RuleEntry AST graph node
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) GetGrlText ¶
GetGrlText get the expression syntax related to this graph when it wast constructed
func (*RuleEntry) GetSnapshot ¶
GetSnapshot will create a structure signature or AST graph
func (*RuleEntry) InitializeContext ¶
func (e *RuleEntry) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
func (*RuleEntry) SetGrlText ¶
SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.
type ThenExpression ¶
type ThenExpression struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory Assignment *Assignment FunctionCall *FunctionCall MethodCall *MethodCall }
ThenExpression AST graph node
func NewThenExpression ¶
func NewThenExpression() *ThenExpression
NewThenExpression create new instance of ThenExpression
func (*ThenExpression) AcceptFunctionCall ¶
func (e *ThenExpression) AcceptFunctionCall(fun *FunctionCall) error
AcceptFunctionCall will accept an FunctionCall AST graph into this ast graph
func (*ThenExpression) AcceptMethodCall ¶
func (e *ThenExpression) AcceptMethodCall(fun *MethodCall) error
AcceptMethodCall will accept an MethodCall AST graph into this ast graph
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() 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) InitializeContext ¶
func (e *ThenExpression) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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 DataContext IDataContext WorkingMemory *WorkingMemory ThenExpressions []*ThenExpression }
ThenExpressionList AST graph node
func NewThenExpressionList ¶
func NewThenExpressionList() *ThenExpressionList
NewThenExpressionList creates new instance of ThenExpressionList
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() 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) InitializeContext ¶
func (e *ThenExpressionList) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
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 ThenScope ¶
type ThenScope struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory ThenExpressionList *ThenExpressionList }
ThenScope AST graph node
func NewThenScope ¶
func NewThenScope() *ThenScope
NewThenScope will create new instance of 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) GetGrlText ¶
GetGrlText get the expression syntax related to this graph when it wast constructed
func (*ThenScope) GetSnapshot ¶
GetSnapshot will create a structure signature or AST graph
func (*ThenScope) InitializeContext ¶
func (e *ThenScope) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
func (*ThenScope) SetGrlText ¶
SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.
type Variable ¶
type Variable struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory Name string Value reflect.Value }
Variable AST graph node
func NewVariable ¶
NewVariable create new instance of 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) GetGrlText ¶
GetGrlText get the expression syntax related to this graph when it wast constructed
func (*Variable) GetSnapshot ¶
GetSnapshot will create a structure signature or AST graph
func (*Variable) InitializeContext ¶
func (e *Variable) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
func (*Variable) SetGrlText ¶
SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.
type VariableReceiver ¶
VariableReceiver should be implemented by AST graph node to receive Variable AST graph node
type WhenScope ¶
type WhenScope struct { AstID string GrlText string DataContext IDataContext WorkingMemory *WorkingMemory Expression *Expression }
WhenScope AST graph node
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) GetGrlText ¶
GetGrlText get the expression syntax related to this graph when it wast constructed
func (*WhenScope) GetSnapshot ¶
GetSnapshot will create a structure signature or AST graph
func (*WhenScope) InitializeContext ¶
func (e *WhenScope) InitializeContext(dataCtx IDataContext, WorkingMemory *WorkingMemory)
InitializeContext will initialize this AST graph with data context and working memory before running rule on them.
func (*WhenScope) SetGrlText ¶
SetGrlText set the expression syntax related to this graph when it was constructed. Only ANTLR4 listener should call this function.
type WorkingMemory ¶
type WorkingMemory struct { Name string Version string ExpressionSnapshotMap map[string]*Expression ExpressionVariableMap map[string][]*Expression ID string }
WorkingMemory handles states of expression evaluation status
func NewWorkingMemory ¶
func NewWorkingMemory(name, version string) *WorkingMemory
NewWorkingMemory create new instance of WorkingMemory
func (*WorkingMemory) Add ¶
func (e *WorkingMemory) Add(exp *Expression) (*Expression, bool)
Add 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) 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) IndexVar ¶ added in v1.2.2
func (e *WorkingMemory) IndexVar(varName string) bool
IndexVar will index all expression that contains a speciffic variable name
func (*WorkingMemory) Reset ¶
func (e *WorkingMemory) Reset(variableName string) bool
Reset will reset the evaluated status of a speciffic expression 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