RdfGlobalResource.define constructor

const RdfGlobalResource.define(
  1. AppVocab vocab,
  2. IriStrategy iriStrategy, {
  3. IriTerm? subClassOf,
  4. List<(IriTerm, RdfObject)> metadata = const [],
  5. String? label,
  6. String? comment,
  7. String? fragment,
  8. bool registerGlobally = true,
  9. 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 vocab parameter specifies the application vocabulary configuration
  • The iriStrategy parameter defines how instance IRIs are constructed
  • The subClassOf parameter optionally specifies a superclass relationship
  • The metadata parameter adds custom RDF metadata triples for this class resource
  • The label parameter optionally sets rdfs:label for the generated class
  • The comment parameter optionally sets rdfs:comment for the generated class
  • The fragment parameter optionally overrides the class IRI fragment (defaults to the Dart class name)
  • The registerGlobally parameter controls whether the generated mapper is registered globally (defaults to true). Set to false when the mapper requires runtime context
  • The direction parameter controls the mapping direction: both (default), toRdf, or fromRdf
  • 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);