RdfIri.withFragment constructor

const RdfIri.withFragment(
  1. String baseIriTemplate,
  2. String fragmentTemplate, {
  3. bool registerGlobally = true,
})

Creates an IRI mapping by appending a fragment to a base IRI.

This constructor is specifically designed for classes that represent IRI terms which 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 identifier classes that represent fragment-based references within a document.

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

Example usage:

@RdfIri.withFragment('{+documentIri}', 'section-{sectionId}')
class SectionReference {
  @RdfIriPart()
  final String sectionId;

  SectionReference(this.sectionId);
}

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

  @RdfProperty(Vocab.currentSection)
  final SectionReference section;
  // Section IRI will be: tag:example.org,2025:document-123#section-intro
}

Implementation

const RdfIri.withFragment(String baseIriTemplate, String fragmentTemplate,
    {bool registerGlobally = true})
    : template = baseIriTemplate,
      fragmentTemplate = fragmentTemplate,
      super(registerGlobally: registerGlobally);