grule_engine

package
v0.0.1-beta.17 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Execute

func Execute(kl *ast.KnowledgeLibrary, dataCtx ast.IDataContext, name, version string) (*ast.KnowledgeBase, error)

Execute 执行规则

dataCtx 可以使用 ast.NewDataContext() 创建

func NewKnowledgeLibrary

func NewKnowledgeLibrary() *ast.KnowledgeLibrary

NewKnowledgeLibrary 创建 KnowledgeLibrary

func RegisterRule

func RegisterRule(kl *ast.KnowledgeLibrary, jsonBytes []byte, name, version string) error

RegisterRule 注册规则

func RemoveRuleEntry

func RemoveRuleEntry(kl *ast.KnowledgeLibrary, ruleName, name string, version string)

RemoveRuleEntry 从规则引擎中移除规则

Types

type ArithmeticOperator

type ArithmeticOperator struct {
	// obj: set 的目标属性
	Field string      `json:"obj,omitempty"`
	Value any         `json:"const,omitempty"`
	BOR   []*Operator `json:"bor,omitempty"`
	BAND  []*Operator `json:"band,omitempty"`
	PLUS  []*Operator `json:"plus,omitempty"`
	MINUS []*Operator `json:"minus,omitempty"`
	DIV   []*Operator `json:"div,omitempty"`
	MUL   []*Operator `json:"mul,omitempty"`
	MOD   []*Operator `json:"mod,omitempty"`
}

ArithmeticOperator 算数运算符

type LogicalOperator

type LogicalOperator struct {
	EQ  []*Operator `json:"eq,omitempty"`
	NOT []*Operator `json:"not,omitempty"`
	GT  []*Operator `json:"gt,omitempty"`
	GTE []*Operator `json:"gte,omitempty"`
	LT  []*Operator `json:"lt,omitempty"`
	LTE []*Operator `json:"lte,omitempty"`
}

LogicalOperator 逻辑运算符

type Operator

type Operator struct {
	Obj   string `json:"obj,omitempty"`
	Const any    `json:"const,omitempty"`
}

func NewOperatorsConst

func NewOperatorsConst(c any) *Operator

NewOperatorsConst 创建常量

func NewOperatorsObj

func NewOperatorsObj(s string) *Operator

NewOperatorsObj 创建对象属性

type Then

type Then struct {
	// contains filtered or unexported fields
}

Then 针对 pkg.GruleJSON 中的 then 数据结构

func NewThen

func NewThen() *Then

NewThen 创建 Then

func (*Then) AddCall

func (build *Then) AddCall(methodName string, parameter ...*Operator) *Then

AddCall 添加要调用的方法

根据情况在最后添加 Retract("规则名")

func (*Then) AddSetBand

func (build *Then) AddSetBand(field string, lo1, lo2 *Operator) *Then

AddSetBand 创建 & 运算

func (*Then) AddSetBor

func (build *Then) AddSetBor(field string, lo1, lo2 *Operator) *Then

AddSetBor 创建 | 运算

func (*Then) AddSetDiv

func (build *Then) AddSetDiv(field string, lo1, lo2 *Operator) *Then

AddSetDiv 创建 / 运算

func (*Then) AddSetMinus

func (build *Then) AddSetMinus(field string, lo1, lo2 *Operator) *Then

AddSetMinus 创建 - 运算

func (*Then) AddSetMod

func (build *Then) AddSetMod(field string, lo1, lo2 *Operator) *Then

AddSetMod 创建 % 运算

func (*Then) AddSetMul

func (build *Then) AddSetMul(field string, lo1, lo2 *Operator) *Then

AddSetMul 创建 * 运算

func (*Then) AddSetPlus

func (build *Then) AddSetPlus(field string, lo1, lo2 *Operator) *Then

AddSetPlus 创建 + 运算

func (*Then) AddSetValueConst

func (build *Then) AddSetValueConst(field string, lo1 any) *Then

AddSetValueConst 设置常量值

func (*Then) AddSetValueObj

func (build *Then) AddSetValueObj(field string, lo1 string) *Then

AddSetValueObj 设置对象的某个属性

func (*Then) Build

func (build *Then) Build() []any

type ThenCall

type ThenCall struct {
	Call []any `json:"call,omitempty"`
}

type ThenSet

type ThenSet struct {
	Set []*ArithmeticOperator `json:"set,omitempty"`
}

type Tx

type Tx struct {
	Test  bool
	Test2 string
}

type When

type When struct {
	And []*LogicalOperator `json:"and,omitempty"`
	Or  []*LogicalOperator `json:"or,omitempty"`
}

When 针对 pkg.GruleJSON 中的 when 数据结构

func NewWhenAnd

func NewWhenAnd() *When

NewWhenAnd 针对 when and

func NewWhenOr

func NewWhenOr() *When

NewWhenOr 针对 when or

func (*When) AddEq

func (build *When) AddEq(lo1, lo2 *Operator) *When

AddEq 添加 when 中的 Eq(==) 逻辑运算

func (*When) AddGt

func (build *When) AddGt(lo1, lo2 *Operator) *When

AddGt 添加 when 中的 Gt(>) 逻辑运算

func (*When) AddGte

func (build *When) AddGte(lo1, lo2 *Operator) *When

AddGte 添加 when 中的 Gte(>=) 逻辑运算

func (*When) AddLogicalOperator

func (build *When) AddLogicalOperator(lo *LogicalOperator) *When

AddLogicalOperator 直接将 LogicalOperator 添加到 When

func (*When) AddLt

func (build *When) AddLt(lo1, lo2 *Operator) *When

AddLt 添加 when 中的 Lt(<) 逻辑运算

func (*When) AddLte

func (build *When) AddLte(lo1, lo2 *Operator) *When

AddLte 添加 when 中的 Lte(<=) 逻辑运算

func (*When) AddNot

func (build *When) AddNot(lo1, lo2 *Operator) *When

AddNot 添加 when 中的 Not(!=) 逻辑运算

Jump to

Keyboard shortcuts

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