Documentation
¶
Overview ¶
Package diversity maps a work's controlled subjects to diversity-audit categories (libcat tasks/365). It is the "content demographics" half of the diversity-audit feature: what works are *about*, derived from their subject headings. Creator demographics are a separate, opt-in axis (tasks/368).
The crosswalk is data-driven from an embedded TOML seed, which an operator may override with their own file. Matching a subject to a category is a statement about the work's topic, never about the identity of its creators.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Auditor ¶
type Auditor struct {
// contains filtered or unexported fields
}
Auditor streams works into a coverage-first content-diversity tally. Build it once from a crosswalk, Add each work's subjects, then read Report. It is not safe for concurrent Add.
func NewAuditor ¶
NewAuditor returns an Auditor over the given crosswalk.
func (*Auditor) Add ¶
func (a *Auditor) Add(subjects []SubjectRef)
Add folds one work's subjects into the tally. A work counts toward CoveredWorks when it carries at least one subject with a URI or a non-empty label, and toward a category once when any of its subjects maps there. A work with no usable subjects contributes only to TotalWorks -- it dilutes coverage, which is the point of reporting coverage.
type Category ¶
type Category struct {
ID string `toml:"id"`
Label string `toml:"label"`
Keywords []string `toml:"keywords"`
URIs []string `toml:"uris"`
}
Category is one diversity-audit category and the controlled subjects that map to it: an exact authority-URI match or a whole-word/phrase match on a subject's heading label. The taxonomy is an editorial choice; this is just its data shape.
type CategoryTally ¶
type CategoryTally struct {
ID string `json:"id"`
Label string `json:"label"`
Works int `json:"works"`
}
CategoryTally is one category's representation. Works counts each work once, however many of its subjects matched. ShareCovered is Works/CoveredWorks (the share among works that could be categorized at all); ShareTotal is Works/TotalWorks (the share of the whole corpus).
type Crosswalk ¶
type Crosswalk struct {
// contains filtered or unexported fields
}
Crosswalk categorizes subjects. It is built once (from the seed plus any operator overrides) and is read-only thereafter, so it is safe for concurrent use.
func Default ¶
func Default() *Crosswalk
Default returns the crosswalk built from the embedded seed alone. A malformed seed is a programming error (the embedded file is guarded by a golden test), so it panics rather than returning a silently empty categorizer.
func Load ¶
Load returns the crosswalk built from the embedded seed with each override file merged over it in order. Merge is by category id: an override category unions its keywords and uris onto the matching seed category and, when it sets a non-empty label, replaces the label; an override category with a new id is appended. A missing or malformed override file is an error -- an operator who points libcat at a crosswalk expects it to be honored, not silently ignored.
func (*Crosswalk) Categories ¶
Categories returns the categories in stable reporting order (seed order, then any operator-added categories). Keyword/URI detail is omitted; this is for labeling aggregated counts.
func (*Crosswalk) Categorize ¶
Categorize returns the ids of every category a single subject maps to, in stable reporting order. A subject matches a category by exact authority URI (when uri is non-empty) or by a whole-word/phrase match of any of the category's keywords against the heading label. Passing "" for either argument skips that dimension.
func (*Crosswalk) CategorizeSubjects ¶
CategorizeSubjects returns the ids of every category any of the given subjects maps to, deduplicated and in stable reporting order -- the work-level roll-up a caller (tasks/366) uses to count a work once per matched category. Each subject is a (uri, label) pair; either may be empty.
type Report ¶
type Report struct {
// TotalWorks is every work the audit saw.
TotalWorks int `json:"totalWorks"`
// CoveredWorks is the works carrying at least one subject (URI or label) --
// the only works that can be categorized, and the honest denominator.
CoveredWorks int `json:"coveredWorks"`
// Coverage is CoveredWorks/TotalWorks in [0,1]. A low value means the audit
// speaks for only part of the collection; read every category share with it.
Coverage float64 `json:"coverage"`
// Categories are the diversity categories in the crosswalk's reporting order.
Categories []CategoryTally `json:"categories"`
}
Report is a coverage-first content-diversity audit of a corpus. It reports what the works are *about*, never who created them. Every category share is stated against an explicit denominator so undercounting is visible rather than hidden: CoveredWorks (works that carry any subject at all) is the honest base for representation, while ShareTotal shows the dilution across the whole corpus, including works no one has subjected yet.
type SubjectRef ¶
SubjectRef is one of a work's subjects as the audit sees it: an authority URI (may be empty for a bare-string ILS heading) and its heading labels (may be empty for a URI-only reference). Either dimension feeds the crosswalk.