Documentation ¶
Index ¶
- type Action
- type ActionDef
- type Case
- type DefaultAction
- type DefaultKnowledgeBase
- func (kBase *DefaultKnowledgeBase) GetFact(key string) interface{}
- func (kBase *DefaultKnowledgeBase) GetFacts() map[string]interface{}
- func (kBase *DefaultKnowledgeBase) InsertFact(key string, value interface{})
- func (kBase *DefaultKnowledgeBase) Reset()
- func (kBase *DefaultKnowledgeBase) SetDefaultValues(parameters map[string]interface{})
- func (kBase *DefaultKnowledgeBase) SetFacts(facts map[string]interface{})
- func (kBase *DefaultKnowledgeBase) String() string
- type DefaultRule
- type DefaultRuleBase
- func (rBase *DefaultRuleBase) ExecuteAll(k KnowledgeBase) []Action
- func (rBase *DefaultRuleBase) ExecuteByID(ruleID int64, k KnowledgeBase) ([]Action, error)
- func (rBase *DefaultRuleBase) ExecuteRules(ruleIDs []int64, k KnowledgeBase) []Action
- func (rBase *DefaultRuleBase) GetRules() map[int64]Rule
- func (rBase *DefaultRuleBase) InsertRule(rule Rule)
- func (rBase *DefaultRuleBase) InsertRules(rules []Rule)
- func (rBase *DefaultRuleBase) RemoveRule(id int64)
- func (rBase *DefaultRuleBase) Reset()
- type Expression
- func (exp Expression) Evaluate(k KnowledgeBase) (interface{}, error)
- func (exp Expression) EvaluateAsBool(k KnowledgeBase) (bool, error)
- func (exp Expression) EvaluateAsString(k KnowledgeBase) (string, error)
- func (exp Expression) MarshalJSON() ([]byte, error)
- func (exp *Expression) UnmarshalJSON(data []byte) error
- type KnowledgeBase
- type Rule
- type RuleBase
- type RuleEngine
- func (engine *RuleEngine) ExecuteAllRules()
- func (engine *RuleEngine) ExecuteRule(id int64) error
- func (engine *RuleEngine) ExecuteRules(ids []int64)
- func (engine *RuleEngine) GetKnowledgeBase() KnowledgeBase
- func (engine *RuleEngine) GetResults() []Action
- func (engine *RuleEngine) GetRulesBase() RuleBase
- func (engine *RuleEngine) InsertKnowledge(key string, value interface{})
- func (engine *RuleEngine) InsertRule(r Rule)
- func (engine *RuleEngine) InsertRules(rules []Rule)
- func (engine *RuleEngine) RemoveRule(id int64)
- func (engine *RuleEngine) Reset()
- func (engine *RuleEngine) SetKnowledge(k KnowledgeBase)
- func (engine *RuleEngine) SetRules(r RuleBase)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action interface { GetName() string GetParameters() map[string]interface{} GetMetaData() map[string]interface{} GetEnabledDependsAction() bool GetEnableDependsForALLAction() bool }
Action ... See DefaultAction for an example implementation.
type ActionDef ¶
type ActionDef struct { Name Expression `json:"name"` Parameters map[string]Expression `json:"parameters"` Enabled bool `json:"enabled"` EnabledDepends bool `json:"enabledDepends"` }
ActionDef action definition
func (ActionDef) Resolve ¶
func (a ActionDef) Resolve(k KnowledgeBase, EnableDependsForALLAction bool) (DefaultAction, error)
Resolve resolves the ActionDef into a DefaultAction
func (*ActionDef) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to Expression
type Case ¶
type Case struct { Name string `json:"name"` Condition Expression `json:"condition"` Actions []ActionDef `json:"actions"` Enabled bool `json:"enabled"` EnableDependsForALLAction bool `json:"enableDependsForALLAction"` }
Case : pair condition tasks use to compose a Rule
func (*Case) UnmarshalJSON ¶
UnmarshalJSON unmashals a quoted json string to Expression
type DefaultAction ¶
type DefaultAction struct { Name string `json:"name"` Parameters map[string]interface{} `json:"parameters"` MetaData map[string]interface{} `json:"metaData"` EnabledDependsAction bool `json:"enabledDepends"` EnableDependsForALLAction bool `json:"enableDependsForALLAction"` }
DefaultAction default action implementation
func (DefaultAction) GetEnableDependsForALLAction ¶
func (a DefaultAction) GetEnableDependsForALLAction() bool
GetEnableDependsForALLAction return if the case supports dependency management
func (DefaultAction) GetEnabledDependsAction ¶
func (a DefaultAction) GetEnabledDependsAction() bool
GetDisableDepends return if the action agrees dependency management
func (DefaultAction) GetMetaData ¶
func (a DefaultAction) GetMetaData() map[string]interface{}
GetMetaData returns the action metadata
func (DefaultAction) GetName ¶
func (a DefaultAction) GetName() string
GetName returns the action name
func (DefaultAction) GetParameters ¶
func (a DefaultAction) GetParameters() map[string]interface{}
GetParameters returns the action parameters
type DefaultKnowledgeBase ¶
type DefaultKnowledgeBase struct {
// contains filtered or unexported fields
}
DefaultKnowledgeBase default knowledge base implementation
func (*DefaultKnowledgeBase) GetFact ¶
func (kBase *DefaultKnowledgeBase) GetFact(key string) interface{}
GetFact returns the value of a key in the facts map
func (*DefaultKnowledgeBase) GetFacts ¶
func (kBase *DefaultKnowledgeBase) GetFacts() map[string]interface{}
GetFacts returns the facts maps of the KBase
func (*DefaultKnowledgeBase) InsertFact ¶
func (kBase *DefaultKnowledgeBase) InsertFact(key string, value interface{})
InsertFact inserts a key value (fact) in the facts map
func (*DefaultKnowledgeBase) Reset ¶
func (kBase *DefaultKnowledgeBase) Reset()
Reset removes all de facts and indexs in the KBase
func (*DefaultKnowledgeBase) SetDefaultValues ¶
func (kBase *DefaultKnowledgeBase) SetDefaultValues(parameters map[string]interface{})
SetDefaultValues add defaults values at the facts in the KBase
func (*DefaultKnowledgeBase) SetFacts ¶
func (kBase *DefaultKnowledgeBase) SetFacts(facts map[string]interface{})
SetFacts overwrides the facts in the KBase
func (*DefaultKnowledgeBase) String ¶
func (kBase *DefaultKnowledgeBase) String() string
type DefaultRule ¶
type DefaultRule struct { ID int64 `json:"id,omitempty"` Cases []Case `json:"cases"` Version int64 `json:"version"` Parameters map[string]interface{} `json:"parameters"` EvaluateAllCases bool `json:"evaluateallcase"` }
DefaultRule default rule implementation
func (DefaultRule) Execute ¶
func (r DefaultRule) Execute(k KnowledgeBase) []Action
Execute executes the rule and return the resulting actions
func (DefaultRule) GetDefaultValues ¶
func (r DefaultRule) GetDefaultValues() map[string]interface{}
GetDefaultValues returns rule default values
func (*DefaultRule) UnmarshalJSON ¶
func (r *DefaultRule) UnmarshalJSON(data []byte) error
UnmarshalJSON unmashals a quoted json string to Expression
type DefaultRuleBase ¶
type DefaultRuleBase struct {
// contains filtered or unexported fields
}
DefaultRuleBase default rule base implementation
func (*DefaultRuleBase) ExecuteAll ¶
func (rBase *DefaultRuleBase) ExecuteAll(k KnowledgeBase) []Action
ExecuteAll executes all the rules of the ruleBase using the knowledgeBase provided as parameter
func (*DefaultRuleBase) ExecuteByID ¶
func (rBase *DefaultRuleBase) ExecuteByID(ruleID int64, k KnowledgeBase) ([]Action, error)
ExecuteByID executes the rule with the name provide in the parameter 'ruleName' using the knowledgeBase provided as parameter
func (*DefaultRuleBase) ExecuteRules ¶
func (rBase *DefaultRuleBase) ExecuteRules(ruleIDs []int64, k KnowledgeBase) []Action
ExecuteRules executes a list of the rules of the ruleBase using the knowledgeBase provided as parameter
func (*DefaultRuleBase) GetRules ¶
func (rBase *DefaultRuleBase) GetRules() map[int64]Rule
GetRules returns the rules
func (*DefaultRuleBase) InsertRule ¶
func (rBase *DefaultRuleBase) InsertRule(rule Rule)
InsertRule allows to inser a Rule in the rulesBase
func (*DefaultRuleBase) InsertRules ¶
func (rBase *DefaultRuleBase) InsertRules(rules []Rule)
InsertRules allows to inser a liste of Rules in the rulesBase
func (*DefaultRuleBase) RemoveRule ¶
func (rBase *DefaultRuleBase) RemoveRule(id int64)
RemoveRule allows to remove a Rule in the rulesBase
func (*DefaultRuleBase) Reset ¶
func (rBase *DefaultRuleBase) Reset()
Reset removes the rules, tasks and errors of the rulesBase
type Expression ¶
type Expression string
Expression struct to represent an expression
func (Expression) Evaluate ¶
func (exp Expression) Evaluate(k KnowledgeBase) (interface{}, error)
Evaluate evaluates the expression and return the result as interface{}
func (Expression) EvaluateAsBool ¶
func (exp Expression) EvaluateAsBool(k KnowledgeBase) (bool, error)
EvaluateAsBool evaluates the expression and verifies that the result is the type boolean use to evaluate the conditions in the rule cases (conditions should return a boolean as result)
func (Expression) EvaluateAsString ¶
func (exp Expression) EvaluateAsString(k KnowledgeBase) (string, error)
EvaluateAsString evaluates the expression and verifies that the result is the type string
func (Expression) MarshalJSON ¶
func (exp Expression) MarshalJSON() ([]byte, error)
MarshalJSON mashals a Expression to a a quoted json string
func (*Expression) UnmarshalJSON ¶
func (exp *Expression) UnmarshalJSON(data []byte) error
UnmarshalJSON unmashals a quoted json string to Expression
type KnowledgeBase ¶
type KnowledgeBase interface { GetFacts() map[string]interface{} InsertFact(key string, value interface{}) SetFacts(facts map[string]interface{}) SetDefaultValues(parameters map[string]interface{}) GetFact(key string) interface{} Reset() }
KnowledgeBase ...
type Rule ¶
type Rule interface { GetID() int64 GetDefaultValues() map[string]interface{} Execute(k KnowledgeBase) []Action }
Rule ... See DefaultRule for an example implementation.
type RuleBase ¶
type RuleBase interface { GetRules() map[int64]Rule InsertRule(r Rule) InsertRules(rules []Rule) RemoveRule(id int64) Reset() ExecuteAll(k KnowledgeBase) []Action ExecuteRules(ids []int64, k KnowledgeBase) []Action ExecuteByID(id int64, k KnowledgeBase) ([]Action, error) }
RuleBase ...
type RuleEngine ¶
type RuleEngine struct {
// contains filtered or unexported fields
}
RuleEngine represents an instance of a rule engine
func (*RuleEngine) ExecuteAllRules ¶
func (engine *RuleEngine) ExecuteAllRules()
ExecuteAllRules executes all the rules in the baseRules using the knowledgeBase
func (*RuleEngine) ExecuteRule ¶
func (engine *RuleEngine) ExecuteRule(id int64) error
ExecuteRule executes a single rule by id using the knowledgeBase
func (*RuleEngine) ExecuteRules ¶
func (engine *RuleEngine) ExecuteRules(ids []int64)
ExecuteRules executes all a list of rules in the baseRules using the knowledgeBase
func (*RuleEngine) GetKnowledgeBase ¶
func (engine *RuleEngine) GetKnowledgeBase() KnowledgeBase
GetKnowledgeBase returns the knowledgeBase in the RuleEngine
func (*RuleEngine) GetResults ¶
func (engine *RuleEngine) GetResults() []Action
GetResults returns the Results of the rules executed
func (*RuleEngine) GetRulesBase ¶
func (engine *RuleEngine) GetRulesBase() RuleBase
GetRulesBase returns the RulesBase in the RuleEngine
func (*RuleEngine) InsertKnowledge ¶
func (engine *RuleEngine) InsertKnowledge(key string, value interface{})
InsertKnowledge inserts a key value (fact) in the knowledgeBase of the RuleEngine
func (*RuleEngine) InsertRule ¶
func (engine *RuleEngine) InsertRule(r Rule)
InsertRule inserts a rule in the ruleBase of the RuleEngine
func (*RuleEngine) InsertRules ¶
func (engine *RuleEngine) InsertRules(rules []Rule)
InsertRules inserts a slice of rules in the ruleBase of the RuleEngine
func (*RuleEngine) RemoveRule ¶
func (engine *RuleEngine) RemoveRule(id int64)
RemoveRule remocves a rule in the ruleBase of the RuleEngine
func (*RuleEngine) Reset ¶
func (engine *RuleEngine) Reset()
Reset remove all the results added in previous rules execution
func (*RuleEngine) SetKnowledge ¶
func (engine *RuleEngine) SetKnowledge(k KnowledgeBase)
SetKnowledge overwrites the knowledgeBase in the RuleEngine
func (*RuleEngine) SetRules ¶
func (engine *RuleEngine) SetRules(r RuleBase)
SetRules overwrites the ruleBase in the RuleEngine