RdfGlobalResource.define constructor
const
RdfGlobalResource.define(
- AppVocab vocab,
- IriStrategy iriStrategy, {
- IriTerm? subClassOf,
- List<
(IriTerm, RdfObject)> metadata = const [], - String? label,
- String? comment,
- String? fragment,
- bool registerGlobally = true,
- MapperDirection direction = MapperDirection.both,
Creates an annotation for vocabulary generation mode.
Use this constructor when you want to automatically generate a vocabulary (Turtle/RDF file) from your Dart class structure. In this mode, the class IRI is derived automatically from the class name and the vocabulary configuration.
When using this constructor:
- The
vocabparameter specifies the application vocabulary configuration - The
iriStrategyparameter defines how instance IRIs are constructed - The
subClassOfparameter optionally specifies a superclass relationship - The
metadataparameter adds custom RDF metadata triples for this class resource - The
labelparameter optionally setsrdfs:labelfor the generated class - The
commentparameter optionally setsrdfs:commentfor the generated class - The
fragmentparameter optionally overrides the class IRI fragment (defaults to the Dart class name) - The
registerGloballyparameter controls whether the generated mapper is registered globally (defaults totrue). Set tofalsewhen the mapper requires runtime context - The
directionparameter controls the mapping direction:both(default),toRdf, orfromRdf - The class IRI is computed at build time as:
vocab.appBaseUri + vocab.vocabPath + '#' + (fragment ?? ClassName) - All properties (both annotated with
@RdfProperty.define()and unannotated) contribute to the vocabulary unless explicitly excluded
Example (basic usage):
const myVocab = AppVocab(
appBaseUri: 'https://my.app.de',
vocabPath: '/vocab',
);
@RdfGlobalResource.define(
myVocab,
IriStrategy('https://my.app.de/books/{id}'),
subClassOf: SchemaBook.classIri,
)
class Book {
@RdfIriPart('id')
final String id;
// This property will be included in the vocabulary with fragment 'title'
final String title;
// This property can explicitly use .define() to customize the fragment
@RdfProperty.define(fragment: 'bookAuthor')
final String author;
}
This will generate a vocabulary file containing:
- Class definition:
<https://my.app.de/vocab#Book> a owl:Class - SubClass relationship:
rdfs:subClassOf <https://schema.org/Book> - Property definitions for 'title' and 'bookAuthor'
Example (with metadata):
// Using label and comment for basic documentation
@RdfGlobalResource.define(
myVocab,
IriStrategy('https://my.app.de/books/{id}'),
label: 'Book',
comment: 'Represents a published book with bibliographic metadata',
)
class Book { /* ... */ }
// Using metadata for custom RDF predicates
@RdfGlobalResource.define(
myVocab,
IriStrategy('https://my.app.de/books/{id}'),
metadata: [
(Dcterms.created, LiteralTerm('2025-01-15', datatype: Xsd.date)),
(Dcterms.creator, IriTerm('https://orcid.org/0000-0001-2345-6789')),
(OwlVocab.versionInfo, LiteralTerm('1.0.0')),
],
)
class Book { /* ... */ }
// Combining label/comment with metadata
@RdfGlobalResource.define(
myVocab,
IriStrategy('https://my.app.de/books/{id}'),
label: 'Book',
comment: 'A published book',
metadata: [
(OwlVocab.versionInfo, LiteralTerm('1.0.0')),
],
)
class Book { /* ... */ }
The generated Turtle will include all metadata as RDF triples on the class IRI:
<https://my.app.de/vocab#Book> a owl:Class ;
rdfs:label "Book" ;
rdfs:comment "A published book" ;
owl:versionInfo "1.0.0" .
Implementation
const RdfGlobalResource.define(
AppVocab vocab,
IriStrategy iriStrategy, {
IriTerm? subClassOf,
List<(IriTerm, RdfObject)> metadata = const [],
this.label,
this.comment,
this.fragment,
bool registerGlobally = true,
MapperDirection direction = MapperDirection.both,
}) : vocab = vocab,
subClassOf = subClassOf,
metadata = metadata,
iri = iriStrategy,
classIri = null,
super(registerGlobally: registerGlobally, direction: direction);