Documentation ¶
Overview ¶
Package qfy is a generic implementation of a semi-optimised qualification rule evaluation engine, using basic principles or the RETE algorithm.
The goal is to match a fact, usually attributes or key/value pairs against a list of pre-defined rules. Rules can be simple conditions or complex logical expressions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CRC64 ¶
type CRC64 struct {
// contains filtered or unexported fields
}
CRC64 is used by conditions to calculate unique and consistent CRC64 sum
type ConcurrentDict ¶
type ConcurrentDict struct {
// contains filtered or unexported fields
}
ConcurrentDict is just like Dict, but thread-safe and therefore slightly slower.
func NewConcurrentDict ¶
func NewConcurrentDict() *ConcurrentDict
NewConcurrentDict creates a new dict
func (*ConcurrentDict) Add ¶
func (d *ConcurrentDict) Add(v string) int64
Add adds a value to the dictionary if not already present and returns the associtated ID
func (*ConcurrentDict) AddSlice ¶
func (d *ConcurrentDict) AddSlice(vv ...string) []int64
AddSlice adds a whole slice of values
func (*ConcurrentDict) Get ¶
func (d *ConcurrentDict) Get(v string) int64
Get is a read-only operation, only returns known ID or 0
func (*ConcurrentDict) GetSlice ¶
func (d *ConcurrentDict) GetSlice(vv ...string) []int64
GetSlice is a read-only operation, only returns known IDs
type Condition ¶
type Condition interface { // CRC64 must return a globally unique an consistent rules identifier CRC64() uint64 // Match tests if the rule is qualified. Certain conditions can only // support certain types and must return a negative response if an // unsupported type is given. Match(interface{}) bool // String returns a human-readable rule description String() string }
Condition is an abstract logic evaluation condition
type Dict ¶
Dict is a simple helper to to turn convert strings into integers using dictionary encoding. Dict instances are NOT thread-safe because they are populated sequentially on Qualifier creation and then only read.
If your use case requires rules to call Add operations concurrently please use (the slower but) thread-safe ConcurrentDict
func (Dict) Add ¶
Add adds a value to the dictionary if not already present and returns the associtated ID
type Equality ¶
type Equality struct {
// contains filtered or unexported fields
}
Equality conditions require the fact value to match input.
func EqualTo ¶
func EqualTo(v interface{}) *Equality
EqualTo constructs an Equality condition Supports bool, string, intN, uintN and floatN fact values as inputs.
type Exclusion ¶
type Exclusion struct {
// contains filtered or unexported fields
}
Exclusion conditions require none of the values to be present in the fact
type Fact ¶
type Fact interface {
GetQualifiable(FactKey) interface{}
}
Fact is an interface of a fact that may be passed to a qualifier. Each fact must implement a GetQualifiable(FatKey) method which receives a key and must return either a bool, an int64 a float64 or an []int64 slice.
type FactKey ¶
type FactKey uint16
FactKey is a unique identifier of any fact attribute
func (FactKey) MustBe ¶
MustBe is syntactic sugar for CheckFact.
Example:
const ( AttrA qfy.FactCheck = iota AttrB ) ruleA := AttrA.MustBe(qfy.OneOf(1,2,3)) ruleB := AttrB.MustBe(qfy.OneOf(6,5,4)) ruleC := qfy.And(ruleA, ruleB)
func (FactKey) MustInclude ¶
MustInclude is an alias for MustBe
type Inclusion ¶
type Inclusion struct {
// contains filtered or unexported fields
}
Inclusion conditions require at least one value to be present in the fact Supports only int64 and []int64 fact values as inputs.
type Negation ¶
type Negation struct {
// contains filtered or unexported fields
}
Negation inverts a Condition
type NumericGreater ¶
type NumericGreater struct {
// contains filtered or unexported fields
}
NumericGreater conditions require the fact value to match input.
func GreaterThan ¶
func GreaterThan(v float64) *NumericGreater
GreaterThan constructs a NumericGreater condition Supports intN and floatN fact values as inputs.
func (*NumericGreater) Match ¶
func (r *NumericGreater) Match(v interface{}) bool
Match tests if the condition is qualified
func (*NumericGreater) String ¶
func (r *NumericGreater) String() string
String returns a human-readable description
type NumericGreaterOrEqual ¶
type NumericGreaterOrEqual struct {
// contains filtered or unexported fields
}
NumericGreaterOrEqual conditions require the fact value to match input.
func GreaterOrEqual ¶
func GreaterOrEqual(v float64) *NumericGreaterOrEqual
GreaterOrEqual constructs a NumericGreaterOrEqual condition Supports intN and floatN fact values as inputs.
func (*NumericGreaterOrEqual) CRC64 ¶
func (r *NumericGreaterOrEqual) CRC64() uint64
CRC64 returns a unique ID
func (*NumericGreaterOrEqual) Match ¶
func (r *NumericGreaterOrEqual) Match(v interface{}) bool
Match tests if the condition is qualified
func (*NumericGreaterOrEqual) String ¶
func (r *NumericGreaterOrEqual) String() string
String returns a human-readable description
type NumericLess ¶
type NumericLess struct {
// contains filtered or unexported fields
}
NumericLess conditions require the fact value to match input.
func LessThan ¶
func LessThan(v float64) *NumericLess
LessThan constructs a NumericLess condition Supports intN and floatN fact values as inputs.
func (*NumericLess) Match ¶
func (r *NumericLess) Match(v interface{}) bool
Match tests if the condition is qualified
func (*NumericLess) String ¶
func (r *NumericLess) String() string
String returns a human-readable description
type NumericLessOrEqual ¶
type NumericLessOrEqual struct {
// contains filtered or unexported fields
}
NumericLessOrEqual conditions require the fact value to match input.
func LessOrEqual ¶
func LessOrEqual(v float64) *NumericLessOrEqual
LessOrEqual constructs a NumericLessOrEqual condition Supports intN and floatN fact values as inputs.
func (*NumericLessOrEqual) CRC64 ¶
func (r *NumericLessOrEqual) CRC64() uint64
CRC64 returns a unique ID
func (*NumericLessOrEqual) Match ¶
func (r *NumericLessOrEqual) Match(v interface{}) bool
Match tests if the condition is qualified
func (*NumericLessOrEqual) String ¶
func (r *NumericLessOrEqual) String() string
String returns a human-readable description
type NumericRange ¶
type NumericRange struct {
// contains filtered or unexported fields
}
NumericRange conditions require the fact value to match input.
func Between ¶
func Between(min, max float64) *NumericRange
Between constructs a NumericRange condition Supports intN and floatN fact values as inputs.
func (*NumericRange) Match ¶
func (r *NumericRange) Match(v interface{}) bool
Match tests if the condition is qualified
func (*NumericRange) String ¶
func (r *NumericRange) String() string
String returns a human-readable description
type Qualifier ¶
type Qualifier struct {
// contains filtered or unexported fields
}
Qualifier represents a rule engine that can match a fact against a list of rule-sets using a fixed set of attributes
func New ¶
func New() *Qualifier
New creates a new qualifier with a list of known/qualifiable attributes