RdfProperty.define constructor
- String? fragment,
- bool noDomain = false,
- List<
(IriTerm, RdfObject)> ? metadata = const [], - String? label,
- String? comment,
- bool include = true,
- dynamic defaultValue,
- bool includeDefaultsInSerialization = false,
- IriMapping? iri,
- LocalResourceMapping? localResource,
- LiteralMapping? literal,
- GlobalResourceMapping? globalResource,
- CollectionMapping? collection = const CollectionMapping.auto(),
- Type? itemType,
- ContextualMapping? contextual,
Creates an RDF property mapping annotation for vocabulary generation mode.
Use this constructor when you want to automatically generate a vocabulary from your Dart class structure. In this mode, the predicate IRI is derived automatically from the property name (or custom fragment) and the vocabulary configuration.
Important: Implicit Property Generation
When a class uses RdfGlobalResource.define or RdfLocalResource.define,
unannotated fields are automatically treated as @RdfProperty.define().
You only need explicit annotations when:
- Using external vocabularies:
@RdfProperty(ExternalVocab.term) - Customizing the fragment:
@RdfProperty.define(fragment: 'customName') - Excluding fields:
@RdfIgnore()(complete exclusion) orinclude: false(read-only) - Overriding default mapping behavior (custom serializers, etc.)
When using this constructor:
- The
fragmentparameter optionally specifies a custom fragment identifier - The
metadataparameter adds custom RDF metadata triples for this property resource - The
labelparameter optionally setsrdfs:labelfor the generated property - The
commentparameter optionally setsrdfs:commentfor the generated property - If fragment is not provided, it's derived from the field name
- The predicate IRI is computed at build time as:
vocab.appBaseUri + vocab.vocabPath + '#' + fragment - The field name must be in lowerCamelCase unless a custom fragment is provided
All other parameters (include, defaultValue, iri, literal, etc.) work
the same as in the standard constructor and control how the property value
is mapped to RDF.
Excluding fields from RDF:
- To completely exclude a field (no vocab entry, no mapping): Use
@RdfIgnore() - To make a field read-only from app perspective (in vocab, deserialized but not serialized): Use
include: false
Example (basic usage):
const myVocab = AppVocab(
appBaseUri: 'https://my.app.de',
vocabPath: '/vocab',
);
@RdfGlobalResource.define(myVocab, IriStrategy('https://my.app.de/books/{id}'))
class Book {
@RdfIriPart('id')
final String id;
// Automatically generates predicate: https://my.app.de/vocab#title
@RdfProperty.define()
final String title;
// Custom fragment: https://my.app.de/vocab#bookAuthor
@RdfProperty.define(fragment: 'bookAuthor')
final String author;
// With custom literal mapping
@RdfProperty.define(
literal: LiteralMapping.withLanguage('en'),
)
final String description;
// Read-only RDF property (in vocab, deserialized but not serialized back)
@RdfProperty.define(include: false)
final DateTime lastModified;
// Completely excluded from RDF (no vocab entry, no serialization/deserialization)
@RdfIgnore()
bool isExpanded; // UI state, not persisted to RDF
}
Example (with metadata):
// Using label and comment for property documentation
@RdfProperty.define(
fragment: 'isbn',
label: 'ISBN',
comment: 'International Standard Book Number',
)
final String isbn;
// Using metadata with literal values
@RdfProperty.define(
fragment: 'publishDate',
metadata: [
(RdfsVocab.range, Xsd.date),
(OwlVocab.deprecated, LiteralTerm.boolean(false)),
],
)
final DateTime publishDate;
// Combining label/comment with metadata
@RdfProperty.define(
fragment: 'pageCount',
label: 'Page Count',
comment: 'Total number of pages in the book',
metadata: [
(RdfsVocab.range, Xsd.nonNegativeInteger),
],
)
final int pageCount;
The generated Turtle will include metadata triples:
<https://my.app.de/vocab#isbn> a rdf:Property ;
rdfs:label "ISBN" ;
rdfs:comment "International Standard Book Number" .
<https://my.app.de/vocab#pageCount> a rdf:Property ;
rdfs:label "Page Count" ;
rdfs:comment "Total number of pages in the book" ;
rdfs:range xsd:nonNegativeInteger .
Implementation
const RdfProperty.define({
this.fragment,
this.noDomain = false,
this.metadata = const [],
this.label,
this.comment,
this.include = true,
this.defaultValue,
this.includeDefaultsInSerialization = false,
this.iri,
this.localResource,
this.literal,
this.globalResource,
this.collection = const CollectionMapping.auto(),
this.itemType,
this.contextual,
}) : predicate = null;