httk.core.dataset_loader¶
Attributes¶
Callback invoked as |
Classes¶
Read-only attribute and mapping view over a |
|
Describe header metadata extracted from a structured JSON-LD document. |
|
Lazy loader for httk dataset files, resolved only when data is first accessed. |
Module Contents¶
- type httk.core.dataset_loader.DecodeObjectCallback = Callable[[dict[str, Any], str], Any][source]¶
Callback invoked as
(dict_obj, jsonld_url)that returns the value to use in place ofdict_obj(return the input unchanged to decline).
- class httk.core.dataset_loader.DatasetRecord(data)[source]¶
Read-only attribute and mapping view over a
dict[str, Any].Top-level keys are reachable both as attributes (
record.name) and as items (record["name"]); the wrapped values are the plain parsed JSON and are not themselves wrapped. Supports iteration over keys,len(),in, andkeys().
- class httk.core.dataset_loader.DatasetMeta[source]¶
Describe header metadata extracted from a structured JSON-LD document.
- Parameters:
context – The raw document context.
id – The document identifier, if present.
type – The document type, if present.
header – Remaining top-level header fields.
dataset_ids – Dataset names mapped to their identifiers.
fields – Dataset names mapped to their field property URLs.
- type_: str | None[source]¶
The document
@type, orNoneif absent (trailing underscore avoids the builtintype).
- class httk.core.dataset_loader.DatasetLoader(identifier, source, decode_object=None, **hints)[source]¶
Lazy loader for httk dataset files, resolved only when data is first accessed.
A
DatasetLoaderis a declare-time placeholder: constructing it records its arguments and performs no I/O. The source is read the first timedata,meta, orindexis accessed. Files are either plain JSON (any JSON value is exposed asdatawithmeta/indexset toNone) or a structured JSON-LD document (with@context, header fields,data, and optionalindicies) whose header is exposed viameta, datasets viadata.<name>, and lookup indices viaindex.<name>.Loaders that share an
identifierdeduplicate through a class-level registry: the first load wins, and later loaders reusing that identifier return the same result while theirsourceanddecode_objectarguments are ignored. Keeping identifiers unique is the caller’s responsibility. Not thread-safe.Format is resolved from the source name after stripping any compression suffix: a
.jsonname (e.g.data.jsonordata.json.gz) is parsed as JSON; any other recognizable suffix raisesValueError; a source with no determinable name is treated as JSON. Compression is handled transparently by the stream layer, so.json.gzand similar load directly. Astr/Pathsource is interpreted as a filename unless its scheme marks it as a URL (http,https,ftp,file); bare network URLs are refused at read time, so passkind="url"or aurllib.request.Request. Passkind="content"for literal content orkind="filename"to force a filename interpretation.Example
symmetry_basics = DatasetLoader(“symmetry_basics”, “data/spacegroup_symbols.json”) spacegroups = symmetry_basics.data.spacegroups # first access triggers the load
- Parameters:
identifier (str) – The deduplication key for this load.
source (httk.core.datastream.TextstreamLike) – The filename, URL-like stream, request, or literal content to read.
decode_object (DecodeObjectCallback | None) – An optional callback for JSON-LD objects identified by context URLs.
**hints (Any) – Stream interpretation hints such as
kind.
- property meta: DatasetMeta | None[source]¶
Return structured-document metadata, or
Nonefor plain JSON.
- property index: DatasetRecord | None[source]¶
Return structured-document lookup indices, or
Nonewhen absent.