Base Model
Base Pydantic RDF model for CDIF profile classes.
- class dartfx.cdif.models._base.CdifBaseModel(*, rdf_uri_generator=<factory>, id=None, rdf_types_jsonld=None, jsonld_context=None, **extra_data)[source]
Bases:
RdfBaseModelBase class for all generated CDIF Pydantic + RDF models.
Supports both:
Direct framed JSON-LD validation/serialization via Pydantic aliases (
from_jsonld/to_jsonld_dict).Full RDF graph round-tripping (Turtle, JSON-LD, RDF/XML, N-Triples) via
dartfx.rdf.pydantic.RdfBaseModel(to_rdf/from_rdf).
- Parameters:
rdf_uri_generator (RdfUriGenerator)
id (str | None)
rdf_types_jsonld (str | list[str] | None)
jsonld_context (dict[str, Any] | list[Any] | str | None)
extra_data (Any)
- model_config = {'arbitrary_types_allowed': True, 'extra': 'allow', 'populate_by_name': True}
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- rdf_prefixes: ClassVar[Any] = {'bios': Namespace('https://bioschemas.org/'), 'cdi': Namespace('http://ddialliance.org/Specification/DDI-CDI/1.0/RDF/'), 'cdif': Namespace('https://w3id.org/cdif/'), 'csvw': Namespace('http://www.w3.org/ns/csvw#'), 'dcat': Namespace('http://www.w3.org/ns/dcat#'), 'dcterms': Namespace('http://purl.org/dc/terms/'), 'dqv': Namespace('http://www.w3.org/ns/dqv#'), 'foaf': Namespace('http://xmlns.com/foaf/0.1/'), 'geosparql': Namespace('http://www.opengis.net/ont/geosparql#'), 'owl': Namespace('http://www.w3.org/2002/07/owl#'), 'prov': Namespace('http://www.w3.org/ns/prov#'), 'rdf': Namespace('http://www.w3.org/1999/02/22-rdf-syntax-ns#'), 'rdfs': Namespace('http://www.w3.org/2000/01/rdf-schema#'), 'schema': Namespace('http://schema.org/'), 'sf': Namespace('http://www.opengis.net/ont/sf#'), 'skos': Namespace('http://www.w3.org/2004/02/skos/core#'), 'spdx': Namespace('http://spdx.org/rdf/terms#'), 'time': Namespace('http://www.w3.org/2006/time#'), 'xsd': Namespace('http://www.w3.org/2001/XMLSchema#')}
- rdf_id_field: ClassVar[str | None] = 'id'
- cdif_profile_uri: ClassVar[str | None] = None
- cdif_required_fields: ClassVar[tuple[str, ...]] = ()
- cdif_any_of_required: ClassVar[tuple[tuple[str, ...], ...]] = ()
- cdif_forbid_extra: ClassVar[bool] = False
- rdf_uri_generator: RdfUriGenerator
- id: str | None
- rdf_types_jsonld: str | list[str] | None
- jsonld_context: dict[str, Any] | list[Any] | str | None
- classmethod default_jsonld_context()[source]
Return the standard prefix dictionary for CDIF JSON-LD serialization.
- Return type:
dict[str, str]
- validate_conformance(strict=False)[source]
Validate profile-level required and conditional (
anyOf) constraints.When the instance declares known CDIF profiles in
schema:subjectOf.dcterms:conformsTo, validates against the combined requirements of those declared profiles rather than the Python container class (e.g.CdifCompleteDatasetholdingdiscovery+provenancewithoutdata_description). Falls back to the class’s owncdif_required_fields/cdif_any_of_requiredwhen no known CDIF profiles are declared.- Parameters:
strict (bool) – When True, raises
ValueErrorif any conformance violation is found.- Returns:
Human-readable list of missing required or conditional field messages.
- Return type:
list[str]
- to_jsonld_dict(*, exclude_none=True, include_context=False)[source]
Serialize this model into a framed JSON-LD dictionary using JSON-LD aliases.
- Parameters:
exclude_none (bool)
include_context (bool)
- Return type:
dict[str, Any]
- to_jsonld(*, indent=2, include_context=True)[source]
Serialize this model to a framed JSON-LD string.
- Parameters:
indent (int | None)
include_context (bool)
- Return type:
str
- classmethod from_jsonld(data)[source]
Deserialize a framed JSON-LD document (string, bytes, or dict) into this model.
- Parameters:
data (str | bytes | dict[str, Any])
- Return type:
Self
- model_post_init(context, /)
This function is meant to behave like a BaseModel method to initialize private attributes.
It takes context as an argument since that’s what pydantic-core passes when calling it.
- Parameters:
self (BaseModel) – The BaseModel instance.
context (Any) – The context.
- Return type:
None