Documentation ¶
Index ¶
- Constants
- func ApplyExecuteOptions(rv typedef.RuleVisitor, dc typedef.DataCtx, opts ...ExecuteOption)
- func ApplyOptions(c *Configuration, opts ...Option)
- func DataContext(ctx context.Context, json string) (dc typedef.DataCtx, err error)
- func DecodeFeatureHash(featureHash string) (featureName string, builtinParamHash string)
- func FeatureFetcherFactory() typedef.FeatureFetcher
- func GenBuiltinParamHash(builtinParam typedef.MetaType) string
- func Initialize(cfg *Configuration, opts ...Option)
- func JudgeCondition(ctx context.Context, condition string, opts ...ExecuteOption) (pass bool, err error)
- func JudgeConditionWithFactMeta(ctx context.Context, condition, factMeta string, opts ...ExecuteOption) (pass bool, err error)
- func NewDefaultFeatureParamWithBuiltinParam(featureName string, builtinParam typedef.MetaType) typedef.FeatureParam
- func NewDefaultFeatureParamWithNoBuiltinParam(featureName string) typedef.FeatureParam
- func WalkAim(aimExpr string, dc typedef.DataCtx, opts ...ExecuteOption) (aim typedef.Aim, err error)
- func WalkAimTree(aimTree antlr.ParseTree, dc typedef.DataCtx, opts ...ExecuteOption) (aim typedef.Aim)
- type ActionAim
- type Builder
- type Condition
- type ConditionGroupBuilder
- type Configuration
- type Const
- type ExecuteMode
- type ExecuteOption
- type Expr
- func NewConstExpr(c *Const) *Expr
- func NewConstListExpr(cs []*Const) *Expr
- func NewFeatureExpr(ft *FeatureExpr) *Expr
- func NewFuncExpr(f *FuncExpr) *Expr
- func NewListExpr(list []*Expr) *Expr
- func NewMapExpr(m map[string]*Expr) *Expr
- func NewMathExpr(mt *MathExpr) *Expr
- func NewVarExpr(v *VarExpr) *Expr
- type ExprType
- type FeatureExpr
- type FuncExpr
- type ListParamFnPair
- type MapParamFnPair
- type MathExpr
- type NoParamFnPair
- type NoPriorityRule
- func (n *NoPriorityRule) AimFeatParams() []typedef.FeatureParam
- func (n *NoPriorityRule) AimPTree() antlr.ParseTree
- func (n *NoPriorityRule) Compare(other typedef.Comparable) int
- func (n *NoPriorityRule) CondFeatParams() []typedef.FeatureParam
- func (n *NoPriorityRule) ConditionPTree() antlr.ParseTree
- func (n *NoPriorityRule) Identifier() string
- type Not
- type Option
- func WithCustomListParamFuncs(funcPairs ...ListParamFnPair) Option
- func WithCustomMapParamFuncs(funcPairs ...MapParamFnPair) Option
- func WithCustomNoParamFuncs(funcPairs ...NoParamFnPair) Option
- func WithDefFeatFetcherFactory() Option
- func WithDefFeatVisitCache() Option
- func WithDefFeatureFetchPool() Option
- func WithDefGranularity() Option
- func WithDefMaxParallels() Option
- func WithDefRuleComputePool() Option
- func WithDefTreeCache() Option
- func WithFeatureFetcherFactory(factory func() typedef.FeatureFetcher) Option
- type PriorityRule
- type RuleResult
- type RuleTarget
- type RuleTree
- type TreeCache
- type VarExpr
Constants ¶
const ( OpLogicAnd = "&&" OpLogicOr = "||" OpLogicNot = "!" )
const ( ExprTypeCondition = iota ExprTypeAim )
Variables ¶
This section is empty.
Functions ¶
func ApplyExecuteOptions ¶ added in v1.0.5
func ApplyExecuteOptions(rv typedef.RuleVisitor, dc typedef.DataCtx, opts ...ExecuteOption)
func ApplyOptions ¶ added in v1.0.5
func ApplyOptions(c *Configuration, opts ...Option)
func DataContext ¶
DataContext will create a new DataContext by fact meta json.
func DecodeFeatureHash ¶ added in v1.0.4
func FeatureFetcherFactory ¶
func FeatureFetcherFactory() typedef.FeatureFetcher
FeatureFetcherFactory provides the ability to create a feature fetcher.
func GenBuiltinParamHash ¶ added in v1.0.4
func Initialize ¶
func Initialize(cfg *Configuration, opts ...Option)
Initialize arishem, this func should be called only once in your init function.
func JudgeCondition ¶
func JudgeCondition(ctx context.Context, condition string, opts ...ExecuteOption) (pass bool, err error)
JudgeCondition will judge the condition string, pass will be set true if condition passed.
func JudgeConditionWithFactMeta ¶
func JudgeConditionWithFactMeta(ctx context.Context, condition, factMeta string, opts ...ExecuteOption) (pass bool, err error)
JudgeConditionWithFactMeta will judge the condition string with fact meta, pass will be set true if condition passed.
func NewDefaultFeatureParamWithBuiltinParam ¶ added in v1.0.4
func NewDefaultFeatureParamWithBuiltinParam(featureName string, builtinParam typedef.MetaType) typedef.FeatureParam
func NewDefaultFeatureParamWithNoBuiltinParam ¶ added in v1.0.4
func NewDefaultFeatureParamWithNoBuiltinParam(featureName string) typedef.FeatureParam
func WalkAim ¶ added in v1.0.10
func WalkAim(aimExpr string, dc typedef.DataCtx, opts ...ExecuteOption) (aim typedef.Aim, err error)
WalkAim will try to parse the aimExpr into the antlr parse tree and visit it to get the result, err will not be null when parse aim expression failed.
func WalkAimTree ¶ added in v1.0.10
func WalkAimTree(aimTree antlr.ParseTree, dc typedef.DataCtx, opts ...ExecuteOption) (aim typedef.Aim)
WalkAimTree will visit the aimTree to get the result
Types ¶
type ActionAim ¶
type ActionAim struct { ActionName string `json:"ActionName"` ParamMap map[string]*Expr `json:"ParamMap,omitempty"` ParamList []*Expr `json:"ParamList,omitempty"` // contains filtered or unexported fields }
func NewParamListAction ¶
NewParamListAction create a new action aim with param list.
func NewParamMapAction ¶
NewParamMapAction create a new action aim with param map.
func (*ActionAim) AddKeyParam ¶
type Condition ¶
type Condition struct { Operator string `json:"Operator"` Lhs *Expr `json:"Lhs,omitempty"` Rhs *Expr `json:"Rhs,omitempty"` }
func NewCondition ¶
type ConditionGroupBuilder ¶
type ConditionGroupBuilder struct { OpLogic string `json:"OpLogic"` ConditionGroups []*ConditionGroupBuilder `json:"ConditionGroups,omitempty"` Conditions []*Condition `json:"Conditions,omitempty"` // contains filtered or unexported fields }
func NewCondGroupsCondGroup ¶
func NewCondGroupsCondGroup(opLogic string) *ConditionGroupBuilder
NewCondGroupsCondGroup create a new condition group with condition groups.
func NewConditionsCondGroup ¶
func NewConditionsCondGroup(opLogic string) *ConditionGroupBuilder
NewConditionsCondGroup create a new condition group with conditions.
func (*ConditionGroupBuilder) AddConditionGroups ¶
func (c *ConditionGroupBuilder) AddConditionGroups(condGroups ...*ConditionGroupBuilder)
func (*ConditionGroupBuilder) AddConditions ¶
func (c *ConditionGroupBuilder) AddConditions(cond ...*Condition)
func (*ConditionGroupBuilder) Build ¶
func (c *ConditionGroupBuilder) Build() (expr string, err error)
type Configuration ¶ added in v1.0.5
type Configuration struct { Granularity func(int, ExecuteMode) int // prefetch feature Prefetch bool TCache TreeCache // max parallel computation MaxParallel int RuleComputePool typedef.ConcurrentPool FeatureFetchPool typedef.ConcurrentPool FeatFetcherFactory func() typedef.FeatureFetcher FeatVisitCache typedef.SharedVisitCache }
func DefaultConfiguration ¶
func DefaultConfiguration() *Configuration
type Const ¶
type Const struct { BoolConst *bool `json:"BoolConst,omitempty"` NumConst *float64 `json:"NumConst,omitempty"` StrConst *string `json:"StrConst,omitempty"` }
func NewBoolConst ¶
func NewNumConst ¶
func NewStrConst ¶
type ExecuteMode ¶ added in v1.0.5
type ExecuteMode int32
const ( ExecuteModePriority ExecuteMode = iota ExecuteModeNoPriority )
type ExecuteOption ¶ added in v1.0.5
type ExecuteOption func(rv typedef.RuleVisitor, dc typedef.DataCtx)
func WithFeatureFetchObserver ¶
func WithFeatureFetchObserver(obs ...typedef.FeatureFetchObserver) ExecuteOption
WithFeatureFetchObserver can add feature fetch observers to feature fetcher.
func WithVisitObserver ¶
func WithVisitObserver(obs ...typedef.VisitObserver) ExecuteOption
WithVisitObserver can add visit observers to rule visitor.
type Expr ¶
type Expr struct { ListExpr []*Expr `json:"ListExpr,omitempty"` MapExpr map[string]*Expr `json:"MapExpr,omitempty"` Const *Const `json:"Const,omitempty"` ConstList []*Const `json:"ConstList,omitempty"` MathExpr *MathExpr `json:"MathExpr,omitempty"` FuncExpr *FuncExpr `json:"FuncExpr,omitempty"` VarExpr *VarExpr `json:"VarExpr,omitempty"` FeatureExpr *FeatureExpr `json:"FeatureExpr,omitempty"` }
func NewConstExpr ¶
func NewConstListExpr ¶
func NewFeatureExpr ¶
func NewFeatureExpr(ft *FeatureExpr) *Expr
func NewFuncExpr ¶
func NewListExpr ¶
func NewMapExpr ¶
func NewMathExpr ¶
func NewVarExpr ¶
type FeatureExpr ¶
type FeatureExpr struct { FeaturePath string `json:"FeaturePath"` BuiltinParam map[string]*Expr `json:"BuiltinParam,omitempty"` }
func NewFeature ¶
func NewFeature(featurePath string) *FeatureExpr
func NewFeatureWithBuiltinParam ¶
func NewFeatureWithBuiltinParam(featurePath string, param map[string]*Expr) *FeatureExpr
type FuncExpr ¶
type FuncExpr struct { FuncName string `json:"FuncName"` ParamMap map[string]*Expr `json:"ParamMap,omitempty"` ParamList []*Expr `json:"ParamList,omitempty"` }
func NewParamListFunc ¶
type ListParamFnPair ¶ added in v1.0.2
type MapParamFnPair ¶ added in v1.0.2
type MathExpr ¶
type MathExpr struct { OpMath string `json:"OpMath"` Lhs *Expr `json:"Lhs,omitempty"` Rhs *Expr `json:"Rhs,omitempty"` ParamList []*Expr `json:"ParamList,omitempty"` }
func NewParamListMath ¶
type NoParamFnPair ¶ added in v1.0.2
type NoPriorityRule ¶
type NoPriorityRule struct {
// contains filtered or unexported fields
}
func (*NoPriorityRule) AimFeatParams ¶
func (n *NoPriorityRule) AimFeatParams() []typedef.FeatureParam
func (*NoPriorityRule) AimPTree ¶
func (n *NoPriorityRule) AimPTree() antlr.ParseTree
func (*NoPriorityRule) Compare ¶
func (n *NoPriorityRule) Compare(other typedef.Comparable) int
func (*NoPriorityRule) CondFeatParams ¶
func (n *NoPriorityRule) CondFeatParams() []typedef.FeatureParam
func (*NoPriorityRule) ConditionPTree ¶
func (n *NoPriorityRule) ConditionPTree() antlr.ParseTree
func (*NoPriorityRule) Identifier ¶
func (n *NoPriorityRule) Identifier() string
type Option ¶ added in v1.0.5
type Option func(cfg *Configuration)
func WithCustomListParamFuncs ¶ added in v1.0.2
func WithCustomListParamFuncs(funcPairs ...ListParamFnPair) Option
func WithCustomMapParamFuncs ¶ added in v1.0.2
func WithCustomMapParamFuncs(funcPairs ...MapParamFnPair) Option
func WithCustomNoParamFuncs ¶ added in v1.0.2
func WithCustomNoParamFuncs(funcPairs ...NoParamFnPair) Option
func WithDefFeatFetcherFactory ¶
func WithDefFeatFetcherFactory() Option
func WithDefFeatVisitCache ¶
func WithDefFeatVisitCache() Option
func WithDefFeatureFetchPool ¶
func WithDefFeatureFetchPool() Option
func WithDefGranularity ¶
func WithDefGranularity() Option
func WithDefMaxParallels ¶
func WithDefMaxParallels() Option
func WithDefRuleComputePool ¶
func WithDefRuleComputePool() Option
func WithDefTreeCache ¶
func WithDefTreeCache() Option
func WithFeatureFetcherFactory ¶
func WithFeatureFetcherFactory(factory func() typedef.FeatureFetcher) Option
type PriorityRule ¶
type PriorityRule struct { *NoPriorityRule // contains filtered or unexported fields }
func (*PriorityRule) Compare ¶
func (p *PriorityRule) Compare(other typedef.Comparable) int
type RuleResult ¶ added in v1.0.6
type RuleResult interface { typedef.VisitTarget Passed() bool Aim() typedef.Aim }
func ExecuteRules ¶
func ExecuteRules(rules []RuleTarget, dc typedef.DataCtx, opts ...ExecuteOption) (rrs []RuleResult)
ExecuteRules will execute all rule target, and returns rule results which passed by condition.
func ExecuteSingleRule ¶
func ExecuteSingleRule(rule RuleTarget, dc typedef.DataCtx, opts ...ExecuteOption) (rr RuleResult)
ExecuteSingleRule will execute a single rule, if condition pass, rr.Aim() will not be null.
type RuleTarget ¶ added in v1.0.6
type RuleTarget interface { typedef.Comparable typedef.VisitTarget ConditionPTree() antlr.ParseTree AimPTree() antlr.ParseTree CondFeatParams() []typedef.FeatureParam AimFeatParams() []typedef.FeatureParam }
func NewNoPriorityRule ¶
func NewNoPriorityRule(name string, cdtExpr, aimExpr string) (npr RuleTarget, err error)
NewNoPriorityRule will create a new rule with no priority.
func NewPriorityRule ¶
func NewPriorityRule(name string, priority int, cdtExpr, aimExpr string) (pr RuleTarget, err error)
NewPriorityRule will create a new rule with priority.
type RuleTree ¶ added in v1.0.5
type RuleTree struct { Tree antlr.ParseTree FeatParams []typedef.FeatureParam }
func ParseAim ¶ added in v1.0.10
ParseAim will parse an aim string and return the rule tree with feature parameter pre-parsed.
func ParseCondition ¶
ParseCondition will parse a condition string and return the rule tree with feature parameter pre-parsed.