Documentation ¶
Overview ¶
Package streams provides a way to access predictions in a YAML stream.
YAML streams contain one or more documents in them, separated by three hyphen-minuses (---). In streams that we’re using, the first document functions as a metadata header while all subsequent documents are predictions. Each prediction, with few exceptions, has both a claim and a confidence.
Index ¶
- Constants
- func ConfidencesUsed(sts []Stream) []float64
- func Everything(_ PredictionDocument) bool
- func KeysUsed(sts []Stream) []string
- func NewErrorClaimMissing(s Stream, i int) error
- func NewErrorConfidenceImpossible(s Stream, i int) error
- func NewErrorConfidenceMissing(s Stream, i int) error
- func NewErrorConfidenceUnity(s Stream, i int) error
- func NewErrorConfidenceZero(s Stream, i int) error
- func TagsUsed(sts []Stream) []string
- type Filter
- type MetadataDocument
- type PredictionDocument
- type PredictionErrorMaker
- type Stream
- type ValidationError
- type ValidationFunction
- type Validator
- func (sv *Validator) AllConfidencesBetweenZeroAndOneHundredInclusive(s Stream) []error
- func (sv *Validator) AllConfidencesSensible(s Stream) []error
- func (sv *Validator) AllPredictionsHaveClaims(s Stream) []error
- func (sv *Validator) AllPredictionsHaveConfidences(s Stream) []error
- func (sv *Validator) HasTitleOrScopeInMetadataBlock(s Stream) []error
- func (sv *Validator) RunAll(s Stream) []error
- func (sv *Validator) RunMinimal(s Stream) []error
- func (sv *Validator) RunValidationFunctions(s Stream, vfs ...ValidationFunction) []error
Constants ¶
const (
NeitherTitleNorScopeInMetadataBlock = ValidationError("Neither title nor scope in metadata block")
)
Various errors returned when decoding documents out of a stream and into structs.
Variables ¶
This section is empty.
Functions ¶
func ConfidencesUsed ¶
ConfidencesUsed returns a list of all confidence intervals used in the given Streams.
func Everything ¶
func Everything(_ PredictionDocument) bool
Everything is a Filter that filters nothing out.
func KeysUsed ¶
KeysUsed returns a list of all keys used in the given Streams.
A “key”, here, is the title and scope of a given stream, with a space in between.
func NewErrorClaimMissing ¶
NewErrorClaimMissing returns an error that describes the approximate location of a prediction that has no claim.
func NewErrorConfidenceImpossible ¶
NewErrorConfidenceImpossible returns an error describing a prediction that has a confidence level below 0% or above 100%.
func NewErrorConfidenceMissing ¶
NewErrorConfidenceMissing returns an error describing a prediction that lacks a confidence level.
func NewErrorConfidenceUnity ¶
NewErrorConfidenceUnity returns an error describing a prediction that has a confidence level of 100%.
func NewErrorConfidenceZero ¶
NewErrorConfidenceZero returns an error describing a prediction that has a confidence level of zero.
Types ¶
type Filter ¶
type Filter func(PredictionDocument) bool
A Filter removes predictions from consideration if the predicate returns false.
func MatchingConfidence ¶
MatchingConfidence returns a Filter that returns true if the prediction’s confidence level matches (to within a fudge factor) the given confidence level.
func MatchingKey ¶
MatchingKey returns a Filter that returns true if the prediction’s key matches the given key.
func MatchingTag ¶
MatchingTag returns a Filter that returns true if the prediction’s tag matches the given tag.
type MetadataDocument ¶
type MetadataDocument struct { Title string Scope string Salt string Notes string // These are here to detect when a user accidentally omits a metadata document in a stream. MisplacedClaim string `yaml:"claim"` MisplacedConfidence string `yaml:"confidence"` }
A MetadataDocument contains information about the predictions in its Stream.
type PredictionDocument ¶
type PredictionDocument struct { Claim string Confidence *float64 Tags []string Happened *bool CauseForExclusion string `yaml:"cause for exclusion"` Hash bool Salt string Notes string Parent *Stream }
A PredictionDocument contains a claim, the claim’s confidence, and so on.
func DocumentsMatching ¶
func DocumentsMatching(sts []Stream, f Filter) []PredictionDocument
DocumentsMatching returns PredictionDocuments from streams that pass the given Filter.
func (*PredictionDocument) HasTag ¶
func (d *PredictionDocument) HasTag(tag string) bool
HasTag returns true if the given tag is in the receiver’s tag list.
func (*PredictionDocument) ShouldExclude ¶
func (d *PredictionDocument) ShouldExclude() bool
ShouldExclude returns true if the receiver should be excluded from stats calculation.
type PredictionErrorMaker ¶
A PredictionErrorMaker takes a Stream and an index and returns an error. The index is meant to be the index of the prediction, so the first prediction is referred to with a zero index.
type Stream ¶
type Stream struct { FromFilename string Metadata MetadataDocument Predictions []PredictionDocument }
A Stream (YAML stream) contains a metadata document and predictions documents.
In YAML, documents are prefixed by “---”.
type ValidationError ¶
type ValidationError string
A ValidationError is returned when something about the stream isn’t right.
func (ValidationError) Error ¶
func (e ValidationError) Error() string
type ValidationFunction ¶
A ValidationFunction ensures that a Stream passes a sanity check.
Because many things can go wrong in a Stream that a user would want to know about all at once, ValidationFunction returns a slice of error.
type Validator ¶
type Validator struct{}
A Validator contains data useful for ValidationFunctions.
func (*Validator) AllConfidencesBetweenZeroAndOneHundredInclusive ¶
AllConfidencesBetweenZeroAndOneHundredInclusive ensures all confidences are on [0, 100].
func (*Validator) AllConfidencesSensible ¶
AllConfidencesSensible ensures no confidence level is 0 or 100.
func (*Validator) AllPredictionsHaveClaims ¶
AllPredictionsHaveClaims ensures that all predictions in a stream have one claim in each.
func (*Validator) AllPredictionsHaveConfidences ¶
AllPredictionsHaveConfidences ensures that all predictions have a confidence key and a value of some sort.
func (*Validator) HasTitleOrScopeInMetadataBlock ¶
HasTitleOrScopeInMetadataBlock ensures that a stream has either title key or a scope key in the metadata block (or both). At least one of those keys’ values must be something other than the empty string.
func (*Validator) RunMinimal ¶
RunMinimal is a convenience function to run the bare minimum of sanity checks.
func (*Validator) RunValidationFunctions ¶
func (sv *Validator) RunValidationFunctions(s Stream, vfs ...ValidationFunction) []error
RunValidationFunctions runs a bunch of validation functions on a stream.
It returns a slice of error of everything that didn’t pass muster.