makeprov.rdfmixin
Functions
|
Return a tuple describing the fields of this dataclass. |
|
Get type arguments with all substitutions performed. |
|
Get the unsubscripted version of a type. |
|
Return type hints for an object. |
|
Returns True if obj is a dataclass or an instance of a dataclass. |
Classes
|
Construct a new Decimal object. |
|
Provide JSON-LD serialization helpers for dataclasses. |
|
Instances of the UUID class represent UUIDs as specified in RFC 4122. |
|
date(year, month, day) --> date object |
|
The year, month and day arguments are required. |
|
time([hour[, minute[, second[, microsecond[, tzinfo]]]]]) --> a time object |
- class makeprov.rdfmixin.RDFMixin
Bases:
objectProvide JSON-LD serialization helpers for dataclasses.
The mixin preserves unknown fields when round-tripping JSON-LD documents and offers convenient conversion to rdflib graphs.
Examples
@dataclass class Person(RDFMixin): id: str type: str = "ex:Person" name: str | None = None person = Person(id="ex:alice", name="Alice") jsonld = person.to_jsonld()
- classmethod fields_subclass_first()
Return dataclass fields with subclass members ordered first.
Examples
from dataclasses import dataclass @dataclass class Thing(RDFMixin): id: str Thing.fields_subclass_first()
- classmethod from_jsonld(data)
Deserialize a JSON-LD mapping into the dataclass instance.
- Parameters:
data (
dict) – Parsed JSON-LD object including optional@context.- Returns:
An instance of
clspopulated fromdata.- Return type:
Examples
person = Person.from_jsonld({"id": "ex:alice", "name": "Alice"})
- to_graph()
Convert this object to an
rdflib.Graphfrom JSON-LD.- Returns:
Graph containing triples representing the instance.
- Return type:
rdflib.Graph
- Raises:
RuntimeError – If
rdflibis not installed.
Examples
graph = Person(id="ex:alice").to_graph()
- to_jsonld(with_context=True, include_extra=True)
Serialize the object to a JSON-LD-compatible mapping.
- Parameters:
- Returns:
JSON-LD representation of the object.
- Return type:
Examples
person = Person(id="ex:alice", name="Alice") payload = person.to_jsonld()