IriStrategy.withFragment constructor
const
IriStrategy.withFragment(})
Creates a strategy for generating IRIs by appending a fragment to a base IRI.
This constructor is specifically designed for creating IRIs that differ from a base IRI
only by their fragment identifier. It works with any URI scheme (hierarchical like https://
or non-hierarchical like tag:), making it ideal for resources within the same document
that are distinguished by fragments.
The generator will:
- Process
baseIriTemplateto get the base IRI - Strip any existing fragment from the base IRI (everything after and including
#) - Process
fragmentTemplateto get the fragment value - Append
#${fragmentValue}to create the final IRI
Both templates support the standard placeholder system:
- Property placeholders from
@RdfIriPartannotated properties - Context variables from global providers,
@RdfProvides, or parent'sprovidedAs - Reserved expansion with
{+variable}to preserve URI structure
The optional providedAs parameter allows this resource's IRI to be provided to dependent
mappers under the specified name.
Example with tag: URI:
@RdfGlobalResource(
DocumentClass.classIri,
IriStrategy('tag:example.org,2025:document-{docId}', 'documentIri')
)
class Document {
@RdfIriPart()
final String docId;
@RdfProperty(Vocab.hasItem)
final List<Item> items;
}
@RdfGlobalResource(
ItemClass.classIri,
IriStrategy.withFragment('{+documentIri}', 'item-{itemId}'),
registerGlobally: false
)
class Item {
@RdfIriPart()
final String itemId;
// IRI will be: tag:example.org,2025:document-123#item-456
}
Example with https:// URI:
@RdfGlobalResource(
PageClass.classIri,
IriStrategy('{+baseUri}/page/{pageId}', 'pageIri')
)
class Page {
@RdfIriPart()
final String pageId;
@RdfProperty(Vocab.hasSection)
final List<Section> sections;
}
@RdfGlobalResource(
SectionClass.classIri,
IriStrategy.withFragment('{+pageIri}', 'section-{sectionId}'),
registerGlobally: false
)
class Section {
@RdfIriPart()
final String sectionId;
// IRI will be: https://example.org/page/123#section-intro
}
Implementation
const IriStrategy.withFragment(
String baseIriTemplate, String fragmentTemplate,
{this.providedAs})
: template = baseIriTemplate,
fragmentTemplate = fragmentTemplate,
super();