Documentation
¶
Overview ¶
Package principles holds the built-in detectors of the values layer: a curated lexicon for the safety principle (destructive infrastructure commands, the shell ones taken from instinct/detection) and the toxicity principle (abuse and threats aimed at people), and the score that turns pattern matches into a violation score.
The patterns are written for folded text (see detection.Fold): lower case, one space between words. The engine scores the folded text.
Lexicon entries are ASCII case-insensitive. Score counts their matches on a lower-cased copy of the text with a literal-prefix search, so a lexicon costs one fast pass per entry instead of a full regexp scan, and stays linear on large inputs. A shell command whose repetition is unbounded runs as one regexp pass over the lower-cased text instead, which is linear too. Score counts exactly what the returned regexps find.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Lexicon ¶
Lexicon returns the built-in patterns of principle p in the given categories, or in every category when categories is empty. It returns nil for a principle without a built-in lexicon: only safety and toxicity have one. The patterns are ASCII case-insensitive.
Types ¶
type Scorer ¶
type Scorer struct {
// contains filtered or unexported fields
}
Scorer counts the matches of a fixed set of patterns, as Score does. It groups the built-in lexicon once, so counting many short texts against the same patterns stays cheap.