annotation
¤
Classes:
-
WithDataType
–Annotation to specify a custom RDF datatype for a field.
-
WithPredicate
–Annotation to specify a custom RDF predicate for a field.
WithDataType
dataclass
¤
WithDataType(data_type: URIRef)
Annotation to specify a custom RDF datatype for a field.
This annotation allows you to define a specific RDF datatype to use when serializing a model field to RDF literals, instead of using the default datatype inference.
Parameters:
-
data_type
(URIRef
) –The RDF datatype URI to use for this field
Example
from typing import Annotated
from pydantic_rdf import BaseRdfModel, WithDataType
from rdflib.namespace import XSD
class Product(BaseRdfModel):
# This will use xsd:decimal datatype instead of the default
price: Annotated[float, WithDataType(XSD.decimal)]
Methods:
-
extract
–Extract from field annotation if present.
WithPredicate
dataclass
¤
WithPredicate(predicate: URIRef)
Annotation to specify a custom RDF predicate for a field.
This annotation allows you to define a specific RDF predicate to use when serializing a model field to RDF, instead of using the default predicate generated from the field name.
Parameters:
-
predicate
(URIRef
) –The RDF predicate URI to use for this field
Example
from typing import Annotated
from pydantic_rdf import BaseRdfModel, WithPredicate
from rdflib import Namespace
EX = Namespace("http://example.org/")
class Person(BaseRdfModel):
# This will use the EX.emailAddress predicate instead of the default EX.email
email: Annotated[str, WithPredicate(EX.emailAddress)]
Methods:
-
extract
–Extract from field annotation if present.