dartfx-cdif provides type-safe Pydantic v2 + RDF models for the Cross-Domain Interoperability Framework (CDIF) profiles, generated directly from the upstream JSON Schemas, JSON-LD contexts, and SKOS vocabularies under git-cdif.
flowchart LR
Schemas["git-cdif Schemas, @context & .ttl Vocabularies"] --> Codegen["dartfx.cdif.codegen\n(loader -> resolver -> emitter)"]
Codegen --> Models["dartfx.cdif.models\n(vocabularies, common, profiles/*)"]
Models --> Base["CdifBaseModel\n(dartfx.rdf.pydantic.RdfBaseModel)"]
Base --> JSONLD["Framed JSON-LD\n(from_jsonld / to_jsonld_dict)"]
Base --> RDF["rdflib.Graph\n(from_rdf / to_rdf)"]
Models --> Registry["ProfileRegistry\n(detect_profiles / load_cdif)"]
Defines canonical rdflib.Namespace bindings matching validation/CDIF-context-2026.jsonld (SCHEMA, DCTERMS, PROV, DQV, GEOSPARQL, SPDX, TIME, SF, CDI, CDIF, CSVW, DCAT, SKOS, BIOS, CDIFACT, GSBPM, XSD), CDIF_PREFIXES, and CURIE resolution helpers (expand_curie, prefix_expr_for_curie).
CdifBaseModel extends dartfx.rdf.pydantic.RdfBaseModel to support dual JSON-LD and RDF graph usage:
- Dual Serialization: Uses
Field(alias="prefix:term")withConfigDict(arbitrary_types_allowed=True, populate_by_name=True, extra="allow")alongsideAnnotated[T, RdfProperty(PREFIX.term)].to_jsonld_dict()/to_jsonld()/from_jsonld()operate directly on framed JSON-LD dictionaries and@graphenvelopes.to_rdf()/from_rdf()/to_rdf_graph()/from_rdf_graph()round-trip throughrdflib.Graphviadartfx-rdfacross Turtle, JSON-LD, RDF/XML, and N-Triples.
- Main-Entity Disambiguation (
_infer_subject): Real CDIF graphs commonly contain multipleschema:Datasetnodes (the root dataset, itsschema:subjectOfdcat:CatalogRecord, andschema:hasPartchild datasets).CdifBaseModel._infer_subjectfilters out catalog records andschema:hasPartmembers before selecting the root entity. - Typed Union Discrimination (
_resolve_typed_union_fields): Amode="before"model validator resolves JSON-LD dicts in multi-model union fields (e.g.,Person | Organization | ObjectReference,DataDownload | WebAPI,DefinedTerm | Concept,DataStructurevariants) by matching@type(CURIEs, full URIs includinghttp(s)://schema.org/, and bare local names) against each candidate class'srdf_type, routing@id-only dicts toObjectReferenceand falling back gracefully for unrecognized external types. - Blank-Node Preservation (
DefaultUriGenerator(auto_uuid=False)): Models without an@idserialize to RDF as anonymousBNodes (and explicit_:...IDs as deterministicBNodes) rather than minting ephemeralurn:uuid:IRIs;dartfx-rdf'sRdfBaseModel.from_rdf_graphpreserves blank-node subjects and keepsid=Noneon round-trip. - Lossless Extra & JSON-LD Value RDF Serialization (
_serialise_into_graph&_value_to_node): Propagates active@contextprefix/@vocab/@type: @idbindings down nested models, serializes undeclaredmodel_extraproperties and additional@typeassertions, keeps plainstrvalues as RDFLiterals unless typed@type: @idin@context(preventing colon-containing text from becoming invalidURIRefs), converts JSON-LD dicts ({"@id": ...},{"@value": ..., "@language": ...},{"@list": [...]},{"@set": [...]}, and nested node objects) andLanguageTaggedValuemodels into proper RDF terms/collections, and emits aUserWarningif an extra property key cannot be resolved to a predicate URI. - Deferred Profile Conformance (
validate_conformance): Models stay ergonomic to construct incrementally, whilevalidate_conformance(strict=False)validates against the combinedcdif_required_fieldsandcdif_any_of_requiredof the profiles declared inschema:subjectOf.dcterms:conformsTo(falling back to the class's own constraints when no known CDIF profile is declared).
config.py: DeclaresProfileSpecentries for all 8 profiles (core,discovery,data_description,data_structure,provenance,manifest,codelist,complete) andresolve_cdif_root()(--cdif-root→CDIF_ROOTenv var → siblinggit-cdifdirectory).loader.py: Loads*StructuredSchema.jsonfiles, composite schemas (CDIFDiscoverySchema.json,CDIFDataDescriptionSchema.json),CDIF-context-2026.jsonld, and SKOS provenance activity concepts fromprofile-provenance/vocabularies/CDIF_Activities.ttl.ir.py: Intermediate Representation dataclasses (EnumIR,TypeAliasIR,FieldIR,ClassIR,ModuleIR).resolver.py:- Deduplicates
$defsacross schemas intomodels/common.pyand promotes inline typed sub-objects (CatalogRecord,DataDownload,WebAPI,MonetaryGrant,Place,GeoCoordinates,GeoShape,ProperInterval,Instant,TimePosition,QualityMeasurement,CdifProvActivity,ManifestPart,ArchivePart,DataStructurevariants, value domains) into first-classCdifBaseModelclasses. - Translates
@typeconstraints (const/contains.const/default) intordf_typedeclarations and CURIE property names intoRdfProperty(...)predicates + JSON-LD aliases. - Composes non-overlapping profile mixins (
CdifDiscoveryMixin,CdifDataDescriptionMixin,CdifProvenanceMixin,CdifManifestMixin) into profile dataset classes (CdifCoreDataset→CdifDiscoveryDataset→CdifDataDescriptionDataset→CdifCompleteDataset).
- Deduplicates
emitter.py: Emits Ruff-formatted,pyrefly-clean Python modules undersrc/dartfx/cdif/models/.
ProfileRegistrymaps profile keys, aliases, and2.0/1.1/1.0/ composite URIs to their correspondingCdifBaseModelroot class.detect_profiles()honors explicitschema:subjectOf.dcterms:conformsTodeclarations when present and falls back to structural property heuristics aligned withdetect_conformance.py(skos:ConceptScheme,cdif:hasPrimaryKey/cdi:InstanceVariable,schema:variableMeasured, dual-typedprov:Activity+schema:Actionwithschema:instrument/object/actionProcess,schema:hasPart) when absent.load_cdif()parses JSON-LD or RDF files/strings into the most specific matching profile model.cli.pyexposescdif codegen,cdif profiles, andcdif validate.
Sphinx documentation suite with Read the Docs theme and MyST-Parser:
overview.md: CDIF background, cross-domain motivation, anddartfx-cdifarchitecture.quickstart.md: Installation, model hydration, property access, dual serialization, and conformance validation.models.md:CdifBaseModelarchitecture, main-entity subject inference (_infer_subject), RDF predicate mapping, common sub-models, and controlled vocabularies.profiles.md: Detailed catalog for all 8 profiles (core,discovery,datadescription,datastructure,provenance,manifest,codelist,complete).generator.md: Code generator pipeline (Loader → Resolver → IR → Emitter) and schema drift management.registry.md: Profile registry, detection algorithms, and polymorphic loading viaload_cdif().cli.md: Reference forcdif profiles,cdif validate, andcdif codegen.api/: Full Sphinx autodoc API references covering all public modules and classes.- Verified build with zero warnings:
sphinx-build -W -b html docs/source docs/build/html.