Documentation
¶
Overview ¶
Package validate runs the real backend over real records and reports whether what the parser recovered survives, intact and plausible, all the way to the structures a client receives.
It is a development tool. Nothing in the served request path imports it, it is never started by the daemon, and it costs the running service nothing.
The pipeline deliberately reuses the shipping implementation at every step — the same sampling as profile detection, the same service lookup, the same Bob adapter — because a validation harness that reimplements the thing it validates only ever proves that the copy agrees with itself.
Index ¶
- Constants
- func SaveBaseline(path string, run *Run) error
- func Write(dir string, run *Run) error
- type Baseline
- type Change
- type Check
- type Comparison
- type DictionaryResult
- type Fields
- type Language
- type Metrics
- type NameCount
- type Options
- type Run
- type RunTotals
- type Snapshot
- type Tier
- type TierTotals
Constants ¶
const ( SignalNoResult = "no-result" SignalFallback = "fallback-only" SignalLowRetention = "low-retention" SignalHighDuplication = "high-duplication" SignalDominantField = "one-field-dominates" SignalRepeatedContent = "repeated-content" SignalSubsenseEcho = "subsense-repeats-parent" SignalExamplesNoDefs = "examples-without-definitions" SignalHighSenseCount = "high-sense-count" SignalHeadwordMismatch = "headword-unlike-key" SignalBilingualNoGloss = "bilingual-without-translation" SignalTranslationOnly = "translation-without-definition" SignalParityFailure = "backend-parity-failure" SignalSingleHugeExample = "example-longer-than-definition" )
Signals are conservative per-record observations. Like the dictionary-level warnings they extend, none of them proves a parse is wrong — every one has a legitimate explanation for some dictionary. What they do is rank: a record carrying three of these is a better use of a reviewer's attention than one carrying none.
const DefaultQueueSize = 100
DefaultQueueSize is chosen from what a person can actually read. A thousand sampled records is data; a hundred ranked ones is a review.
Variables ¶
This section is empty.
Functions ¶
func SaveBaseline ¶
SaveBaseline writes this run's snapshots for the next one to compare with.
Types ¶
type Baseline ¶
type Baseline struct {
GeneratedAt string `json:"generatedAt"`
Snapshots []Snapshot `json:"snapshots"`
}
Baseline is a previous run, reduced to what a comparison needs.
func LoadBaseline ¶
LoadBaseline reads a saved run. A missing file is not an error: the first run of the pipeline has nothing to compare against and should say so rather than fail.
type Change ¶
type Change string
Change classifies one record between two runs.
const ( ChangeUnchanged Change = "unchanged" // ChangeSourceChanged means the record itself is different, so nothing can // be concluded about the parser from it. ChangeSourceChanged Change = "source-changed" ChangeImprovement Change = "likely-improvement" ChangeNeedsReview Change = "changed" ChangeRegression Change = "possible-regression" ChangeNew Change = "new" ChangeMissing Change = "missing" )
type Check ¶
type Check struct {
Name string `json:"name"`
OK bool `json:"ok"`
Detail string `json:"detail,omitempty"`
}
Check is one invariant and whether it held.
type Comparison ¶
type Comparison struct {
BaselineAt string `json:"baselineAt"`
Counts []NameCount `json:"counts"`
// Missing lists records the baseline had that this run did not produce.
Missing []string `json:"missing,omitempty"`
// contains filtered or unexported fields
}
Comparison is the full baseline-versus-current result.
type DictionaryResult ¶
type DictionaryResult struct {
Report diagnose.Report `json:"report"`
// RuntimeProfile is authoritative for every metric below. Report.Profile
// remains the independent diagnostic evidence used to explain the choice.
RuntimeProfile string `json:"runtimeProfile"`
Language Language `json:"language"`
Snapshots []Snapshot `json:"snapshots"`
// Aggregates over this dictionary's snapshots.
MeanRetention float64 `json:"meanRetention"`
MeanDuplication float64 `json:"meanDuplication"`
Rules []NameCount `json:"rules,omitempty"`
Signals []NameCount `json:"signals,omitempty"`
Failures []NameCount `json:"failures,omitempty"`
}
DictionaryResult is one dictionary's validation run.
func Dictionary ¶
func Dictionary(svc *service.Service, dict *mdict.Dictionary) DictionaryResult
Dictionary validates one dictionary end to end.
type Fields ¶
type Fields struct {
Parts int `json:"parts"`
POSLabels int `json:"posLabels"`
Senses int `json:"senses"`
Subsenses int `json:"subsenses"`
Definitions int `json:"definitions"`
Translations int `json:"translations"`
Examples int `json:"examples"`
ExampleTranslations int `json:"exampleTranslations"`
Labels int `json:"labels"`
IPA int `json:"ipa"`
Audio int `json:"audio"`
Forms int `json:"forms"`
Phrases int `json:"phrases"`
CrossReferences int `json:"crossReferences"`
Sections int `json:"sections"`
Fallback int `json:"fallback"`
}
Fields counts what one record's parse produced, by kind.
type Language ¶
type Language struct {
Tier Tier `json:"tier"`
// KeyScript is the writing system the headwords are in.
KeyScript string `json:"keyScript"`
// ContentScripts are the scripts found in record text, most common first.
ContentScripts []string `json:"contentScripts,omitempty"`
// Chinese reports Chinese text on either side of the dictionary.
Chinese bool `json:"chinese"`
// Bilingual reports two scripts, or a title that names two languages.
Bilingual bool `json:"bilingual"`
// Lexical reports whether the resource behaves like a lexicon at all.
Lexical bool `json:"lexical"`
// ChineseClauses and CJKClauses are the raw counts the Chinese decision
// was made from, kept so the threshold can be argued with rather than
// taken on trust.
ChineseClauses int `json:"chineseClauses,omitempty"`
CJKClauses int `json:"cjkClauses,omitempty"`
// Evidence records, in words, why the tier came out as it did.
Evidence []string `json:"evidence,omitempty"`
}
Language is what sampling can determine about a dictionary's languages without anyone labelling it by hand.
Everything here is derived from scripts in the sampled records plus the dictionary's own title. It decides review priority only. No parsing behaviour depends on it, which is the reason a rough answer is acceptable: the cost of misclassifying a dictionary is that a human reads it in the wrong order, not that it parses differently.
type Metrics ¶
type Metrics struct {
// SourceTokens is the record text the parser was actually asked to read:
// the whole record, less what the profile scopes out. OutputTokens is
// counted over the same tokenization, so the two are directly comparable.
SourceTokens int `json:"sourceTokens"`
OutputTokens int `json:"outputTokens"`
// RecordTokens is the whole record before scoping, and Scope the fraction
// of it left in play. A profile that narrows a record to a tenth of itself
// is making a real editorial decision, and hiding that inside a healthy
// retention figure would be the wrong kind of tidy.
RecordTokens int `json:"recordTokens"`
Scope float64 `json:"scope"`
// Retention is the share of source tokens the semantic output accounts
// for. Low retention means the parser dropped content on the floor.
Retention float64 `json:"retention"`
// Duplication is the share of output tokens in excess of what the source
// contains. High duplication means one passage was emitted twice.
Duplication float64 `json:"duplication"`
// LargestFieldShare is the biggest single extracted field as a share of
// the record. Near 1 means one field swallowed the entry.
LargestFieldKind string `json:"largestFieldKind,omitempty"`
RepeatedDefinitions int `json:"repeatedDefinitions,omitempty"`
RepeatedExamples int `json:"repeatedExamples,omitempty"`
SubsenseEchoesParent int `json:"subsenseEchoesParent,omitempty"`
SectionEchoesSense int `json:"sectionEchoesSense,omitempty"`
}
Metrics are the automatic consistency signals for one parsed record.
type Options ¶
type Options struct {
// QueueSize caps the human-review queue.
QueueSize int
// Baseline is a previous run to compare against, or nil.
Baseline *Baseline
// Progress is called once per dictionary.
Progress func(index, total int, title string)
}
Options configures a validation run.
type Run ¶
type Run struct {
Root string `json:"root"`
GeneratedAt string `json:"generatedAt"`
Total int `json:"total"`
Healthy int `json:"healthy"`
Dictionaries []DictionaryResult `json:"dictionaries"`
Families []diagnose.Family `json:"families,omitempty"`
Tiers []NameCount `json:"tiers,omitempty"`
Parsers []NameCount `json:"parsers,omitempty"`
Rules []NameCount `json:"rules,omitempty"`
Signals []NameCount `json:"signals,omitempty"`
Failures []NameCount `json:"failures,omitempty"`
Aggregate RunTotals `json:"aggregate"`
Queue []Snapshot `json:"queue,omitempty"`
Comparison *Comparison `json:"comparison,omitempty"`
}
Run is one complete validation pass over one or many dictionaries.
type RunTotals ¶
type RunTotals struct {
Records int `json:"records"`
MeanRetention float64 `json:"meanRetention"`
MeanDuplication float64 `json:"meanDuplication"`
ByTier []TierTotals `json:"byTier,omitempty"`
}
RunTotals are the corpus-level numbers a parser change is judged by.
They are reported per tier as well as overall, because an average taken over a corpus that is a quarter encyclopedias measures the corpus, not the parser.
type Snapshot ¶
type Snapshot struct {
DictionaryID string `json:"dictionaryId"`
DictionaryTitle string `json:"dictionaryTitle"`
Tier string `json:"tier"`
// Key and MatchedKey are local-only identity. They stay inside
// git-ignored artifacts.
Key string `json:"key"`
MatchedKey string `json:"matchedKey,omitempty"`
// RecordHash identifies the source bytes without reproducing them, so a
// baseline can tell "the parser changed" from "the dictionary changed".
RecordHash string `json:"recordHash"`
EntryHash string `json:"entryHash"`
Parser string `json:"parser"`
Evidence string `json:"evidence"`
RawRecords int `json:"rawRecords"`
Records int `json:"records"`
Fields Fields `json:"fields"`
Metrics Metrics `json:"metrics"`
Rules []NameCount `json:"rules,omitempty"`
Signals []string `json:"signals,omitempty"`
Failures []string `json:"failures,omitempty"`
// Score and Reasons are filled in by the review queue.
Score int `json:"score,omitempty"`
Reasons []string `json:"reasons,omitempty"`
// contains filtered or unexported fields
}
Snapshot is one validated record: what went in, what came out at each layer, and every automatic signal about it.
The persisted half is metadata and measurements. The rendered half — source HTML, Plain Text, Markdown, Bob JSON — carries real dictionary text and is therefore never serialized: it exists only to be written into a local review file.
type Tier ¶
type Tier int
Tier is how much scrutiny a dictionary earns, ordered by what this project is actually for.
The corpus contains a hundred dictionaries and they are not equally important. A Chinese-English learner's dictionary is the product; a database of place names is a file that happens to be in MDX. Weighting review by that difference is what keeps a hundred encyclopedia fallbacks from drowning out twenty real parsing problems.
const ( // TierChinese is any dictionary with Chinese on either side. TierChinese Tier = iota // TierEnglishMono is English-to-English. TierEnglishMono // TierEnglishOther is English paired with a language other than Chinese. TierEnglishOther // TierOtherLexical is an ordinary dictionary in some other combination. TierOtherLexical // TierReference is an encyclopedia, name list or article collection: not // primarily a lexicon, and not something to force senses onto. TierReference )
type TierTotals ¶
type TierTotals struct {
Tier string `json:"tier"`
Dictionaries int `json:"dictionaries"`
Records int `json:"records"`
Structured int `json:"structured"`
Fallback int `json:"fallback"`
MeanRetention float64 `json:"meanRetention"`
MeanDuplication float64 `json:"meanDuplication"`
Flagged int `json:"flagged"`
}
TierTotals are one priority tier's numbers.