Skip to content

model ¤

Classes:

  • BaseRdfModel

    Base class for RDF-mappable Pydantic models.

BaseRdfModel pydantic-model ¤

Bases: BaseModel

Base class for RDF-mappable Pydantic models.

Config:

  • arbitrary_types_allowed: True

Fields:

  • uri (PydanticURIRef)

uri pydantic-field ¤

uri: PydanticURIRef

The URI identifier for this RDF entity

all_entities classmethod ¤

all_entities(graph: Graph) -> list[T]

Return all entities of this model's RDF type from the graph.

Returns:

  • list[T]

    A list of model instances for each entity of this RDF type in the graph.

Raises:

Example
entities = MyModel.all_entities(graph)

model_dump_rdf ¤

model_dump_rdf() -> Graph

Serialize this model instance to an RDF graph.

Returns:

  • Graph

    An RDFLib Graph representing this model instance.

Example
graph = instance.model_dump_rdf()

parse_graph classmethod ¤

parse_graph(graph: Graph, uri: URIRef, _cache: RDFEntityCache | None = None) -> T

Parse an RDF entity from the graph into a model instance.

Uses a cache to prevent recursion and circular references.

Parameters:

  • _cache (RDFEntityCache | None, default: None ) –

    Optional cache for already-parsed entities.

Returns:

  • T

    An instance of the model corresponding to the RDF entity.

Raises:

Example
model = MyModel.parse_graph(graph, EX.some_uri)