RdfLocalResource.define constructor
const
RdfLocalResource.define(})
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
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
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 + '#' + 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);