IriMapping.withFragment constructor

const IriMapping.withFragment(
  1. String baseIriTemplate,
  2. String fragmentTemplate
)

Creates a mapping for generating IRIs by appending a fragment to a base IRI.

This constructor is specifically designed for creating property 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 properties that reference resources within the same document 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 corresponding to the annotated property's value
  • Context variables from global providers, @RdfProvides, or parent's providedAs
  • Reserved expansion with {+variable} to preserve URI structure

Example usage:

@RdfGlobalResource(
  DocumentClass.classIri,
  IriStrategy('tag:example.org,2025:document-{docId}', 'documentIri')
)
class Document {
  @RdfIriPart()
  final String docId;

  @RdfProperty(
    Vocab.relatedItem,
    iri: IriMapping.withFragment('{+documentIri}', 'item-{itemId}')
  )
  final String itemId;
  // Property IRI will be: tag:example.org,2025:document-123#item-456
}

Implementation

const IriMapping.withFragment(String baseIriTemplate, String fragmentTemplate)
    : template = baseIriTemplate,
      fragmentTemplate = fragmentTemplate,
      super();