wikidata

package
v0.181.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package wikidata resolves a Work's creators to Wikidata entities and caches their EXPLICITLY-STATED demographic claims as enrichment statements -- the creator-demographics half of the diversity-audit feature.

The contract, in order of importance:

  • No name inference, ever. Resolution goes ISBN -> edition (P212/P957) -> work (P629) -> author (P50): every hop is a cataloged identifier or an explicit Wikidata statement. A creator's name is never matched against anything, and a work without a resolvable identifier yields nothing.
  • Explicit claims only, with provenance. Only the values Wikidata states outright for P21 (sex or gender), P27 (country of citizenship), P91 (sexual orientation), and P172 (ethnic group) are recorded, each as the claim's own entity URI plus label, alongside the QID it came from, what identifier matched it, and the retrieval date. Birth/death dates are deliberately not fetched.
  • Aggregate use. These statements exist so a collection-level audit can report distributions with coverage; they are enrichment-graph data, not display fields, and the projector does not surface them on work pages.

Coverage will be partial and skewed (Wikidata's own coverage is); the audit reading this data is responsible for reporting match rate and unknowns first. Statements land in the enrichment:wikidata graph, dropped and replaced on each run, so a re-run refreshes and a removed claim upstream disappears here too.

Index

Constants

View Source
const DefaultEndpoint = "https://query.wikidata.org/sparql"

DefaultEndpoint is the public Wikidata Query Service SPARQL endpoint.

View Source
const Name = "wikidata"

Name is the enrichment source name; statements land in enrichment:wikidata.

Variables

This section is empty.

Functions

This section is empty.

Types

type Doer

type Doer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer is the HTTP seam, injectable for tests.

type Enricher

type Enricher struct {
	// contains filtered or unexported fields
}

Enricher resolves creators via the Wikidata Query Service.

func New

func New(opts ...Option) *Enricher

New returns the Wikidata creator-demographics enricher.

func (*Enricher) Enrich

func (e *Enricher) Enrich(ctx context.Context, works []ingest.WorkSummary) ([]ingest.Enrichment, error)

Enrich resolves each Work's ISBNs and returns creator-claim enrichments for the Works that matched. Works with no ISBN, or whose ISBNs Wikidata does not know, are absent from the result -- RunEnrich leaves them untouched, and the audit reports them as unmatched rather than guessing.

func (*Enricher) Name

func (e *Enricher) Name() string

Name implements ingest.Enricher.

func (*Enricher) Skipped added in v0.181.1

func (e *Enricher) Skipped() int

Skipped reports how many batches the last Enrich call abandoned after retries; their works were left untouched for a re-run to backfill.

type Option

type Option func(*Enricher)

Option configures the enricher.

func WithClient

func WithClient(d Doer) Option

WithClient injects the HTTP client (tests; a caller with its own limits).

func WithDelay

func WithDelay(d time.Duration) Option

WithDelay overrides the politeness pause between SPARQL batches.

func WithEndpoint

func WithEndpoint(u string) Option

WithEndpoint points at a different SPARQL endpoint (a mirror, a test stub).

func WithRetryBase added in v0.181.1

func WithRetryBase(d time.Duration) Option

WithRetryBase overrides the first retry pause (tests use 0).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL