RdfLocalResource.define constructor

const RdfLocalResource.define(
  1. AppVocab vocab, {
  2. IriTerm? subClassOf,
  3. List<(IriTerm, RdfObject)> metadata = const [],
  4. String? label,
  5. String? comment,
  6. bool registerGlobally = true,
  7. 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 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 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 + '#' + ClassName
  • All properties (both annotated with @RdfProperty.define() and unannotated) contribute to the vocabulary unless explicitly excluded

Unlike RdfGlobalResource.define(), local resources don't have an IRI strategy since they are represented as blank nodes in RDF.

Example (basic usage):

const myVocab = AppVocab(
  appBaseUri: 'https://my.app.de',
  vocabPath: '/vocab',
);

@RdfLocalResource.define(
  myVocab,
  subClassOf: SchemaChapter.classIri,
)
class Chapter {
  // 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: 'chapterNumber')
  final int number;
}

This will generate a vocabulary file containing:

  • Class definition: <https://my.app.de/vocab#Chapter> a owl:Class
  • SubClass relationship: rdfs:subClassOf <https://schema.org/Chapter>
  • Property definitions for 'title' and 'chapterNumber'

Example (with metadata):

// Using label and comment for documentation
@RdfLocalResource.define(
  myVocab,
  label: 'Chapter',
  comment: 'A chapter within a book or document',
)
class Chapter { /* ... */ }

// Combining label/comment with custom metadata
@RdfLocalResource.define(
  myVocab,
  label: 'Chapter',
  metadata: [
    (OwlVocab.deprecated, LiteralTerm('false', datatype: Xsd.boolean)),
    (Dcterms.modified, LiteralTerm('2025-02-17', datatype: Xsd.date)),
  ],
)
class Chapter { /* ... */ }

The generated Turtle will include metadata triples:

<https://my.app.de/vocab#Chapter> a owl:Class ;
    rdfs:label "Chapter" ;
    owl:deprecated false ;
    dcterms:modified "2025-02-17"^^xsd:date .

Implementation

const RdfLocalResource.define(
  AppVocab vocab, {
  IriTerm? subClassOf,
  List<(IriTerm, RdfObject)> metadata = const [],
  this.label,
  this.comment,
  bool registerGlobally = true,
  MapperDirection direction = MapperDirection.both,
})  : vocab = vocab,
      subClassOf = subClassOf,
      metadata = metadata,
      classIri = null,
      super(registerGlobally: registerGlobally, direction: direction);