IriStrategy.withFragment constructor

const IriStrategy.withFragment(
  1. String baseIriTemplate,
  2. String fragmentTemplate, {
  3. String? providedAs,
})

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:

  1. Process baseIriTemplate to get the base IRI
  2. Strip any existing fragment from the base IRI (everything after and including #)
  3. Process fragmentTemplate to get the fragment value
  4. Append #${fragmentValue} to create the final IRI

Both templates support the standard placeholder system:

  • Property placeholders from @RdfIriPart annotated properties
  • Context variables from global providers, @RdfProvides, or parent's providedAs
  • 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();