Profile Registry & Document Loading
The dartfx.cdif.registry module coordinates the discovery, registration, and polymorphic loading of CDIF metadata. It provides automated profile detection and document ingestion across multiple input formats.
The ProfileRegistry
The ProfileRegistry acts as the central lookup table linking CDIF profile keys, canonical URIs, schema paths, and Pydantic model classes.
Built-in Profiles in DEFAULT_REGISTRY
By default, dartfx-cdif provides a pre-populated registry instance: DEFAULT_REGISTRY.
from dartfx.cdif.registry import DEFAULT_REGISTRY, ProfileInfo
# List all registered profiles
for profile in DEFAULT_REGISTRY.list_profiles():
print(f"Key: {profile.key}")
print(f" Model: {profile.model_class.__name__ if profile.model_class else 'None'}")
print(f" URIs: {profile.uris}")
print(f" Schema: {profile.schema_path}")
Profile Metadata: ProfileInfo
Each registered profile is documented by a ProfileInfo dataclass:
@dataclass(frozen=True)
class ProfileInfo:
key: str # E.g., 'core', 'discovery'
uris: tuple[str, ...] # Canonical and versioned URIs
model_class: type[CdifBaseModel] | None # Root Pydantic model class
schema_path: str # Path to JSON schema
frame_path: str # Path to JSON-LD frame
shacl_path: str # Path to SHACL shape
description: str # Profile overview
Profile Detection (detect_profiles)
When an arbitrary metadata document is received, detect_profiles() inspects its contents to determine which CDIF profiles it satisfies.
from dartfx.cdif.registry import detect_profiles
# Inspect a raw JSON-LD dictionary or rdflib.Graph
detected_profiles: list[str] = detect_profiles(doc)
print(f"Matching profiles: {detected_profiles}")
Detection Strategy
The detection engine uses a two-tiered strategy:
[ Ingested Document ]
|
v
[ Check for dcterms:conformsTo Statements ]
|
+-------------------+-------------------+
| |
(URI Matches Found) (No Conformance URIs)
| |
v v
Map URIs to Profiles [ Heuristic Structural Scoring ]
(e.g., cdif/core/1.1 -> core) - spatial/temporal -> discovery
- variableMeasured -> datadescription
- prov:wasGeneratedBy -> provenance
- skos:ConceptScheme -> codelist
- manifest/part -> manifest
|
+-------------------+-------------------+
|
v
[ Ordered Profile List ]
Exact Conformance URI Matching: Inspects
dcterms:conformsTo(in JSON-LD dictionaries or RDF triples). If standard CDIF profile URIs (such ashttps://w3id.org/cdif/core/1.1orhttps://w3id.org/cdif/discovery/1.0) are present, they are directly mapped to their profile keys.Structural Heuristic Scoring: If conformance declarations are omitted, the document is scanned for characteristic signatures:
Presence of
schema:spatialCoverageorschema:temporalCoverage->discoveryPresence of
schema:variableMeasured->data_descriptionPresence of
prov:wasGeneratedByorprov:Activity->provenancePresence of
skos:ConceptSchemeorskos:Concept->codelistPresence of
manifestor distribution parts ->manifestBaseline dataset with title/description/identifier ->
core
Polymorphic Document Loading (load_cdif)
The load_cdif() function is the primary entrypoint for ingesting CDIF data. It handles document loading, format normalization, profile detection, and model instantiation in a single step.
from dartfx.cdif import load_cdif
# 1. From a file path (JSON-LD or RDF)
ds1 = load_cdif("examples/kaggle-iris.jsonld")
# 2. From a JSON string
ds2 = load_cdif('{"@type": "schema:Dataset", "schema:name": "Sample"}')
# 3. From a Python dictionary
ds3 = load_cdif({"@type": "schema:Dataset", "schema:name": "Sample"})
# 4. From an rdflib.Graph
from rdflib import Graph
g = Graph()
g.parse("dataset.ttl", format="turtle")
ds4 = load_cdif(g)
Explicit Profile Overriding
If you want to enforce a specific profile model rather than relying on automatic detection, pass the profile parameter:
# Force instantiation as a Discovery profile model
dataset = load_cdif("dataset.jsonld", profile="discovery")