Documentation ¶
Index ¶
- Constants
- Variables
- type ArgumentHolder
- type AssignExpression
- func (ae *AssignExpression) AcceptFunctionCall(funcCall *FunctionCall) error
- func (ae *AssignExpression) AcceptMethodCall(methodCall *MethodCall) error
- func (ae *AssignExpression) Evaluate() (reflect.Value, error)
- func (ae *AssignExpression) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, ...)
- type AssignExpressions
- type Assignment
- func (assign *Assignment) AcceptExpression(expression *Expression) error
- func (assign *Assignment) AcceptVariable(name string) error
- func (assign *Assignment) Evaluate() (reflect.Value, error)
- func (assign *Assignment) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, ...)
- type ComparisonOperator
- type Constant
- type ConstantHolder
- type DecimalHolder
- type Evaluator
- type Expression
- type ExpressionAtom
- func (exprAtm *ExpressionAtom) AcceptConstant(cons *Constant) error
- func (exprAtm *ExpressionAtom) AcceptExpressionAtom(exprAtom *ExpressionAtom) error
- func (exprAtm *ExpressionAtom) AcceptFunctionCall(funcCall *FunctionCall) error
- func (exprAtm *ExpressionAtom) AcceptMethodCall(methodCall *MethodCall) error
- func (exprAtm *ExpressionAtom) AcceptVariable(name string) error
- func (exprAtm *ExpressionAtom) Evaluate() (reflect.Value, error)
- func (exprAtm *ExpressionAtom) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, ...)
- type ExpressionAtomHolder
- type ExpressionHolder
- type FunctionArgument
- func (funcArg *FunctionArgument) AcceptConstant(cons *Constant) error
- func (funcArg *FunctionArgument) AcceptExpression(expression *Expression) error
- func (funcArg *FunctionArgument) AcceptFunctionCall(funcCall *FunctionCall) error
- func (funcArg *FunctionArgument) AcceptMethodCall(methodCall *MethodCall) error
- func (funcArg *FunctionArgument) AcceptVariable(name string) error
- func (funcArg *FunctionArgument) EvaluateArguments() ([]reflect.Value, error)
- func (funcArg *FunctionArgument) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, ...)
- type FunctionArgumentHolder
- type FunctionCall
- type FunctionCallHolder
- type GraphInitializer
- type GruleFunction
- func (gf *GruleFunction) GetTimeDay(time time.Time) int
- func (gf *GruleFunction) GetTimeHour(time time.Time) int
- func (gf *GruleFunction) GetTimeMinute(time time.Time) int
- func (gf *GruleFunction) GetTimeMonth(time time.Time) int
- func (gf *GruleFunction) GetTimeSecond(time time.Time) int
- func (gf *GruleFunction) GetTimeYear(time time.Time) int
- func (gf *GruleFunction) IsNil(i interface{}) bool
- func (gf *GruleFunction) IsTimeAfter(time, after time.Time) bool
- func (gf *GruleFunction) IsTimeBefore(time, before time.Time) bool
- func (gf *GruleFunction) IsZero(i interface{}) bool
- func (gf *GruleFunction) Log(text string)
- func (gf *GruleFunction) MakeTime(year, month, day, hour, minute, second int64) time.Time
- func (gf *GruleFunction) Now() time.Time
- func (gf *GruleFunction) Retract(ruleName string)
- func (gf *GruleFunction) TimeFormat(time time.Time, layout string) string
- type KnowledgeBase
- type LogicalOperator
- type MathOperator
- type MethodCall
- type MethodCallHolder
- type Predicate
- type RuleEntry
- type ThenScope
- type VariableHolder
- type WhenScope
Constants ¶
const (
// TimeTypeString store the value of Time type.
TimeTypeString = "time.Time"
)
Variables ¶
var ( // ComparisonOperatorGT a comparison operator for symbol > ComparisonOperatorGT = ComparisonOperator(">") // ComparisonOperatorLT a comparison operator for symbol < ComparisonOperatorLT = ComparisonOperator("<") // ComparisonOperatorGTE a comparison operator for symbol >= ComparisonOperatorGTE = ComparisonOperator(">=") // ComparisonOperatorLTE a comparison operator for symbol <= ComparisonOperatorLTE = ComparisonOperator("<=") // ComparisonOperatorEQ a comparison operator for symbol == ComparisonOperatorEQ = ComparisonOperator("==") // ComparisonOperatorNEQ a comparison operator for symbol != ComparisonOperatorNEQ = ComparisonOperator("!=") )
var ( // LogicalOperatorAnd serve as operator value of AND logic LogicalOperatorAnd = LogicalOperator(1) // LogicalOperatorOr serve as operator value of OR logic LogicalOperatorOr = LogicalOperator(2) )
var ( // MathOperatorMul a math operator symbol for Multiplication MathOperatorMul = MathOperator(1) // MathOperatorDiv a math operator symbol for Division MathOperatorDiv = MathOperator(2) // MathOperatorPlus a math operator symbol for Addition MathOperatorPlus = MathOperator(3) // MathOperatorMinus a math operator symbol for Substraction MathOperatorMinus = MathOperator(4) )
Functions ¶
This section is empty.
Types ¶
type ArgumentHolder ¶
type ArgumentHolder struct { Constant *Constant Variable string FunctionCall *FunctionCall MethodCall *MethodCall Expression *Expression // contains filtered or unexported fields }
ArgumentHolder is a struct part of the rule object graph. It holds child graph such as Variable name, Constant data, Function, Expressions, etc.
func (*ArgumentHolder) Evaluate ¶
func (ah *ArgumentHolder) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*ArgumentHolder) Initialize ¶
func (ah *ArgumentHolder) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize this ArgumentHolder instance graph before rule execution start.
type AssignExpression ¶
type AssignExpression struct { Assignment *Assignment FunctionCall *FunctionCall MethodCall *MethodCall // contains filtered or unexported fields }
AssignExpression an expression for assignment, used to assign a variable with some function, constants or method all or simply calling function.
func (*AssignExpression) AcceptFunctionCall ¶
func (ae *AssignExpression) AcceptFunctionCall(funcCall *FunctionCall) error
AcceptFunctionCall prepare this graph for function call.
func (*AssignExpression) AcceptMethodCall ¶
func (ae *AssignExpression) AcceptMethodCall(methodCall *MethodCall) error
AcceptMethodCall prepare this graph for method all
func (*AssignExpression) Evaluate ¶
func (ae *AssignExpression) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*AssignExpression) Initialize ¶
func (ae *AssignExpression) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will initiate this graph with context.
type AssignExpressions ¶
type AssignExpressions struct { ExpressionList []*AssignExpression // contains filtered or unexported fields }
AssignExpressions contains list of assignment expression in the "then" scope.
func (*AssignExpressions) Evaluate ¶
func (ae *AssignExpressions) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*AssignExpressions) Initialize ¶
func (ae *AssignExpressions) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will initialize this graph with context.
type Assignment ¶
type Assignment struct { Variable string Expression *Expression // contains filtered or unexported fields }
Assignment contains a simple assignment, where rule can assign some result from an expression into variable.
func (*Assignment) AcceptExpression ¶
func (assign *Assignment) AcceptExpression(expression *Expression) error
AcceptExpression initialize this assignment with some expression
func (*Assignment) AcceptVariable ¶
func (assign *Assignment) AcceptVariable(name string) error
AcceptVariable initialize this assignment with a variable name
func (*Assignment) Evaluate ¶
func (assign *Assignment) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*Assignment) Initialize ¶
func (assign *Assignment) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will prepare this graph with contexts.
type ComparisonOperator ¶
type ComparisonOperator string
ComparisonOperator operator symbol for mathematical comparison
type Constant ¶
Constant holds a constants, it holds a simple golang value.
func (*Constant) AcceptDecimal ¶
AcceptDecimal prepare this graph with a decimal value.
func (*Constant) Evaluate ¶
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*Constant) Initialize ¶
func (cons *Constant) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will initialize this graph with context
type ConstantHolder ¶
ConstantHolder define all graphs that should be able to hold a constants.
type DecimalHolder ¶
DecimalHolder defines all graph that should be able to store a decimal value.
type Evaluator ¶
Evaluator define the interface for all element that able to evaluate rule element against underlying datacontext within the rule engine execution.
type Expression ¶
type Expression struct { LeftExpression *Expression RightExpression *Expression LogicalOperator LogicalOperator Predicate *Predicate // contains filtered or unexported fields }
Expression hold the object graph as defined in the rule semantic. an expression could hold a predicate or pair of logical operated expression.
func (*Expression) AcceptExpression ¶
func (expr *Expression) AcceptExpression(expression *Expression) error
AcceptExpression will store expression as they are defined in the rule script, into this object graph.
func (*Expression) Evaluate ¶
func (expr *Expression) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*Expression) Initialize ¶
func (expr *Expression) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize this object graph with necessary context prior engine execution.
type ExpressionAtom ¶
type ExpressionAtom struct { Text string ExpressionAtomLeft *ExpressionAtom ExpressionAtomRight *ExpressionAtom MathOperator MathOperator Variable string Constant *Constant FunctionCall *FunctionCall MethodCall *MethodCall // contains filtered or unexported fields }
ExpressionAtom holds an expression atom graph. it can form a mathematical expression, a simple contants, function all, method call.
func (*ExpressionAtom) AcceptConstant ¶
func (exprAtm *ExpressionAtom) AcceptConstant(cons *Constant) error
AcceptConstant will prepare this expression as a constant.
func (*ExpressionAtom) AcceptExpressionAtom ¶
func (exprAtm *ExpressionAtom) AcceptExpressionAtom(exprAtom *ExpressionAtom) error
AcceptExpressionAtom will prepare this graph an expression atom. The first invocation to this function will set the left hand value, the second will set the right hand to be evaluated with math operator.
func (*ExpressionAtom) AcceptFunctionCall ¶
func (exprAtm *ExpressionAtom) AcceptFunctionCall(funcCall *FunctionCall) error
AcceptFunctionCall will prepare this expression atom as a function call
func (*ExpressionAtom) AcceptMethodCall ¶
func (exprAtm *ExpressionAtom) AcceptMethodCall(methodCall *MethodCall) error
AcceptMethodCall will prepare this expression atom as a method call.
func (*ExpressionAtom) AcceptVariable ¶
func (exprAtm *ExpressionAtom) AcceptVariable(name string) error
AcceptVariable will prepare this expression atom as a variable.
func (*ExpressionAtom) Evaluate ¶
func (exprAtm *ExpressionAtom) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*ExpressionAtom) Initialize ¶
func (exprAtm *ExpressionAtom) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will prepare this graph with contexts
type ExpressionAtomHolder ¶
type ExpressionAtomHolder interface {
AcceptExpressionAtom(exprAtom *ExpressionAtom) error
}
ExpressionAtomHolder defines all graph that should be able to store an expression atom.
type ExpressionHolder ¶
type ExpressionHolder interface {
AcceptExpression(expression *Expression) error
}
ExpressionHolder defines a graph that should be able to hold an expression.
type FunctionArgument ¶
type FunctionArgument struct { Arguments []*ArgumentHolder // contains filtered or unexported fields }
FunctionArgument stores set of argument within a function call.
func (*FunctionArgument) AcceptConstant ¶
func (funcArg *FunctionArgument) AcceptConstant(cons *Constant) error
AcceptConstant add a constant into function argument.
func (*FunctionArgument) AcceptExpression ¶
func (funcArg *FunctionArgument) AcceptExpression(expression *Expression) error
AcceptExpression add an expression into function arguments.
func (*FunctionArgument) AcceptFunctionCall ¶
func (funcArg *FunctionArgument) AcceptFunctionCall(funcCall *FunctionCall) error
AcceptFunctionCall add a function call into function arguments.
func (*FunctionArgument) AcceptMethodCall ¶
func (funcArg *FunctionArgument) AcceptMethodCall(methodCall *MethodCall) error
AcceptMethodCall add a method call into function argument.
func (*FunctionArgument) AcceptVariable ¶
func (funcArg *FunctionArgument) AcceptVariable(name string) error
AcceptVariable add a variable into function argument.
func (*FunctionArgument) EvaluateArguments ¶
func (funcArg *FunctionArgument) EvaluateArguments() ([]reflect.Value, error)
EvaluateArguments the object graph against underlined context or execute evaluation in the sub graph.
func (*FunctionArgument) Initialize ¶
func (funcArg *FunctionArgument) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will prepare this set of arguments with contexts.
type FunctionArgumentHolder ¶
type FunctionArgumentHolder interface {
AcceptFunctionArgument(funcArg *FunctionArgument) error
}
FunctionArgumentHolder define a graph that should store function argument.
type FunctionCall ¶
type FunctionCall struct { FunctionName string FunctionArguments *FunctionArgument // contains filtered or unexported fields }
FunctionCall defines function structure which defines its name and arguments.
func (*FunctionCall) AcceptFunctionArgument ¶
func (funcCall *FunctionCall) AcceptFunctionArgument(funcArg *FunctionArgument) error
AcceptFunctionArgument configure this function call with sets of function arguments.
func (*FunctionCall) Evaluate ¶
func (funcCall *FunctionCall) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*FunctionCall) Initialize ¶
func (funcCall *FunctionCall) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will prepare this graph with context
type FunctionCallHolder ¶
type FunctionCallHolder interface {
AcceptFunctionCall(funcCall *FunctionCall) error
}
FunctionCallHolder defines a graph that should be able to store function call.
type GraphInitializer ¶
type GraphInitializer interface {
Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
}
GraphInitializer defines all graph that can be initalized with context.
type GruleFunction ¶
type GruleFunction struct {
Knowledge *KnowledgeBase
}
GruleFunction strucr hosts the built-in functions ready to invoke from the rule engine execution.
func (*GruleFunction) GetTimeDay ¶
func (gf *GruleFunction) GetTimeDay(time time.Time) int
GetTimeDay will get the day value of time
func (*GruleFunction) GetTimeHour ¶
func (gf *GruleFunction) GetTimeHour(time time.Time) int
GetTimeHour will get the hour value of time
func (*GruleFunction) GetTimeMinute ¶
func (gf *GruleFunction) GetTimeMinute(time time.Time) int
GetTimeMinute will get the minute value of time
func (*GruleFunction) GetTimeMonth ¶
func (gf *GruleFunction) GetTimeMonth(time time.Time) int
GetTimeMonth will get the month value of time
func (*GruleFunction) GetTimeSecond ¶
func (gf *GruleFunction) GetTimeSecond(time time.Time) int
GetTimeSecond will get the second value of time
func (*GruleFunction) GetTimeYear ¶
func (gf *GruleFunction) GetTimeYear(time time.Time) int
GetTimeYear will get the year value of time
func (*GruleFunction) IsNil ¶
func (gf *GruleFunction) IsNil(i interface{}) bool
IsNil Enables nill checking on variables.
func (*GruleFunction) IsTimeAfter ¶
func (gf *GruleFunction) IsTimeAfter(time, after time.Time) bool
IsTimeAfter will check if the 1st argument is after the 2nd argument.
func (*GruleFunction) IsTimeBefore ¶
func (gf *GruleFunction) IsTimeBefore(time, before time.Time) bool
IsTimeBefore will check if the 1st argument is before the 2nd argument.
func (*GruleFunction) IsZero ¶
func (gf *GruleFunction) IsZero(i interface{}) bool
IsZero Enable zero checking
func (*GruleFunction) MakeTime ¶
func (gf *GruleFunction) MakeTime(year, month, day, hour, minute, second int64) time.Time
MakeTime will create a Time struct according to the argument values.
func (*GruleFunction) Now ¶
func (gf *GruleFunction) Now() time.Time
Now is an extension tn time.Now().
func (*GruleFunction) Retract ¶
func (gf *GruleFunction) Retract(ruleName string)
Retract will retract a rule from next evaluation cycle.
func (*GruleFunction) TimeFormat ¶
func (gf *GruleFunction) TimeFormat(time time.Time, layout string) string
TimeFormat will format a time according to format layout.
type KnowledgeBase ¶
KnowledgeBase hold list of rule entry to be evaluated in each cycle.
func NewKnowledgeBase ¶
func NewKnowledgeBase() *KnowledgeBase
NewKnowledgeBase create new instance of knowledge
func (*KnowledgeBase) Reset ¶
func (k *KnowledgeBase) Reset()
Reset will reset the retract status of all rule entries.
func (*KnowledgeBase) Retract ¶
func (k *KnowledgeBase) Retract(ruleEntryName string)
Retract retract a rule entry from next evaluation cycle.
type MathOperator ¶
type MathOperator int
MathOperator define a constants type of mathematical operator.
type MethodCall ¶
type MethodCall struct { MethodName string MethodArguments *FunctionArgument // contains filtered or unexported fields }
MethodCall defines a graph struct that form a method call. It holds the method name to call and the arguments.
func (*MethodCall) AcceptFunctionArgument ¶
func (methCall *MethodCall) AcceptFunctionArgument(funcArg *FunctionArgument) error
AcceptFunctionArgument will prepare this graph with the function arguments.
func (*MethodCall) Evaluate ¶
func (methCall *MethodCall) Evaluate() (reflect.Value, error)
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*MethodCall) Initialize ¶
func (methCall *MethodCall) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will initialize this graph with context.
type MethodCallHolder ¶
type MethodCallHolder interface {
AcceptMethodCall(methodCall *MethodCall) error
}
MethodCallHolder defins all graph that should store method calls.
type Predicate ¶
type Predicate struct { ExpressionAtomLeft *ExpressionAtom ExpressionAtomRight *ExpressionAtom ComparisonOperator ComparisonOperator // contains filtered or unexported fields }
Predicate holds the left and right Expression Atom graph. And apply comparisson operator from both expression atom result.
func (*Predicate) AcceptExpressionAtom ¶
func (prdct *Predicate) AcceptExpressionAtom(exprAtom *ExpressionAtom) error
AcceptExpressionAtom configure this graph with left and right side of expression atom. The first call to this function will set the left hand side and the second call will set the right.
func (*Predicate) Evaluate ¶
Evaluate the object graph against underlined context or execute evaluation in the sub graph.
func (*Predicate) Initialize ¶
func (prdct *Predicate) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize initialize this graph with context
type RuleEntry ¶
type RuleEntry struct { Salience int64 RuleName string RuleDescription string WhenScope *WhenScope ThenScope *ThenScope Retracted bool // contains filtered or unexported fields }
RuleEntry represent the language graph of a single rule entry.
func (*RuleEntry) AcceptDecimal ¶
AcceptDecimal will store salience information.
func (*RuleEntry) CanExecute ¶
CanExecute Test whether this rule entry are eligible for execution by the rule engine with the underlying data.
func (*RuleEntry) Initialize ¶
func (entry *RuleEntry) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will init this graph prior execution.
type ThenScope ¶
type ThenScope struct { AssignExpressions *AssignExpressions // contains filtered or unexported fields }
ThenScope holds the language graph for then expressions.
func (*ThenScope) Initialize ¶
func (then *ThenScope) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize will init this object graph prior execution
type VariableHolder ¶
VariableHolder should be implemented by any object graph that would hold a variable name.
type WhenScope ¶
type WhenScope struct { Expression *Expression // contains filtered or unexported fields }
WhenScope struct hold the syntax graph for "When" expression.
func (*WhenScope) AcceptExpression ¶
func (when *WhenScope) AcceptExpression(expression *Expression) error
AcceptExpression will accept any child expression underneath this Scope.
func (*WhenScope) ExecuteWhen ¶
ExecuteWhen will evaluate all underneath expression.
func (*WhenScope) Initialize ¶
func (when *WhenScope) Initialize(knowledgeContext *context.KnowledgeContext, ruleCtx *context.RuleContext, dataCtx *context.DataContext)
Initialize initialize the object graph prior execution
Source Files ¶
- ArgumentHolder.go
- AssignExpression.go
- AssignExpressions.go
- Assignment.go
- ComparisonOperator.go
- Constant.go
- ConstantHolder.go
- DecimalHolder.go
- Evaluator.go
- Expression.go
- ExpressionAtom.go
- ExpressionAtomHolder.go
- ExpressionHolder.go
- FunctionArgument.go
- FunctionArgumentHolder.go
- FunctionCall.go
- FunctionCallHolder.go
- GraphInitializer.go
- GruleFunctions.go
- Knowledge.go
- LogicalOperator.go
- MathOperator.go
- MethodCall.go
- MethodCallHolder.go
- Predicate.go
- RuleEntry.go
- ThenScope.go
- VariableHolder.go
- WhenScope.go