Documentation ¶
Index ¶
- Constants
- Variables
- type ArgumentList
- func (e *ArgumentList) AcceptExpression(exp *Expression) error
- 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 *DataContext, 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) Execute() error
- func (e *Assignment) GetAstID() string
- func (e *Assignment) GetGrlText() string
- func (e *Assignment) GetSnapshot() string
- func (e *Assignment) InitializeContext(dataCtx *DataContext, workingMemory *WorkingMemory)
- func (e *Assignment) SetGrlText(grlText string)
- type BuildInFunctions
- func (gf *BuildInFunctions) Changed(variableName string)
- func (gf *BuildInFunctions) GetTimeDay(time time.Time) int
- func (gf *BuildInFunctions) GetTimeHour(time time.Time) int
- func (gf *BuildInFunctions) GetTimeMinute(time time.Time) int
- func (gf *BuildInFunctions) GetTimeMonth(time time.Time) int
- func (gf *BuildInFunctions) GetTimeSecond(time time.Time) int
- func (gf *BuildInFunctions) GetTimeYear(time time.Time) int
- func (gf *BuildInFunctions) IsNil(i interface{}) bool
- func (gf *BuildInFunctions) IsTimeAfter(time, after time.Time) bool
- func (gf *BuildInFunctions) IsTimeBefore(time, before time.Time) bool
- func (gf *BuildInFunctions) IsZero(i interface{}) bool
- func (gf *BuildInFunctions) Log(text string)
- func (gf *BuildInFunctions) LogFormat(format string, i interface{})
- func (gf *BuildInFunctions) MakeTime(year, month, day, hour, minute, second int64) time.Time
- func (gf *BuildInFunctions) Now() time.Time
- func (gf *BuildInFunctions) Retract(ruleName string)
- func (gf *BuildInFunctions) StringContains(str, substr string) bool
- func (gf *BuildInFunctions) TimeFormat(time time.Time, layout string) string
- type Constant
- type ConstantReceiver
- type DataContext
- func (ctx *DataContext) Add(key string, obj interface{}) error
- 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) IsRestracted(key string) bool
- func (ctx *DataContext) Reset()
- func (ctx *DataContext) Retract(key string)
- func (ctx *DataContext) SetValue(variable string, newValue reflect.Value) error
- type Expression
- func (e *Expression) AcceptExpression(exp *Expression) error
- 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 *DataContext, 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) Evaluate() (reflect.Value, error)
- func (e *ExpressionAtom) GetAstID() string
- func (e *ExpressionAtom) GetGrlText() string
- func (e *ExpressionAtom) GetSnapshot() string
- func (e *ExpressionAtom) InitializeContext(dataCtx *DataContext, WorkingMemory *WorkingMemory)
- func (e *ExpressionAtom) SetGrlText(grlText string)
- type ExpressionReceiver
- type FunctionCall
- func (e *FunctionCall) AcceptArgumentList(argList *ArgumentList)
- 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 *DataContext, WorkingMemory *WorkingMemory)
- func (e *FunctionCall) SetGrlText(grlText string)
- type FunctionCallReceiver
- type KnowledgeBase
- func (e *KnowledgeBase) AddRuleEntry(entry *RuleEntry) error
- func (e *KnowledgeBase) ContainsRuleEntry(name string) bool
- func (e *KnowledgeBase) InitializeContext(dataCtx *DataContext, memory *WorkingMemory)
- func (e *KnowledgeBase) IsRuleRetracted(ruleName string) bool
- func (e *KnowledgeBase) RemoveRuleEntry(name string)
- func (e *KnowledgeBase) Reset()
- func (e *KnowledgeBase) RetractRule(ruleName string)
- type MethodCall
- func (e *MethodCall) AcceptArgumentList(argList *ArgumentList)
- 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 *DataContext, WorkingMemory *WorkingMemory)
- func (e *MethodCall) SetGrlText(grlText string)
- type MethodCallReceiver
- type Node
- type 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 *DataContext, 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) Execute() error
- func (e *ThenExpression) GetAstID() string
- func (e *ThenExpression) GetGrlText() string
- func (e *ThenExpression) GetSnapshot() string
- func (e *ThenExpression) InitializeContext(dataCtx *DataContext, WorkingMemory *WorkingMemory)
- func (e *ThenExpression) SetGrlText(grlText string)
- type 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 *DataContext, WorkingMemory *WorkingMemory)
- func (e *ThenExpressionList) SetGrlText(grlText string)
- type ThenScope
- type 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 *DataContext, WorkingMemory *WorkingMemory)
- func (e *Variable) SetGrlText(grlText string)
- type VariableReceiver
- type WhenScope
- func (e *WhenScope) AcceptExpression(exp *Expression) error
- 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 *DataContext, 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 *DataContext 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) 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 *DataContext, 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 *DataContext 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) 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 *DataContext, 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 BuildInFunctions ¶
type BuildInFunctions struct { Knowledge *KnowledgeBase WorkingMemory *WorkingMemory }
BuildInFunctions strucr hosts the built-in functions ready to invoke from the rule engine execution.
func (*BuildInFunctions) Changed ¶
func (gf *BuildInFunctions) 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 (*BuildInFunctions) GetTimeDay ¶
func (gf *BuildInFunctions) GetTimeDay(time time.Time) int
GetTimeDay will get the day value of time
func (*BuildInFunctions) GetTimeHour ¶
func (gf *BuildInFunctions) GetTimeHour(time time.Time) int
GetTimeHour will get the hour value of time
func (*BuildInFunctions) GetTimeMinute ¶
func (gf *BuildInFunctions) GetTimeMinute(time time.Time) int
GetTimeMinute will get the minute value of time
func (*BuildInFunctions) GetTimeMonth ¶
func (gf *BuildInFunctions) GetTimeMonth(time time.Time) int
GetTimeMonth will get the month value of time
func (*BuildInFunctions) GetTimeSecond ¶
func (gf *BuildInFunctions) GetTimeSecond(time time.Time) int
GetTimeSecond will get the second value of time
func (*BuildInFunctions) GetTimeYear ¶
func (gf *BuildInFunctions) GetTimeYear(time time.Time) int
GetTimeYear will get the year value of time
func (*BuildInFunctions) IsNil ¶
func (gf *BuildInFunctions) IsNil(i interface{}) bool
IsNil Enables nill checking on variables.
func (*BuildInFunctions) IsTimeAfter ¶
func (gf *BuildInFunctions) IsTimeAfter(time, after time.Time) bool
IsTimeAfter will check if the 1st argument is after the 2nd argument.
func (*BuildInFunctions) IsTimeBefore ¶
func (gf *BuildInFunctions) IsTimeBefore(time, before time.Time) bool
IsTimeBefore will check if the 1st argument is before the 2nd argument.
func (*BuildInFunctions) IsZero ¶
func (gf *BuildInFunctions) IsZero(i interface{}) bool
IsZero Enable zero checking
func (*BuildInFunctions) Log ¶
func (gf *BuildInFunctions) Log(text string)
Log extension to log.Print
func (*BuildInFunctions) LogFormat ¶ added in v1.2.1
func (gf *BuildInFunctions) LogFormat(format string, i interface{})
LogFormat extension to log.Printf
func (*BuildInFunctions) MakeTime ¶
func (gf *BuildInFunctions) MakeTime(year, month, day, hour, minute, second int64) time.Time
MakeTime will create a Time struct according to the argument values.
func (*BuildInFunctions) Now ¶
func (gf *BuildInFunctions) Now() time.Time
Now is an extension tn time.Now().
func (*BuildInFunctions) Retract ¶
func (gf *BuildInFunctions) Retract(ruleName string)
Retract will retract a rule from next evaluation cycle.
func (*BuildInFunctions) StringContains ¶ added in v1.2.1
func (gf *BuildInFunctions) StringContains(str, substr string) bool
StringContains extension to strings.Contains
func (*BuildInFunctions) TimeFormat ¶
func (gf *BuildInFunctions) 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 *DataContext WorkingMemory *WorkingMemory Value reflect.Value }
Constant AST node that stores AST graph for Constants
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 *DataContext, 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{} Retracted []string VariableChangeCount uint64 }
DataContext holds all structs instance to be used in rule execution environment.
func NewDataContext ¶
func NewDataContext() *DataContext
NewDataContext will create a new DataContext instance
func (*DataContext) Add ¶
func (ctx *DataContext) Add(key string, obj interface{}) error
Add will add struct instance into rule execution context
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) IsRestracted ¶
func (ctx *DataContext) IsRestracted(key string) bool
IsRestracted 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) Retract ¶
func (ctx *DataContext) Retract(key string)
Retract temporary retract a fact from data context, making it unavailable for evaluation or modification.
type Expression ¶
type Expression struct { AstID string GrlText string DataContext *DataContext 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) 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 *DataContext, 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 *DataContext 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) 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 *DataContext, 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 *DataContext 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) 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 *DataContext, 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 KnowledgeBase ¶
type KnowledgeBase struct { Name string Version string DataContext *DataContext 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 NewKnowledgeBase ¶
func NewKnowledgeBase(name, version string) *KnowledgeBase
NewKnowledgeBase create a new instance of KnowledgeBase
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) 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 *DataContext, memory *WorkingMemory)
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 MethodCall ¶
type MethodCall struct { AstID string GrlText string DataContext *DataContext 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) 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 *DataContext, 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 *DataContext WorkingMemory *WorkingMemory Name string Description string Salience int WhenScope *WhenScope ThenScope *ThenScope Retracted bool }
RuleEntry AST graph node
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 *DataContext, 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 *DataContext 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) 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 *DataContext, 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 *DataContext WorkingMemory *WorkingMemory ThenExpressions []*ThenExpression }
ThenExpressionList AST graph node
func NewThenExpressionList ¶
func NewThenExpressionList() *ThenExpressionList
NewThenExpressionList creates new instance of ThenExpressionList
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 *DataContext, 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 *DataContext WorkingMemory *WorkingMemory ThenExpressionList *ThenExpressionList }
ThenScope AST graph node
func NewThenScope ¶
func NewThenScope() *ThenScope
NewThenScope will create new instance of ThenScope
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 *DataContext, 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 *DataContext WorkingMemory *WorkingMemory Name string Value reflect.Value }
Variable AST graph node
func NewVariable ¶
NewVariable create new instance of Variable
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 *DataContext, 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 *DataContext 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) 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 *DataContext, 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 { ExpressionSnapshotMap map[string]*Expression ExpressionVariableMap map[string][]*Expression ID string }
WorkingMemory handles states of expression evaluation status
func NewWorkingMemory ¶
func NewWorkingMemory() *WorkingMemory
NewWorkingMemory create new instance of WorkingMemory
func (*WorkingMemory) Add ¶
func (wm *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) IndexVar ¶ added in v1.2.2
func (wm *WorkingMemory) IndexVar(varName string) bool
IndexVar will index all expression that contains a speciffic variable name
func (*WorkingMemory) Reset ¶
func (wm *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 (wm *WorkingMemory) ResetAll() bool
ResetAll sets all expression evaluated status to false. Returns true if any expression was reset, false if otherwise