Documentation
¶
Overview ¶
Package wikidataclient is a small client for the Wikidata Query Service SPARQL endpoint (https://query.wikidata.org/sparql) — free, keyless, but it 403s a request with no identifying User-Agent (Wikimedia's own UA policy).
It decodes the standard SPARQL 1.1 Query Results JSON Format (https://www.w3.org/TR/sparql11-results-json/) — `head.vars` + `results.bindings` — generically: this package has no knowledge of any particular query's projected variables or what they mean. Turning a result row into an application's own domain type (e.g. an organization record) is the caller's job.
The request shape (endpoint, format=json, query param, Accept header, User-Agent requirement) mirrors an already-shipped, already-verified integration against this same endpoint: https://github.com/olehmushka/go-oikumenea/blob/main/internal/hermenea/fetcher/fetcher.go (its generic HTTP fetcher, used for the Wikidata SPARQL source) and https://github.com/olehmushka/go-oikumenea/blob/main/internal/hermenea/wikidataorgs/mapper.go (D-ExternalOrgs / M30, which reads this exact JSON shape) — this package is that integration's fetch+decode layer, extracted and generalized to the standard format rather than one caller's projected fields.
Index ¶
Constants ¶
const DefaultEndpoint = "https://query.wikidata.org/sparql"
DefaultEndpoint is the public Wikidata Query Service SPARQL endpoint.
const DefaultUserAgent = "go-wikidata-client/0.1 (+https://github.com/olehmushka/go-wikidata-client)"
DefaultUserAgent identifies this client when UserAgentEnv is unset. Wikimedia's UA policy expects a real contact for anything beyond casual use — an operator embedding this client in their own product should set UserAgentEnv to their own.
const UserAgentEnv = "WIKIDATA_CLIENT_USER_AGENT"
UserAgentEnv lets an operator override the outbound User-Agent with their own contact, as Wikimedia's UA policy requires for sustained use.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a Wikidata SPARQL query client. The zero value is not usable — construct one with New.
type Option ¶
type Option func(*Client)
Option configures a Client constructed via New.
func WithEndpoint ¶
WithEndpoint overrides DefaultEndpoint — e.g. to point at a different SPARQL endpoint entirely (Wikidata's own JSON shape is the standard SPARQL 1.1 format, so this client works against any conformant endpoint, not only Wikidata's).
func WithUserAgent ¶
WithUserAgent overrides the default/env-resolved User-Agent.
type Result ¶
Result is one SPARQL query's decoded result set. Vars are the projected variable names (SELECT ?org ?orgLabel ... -> ["org", "orgLabel", ...]); Rows are one map[varName]Value per result row. A variable absent from a given row (SPARQL OPTIONAL) is simply absent from that row's map.