model

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2019 License: Apache-2.0 Imports: 9 Imported by: 2

Documentation

Index

Constants

View Source
const (
	TimeTypeString = "time.Time"
)

Variables

View Source
var (
	ComparisonOperatorGT  = ComparisonOperator(">")
	ComparisonOperatorLT  = ComparisonOperator("<")
	ComparisonOperatorGTE = ComparisonOperator(">=")
	ComparisonOperatorLTE = ComparisonOperator("<=")
	ComparisonOperatorEQ  = ComparisonOperator("==")
	ComparisonOperatorNEQ = ComparisonOperator("!=")
)
View Source
var (
	LogicalOperatorAnd = LogicalOperator(1)
	LogicalOperatorOr  = LogicalOperator(2)
)
View Source
var (
	MathOperatorMul   = MathOperator(1)
	MathOperatorDiv   = MathOperator(2)
	MathOperatorPlus  = MathOperator(3)
	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

type Constant

type Constant struct {
	ConstantValue reflect.Value
	// contains filtered or unexported fields
}

Constant holds a constants, it holds a simple golang value.

func (*Constant) AcceptDecimal

func (cons *Constant) AcceptDecimal(val int64) error

AcceptDecimal prepare this graph with a decimal value.

func (*Constant) Evaluate

func (cons *Constant) Evaluate() (reflect.Value, error)

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

type ConstantHolder interface {
	AcceptConstant(cons *Constant) error
}

ConstantHolder define all graphs that should be able to hold a constants.

type DecimalHolder

type DecimalHolder interface {
	AcceptDecimal(val int64) error
}

DecimalHolder defines all graph that should be able to store a decimal value.

type Evaluator

type Evaluator interface {
	Evaluate() (reflect.Value, error)
}

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 GroolFunctions

type GroolFunctions struct {
	Knowledge *KnowledgeBase
}

GroolFunctions strucr hosts the built-in functions ready to invoke from the rule engine execution.

func (*GroolFunctions) GetTimeDay

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

GetTimeDay will get the day value of time

func (*GroolFunctions) GetTimeHour

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

GetTimeHour will get the hour value of time

func (*GroolFunctions) GetTimeMinute

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

GetTimeMinute will get the minute value of time

func (*GroolFunctions) GetTimeMonth

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

GetTimeMonth will get the month value of time

func (*GroolFunctions) GetTimeSecond

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

GetTimeSecond will get the second value of time

func (*GroolFunctions) GetTimeYear

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

GetTimeYear will get the year value of time

func (*GroolFunctions) IsNil

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

Enables nill checking on variables.

func (*GroolFunctions) IsTimeAfter

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

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

func (*GroolFunctions) IsTimeBefore

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

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

func (*GroolFunctions) IsZero

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

Enable zero checking

func (*GroolFunctions) Log

func (gf *GroolFunctions) Log(text string)

Log extension to log.Print

func (*GroolFunctions) MakeTime

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

func (*GroolFunctions) Now

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

Now is an extension tn time.Now().

func (*GroolFunctions) Retract

func (gf *GroolFunctions) Retract(ruleName string)

Retract will retract a rule from next evaluation cycle.

func (*GroolFunctions) TimeFormat

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

TimeFormat will format a time according to format layout.

type KnowledgeBase

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

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 LogicalOperator

type LogicalOperator int

type MathOperator

type MathOperator int

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

func (prdct *Predicate) Evaluate() (reflect.Value, error)

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

func (entry *RuleEntry) AcceptDecimal(val int64) error

AcceptDecimal will store salience information.

func (*RuleEntry) CanExecute

func (entry *RuleEntry) CanExecute() (bool, error)

CanExecute Test whether this rule entry are eligible for execution by the rule engine with the underlying data.

func (*RuleEntry) Execute

func (entry *RuleEntry) Execute() error

Execute will execute the action part of the rule entry.

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) Execute

func (then *ThenScope) Execute() error

Execute this graph against underlying facts.

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

type VariableHolder interface {
	AcceptVariable(name string) error
}

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

func (when *WhenScope) ExecuteWhen() (bool, error)

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

Jump to

Keyboard shortcuts

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