Documentation
¶
Overview ¶
Package rules implements deterministic matching as a classmesh.Stage. Rules are evaluated in order and the first match wins. Matches emit confidence 1 and misses return classmesh.ErrUnclassified.
Index ¶
Constants ¶
const Name = "rules"
Name identifies this stage in classifications, stats, and logs.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type FieldMatcher ¶
type FieldMatcher struct {
Path string
Exact *string
Contains *string
Regex *string
Exists *bool
Gt *float64
Gte *float64
Lt *float64
Lte *float64
}
FieldMatcher tests one value in a record's decoded Fields, addressed by a dot-separated Path (see fieldpath). Exactly one condition must be set:
- Exact (equal), Contains (substring), Regex (pattern) compare the value as text; a value that is an object or array never matches. Numbers are matched by their text form.
- Gt, Gte, Lt, Lte compare the value as a number; a value that is not numeric (including a numeric-looking string) never matches.
- Exists is true when the path is present, false when absent.
type Matcher ¶
type Matcher struct {
Contains *string
Regex *string
Field *FieldMatcher
}
Matcher is one condition inside an Any or All group: exactly one of a payload Contains substring, a payload Regex, or a Field test.
type Rule ¶
type Rule struct {
ID string
Category string
Contains []string
Regex []string
Fields []FieldMatcher
Any []Matcher
All []Matcher
}
Rule maps matchers to a category. It carries up to three matcher blocks, all of which must be satisfied for the rule to match (an absent block is ignored):
- the top-level Contains/Regex/Fields matchers, satisfied when ANY of them hits (the shorthand for a simple rule);
- All, satisfied when every listed matcher hits;
- Any, satisfied when at least one listed matcher hits.
Substring matching is case-sensitive; use (?i) in a regex for case-insensitive matching. ID and Category label the rule in errors and in the reason attached to a match.
type Stage ¶
type Stage struct {
// contains filtered or unexported fields
}
Stage is a deterministic rule-matching stage.
func New ¶
New compiles rules in order. Every rule needs a category and at least one matcher; every regex must compile and every matcher must be well formed.